class BankLevelEnum extends BaseEnum { const HEAD = 1; const DIVISION = 2; const BRANCH = 3; const ATM = 4; const ORTHER = 5; /** * @return array */ public static function getMap(): array { return [ // self::HEAD => '总行', self::DIVISION => '分行', self::BRANCH => '支行', self::ATM => '4级', self::ORTHER => '5级', ]; } } 如何根据中文的“分行”值,获取类中的key值
时间: 2023-05-20 13:01:56 浏览: 90
可以使用 array_search 函数来实现,代码如下:
$key = array_search('分行', BankLevelEnum::getMap());
echo $key; // 输出 2
相关问题
如何在下面这段代码中将 OrdeilistProvider 添加到 MultiProvider 中:class Tabs extends StatefulWidget { const Tabs({super.key}); @override State<Tabs> createState() => _TabsState(); } class _TabsState extends State<Tabs> { int _currentIndex = 0; final List<Widget> pages = [ HomePage( key: homePageKey, ), const OrderPage(), const ProfilePage() ]; @override Widget build(BuildContext context) { return Scaffold( body: IndexedStack( index: _currentIndex, children: pages, ), bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, type: BottomNavigationBarType.fixed, onTap: (index) { setState(() { _currentIndex = index; }); if (_currentIndex == 0) { homePageKey.currentState!.toMyLocation(); } }, items: const [ BottomNavigationBarItem(icon: Icon(Icons.home), label: ''), // BottomNavigationBarItem(icon: Icon(Icons.gas_meter), label: ''), BottomNavigationBarItem(icon: Icon(Icons.note_alt), label: ''), BottomNavigationBarItem(icon: Icon(Icons.person), label: ''), ], ), ); } }
可以使用 MultiProvider 包裹整个 MaterialApp,并将 OrdeilistProvider 添加到 providers 列表中,如下所示:
```dart
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => OrdeilistProvider()),
],
child: MaterialApp(
title: 'My App',
home: const Tabs(),
),
);
}
}
class Tabs extends StatefulWidget {
const Tabs({Key? key}) : super(key: key);
@override
State<Tabs> createState() => _TabsState();
}
class _TabsState extends State<Tabs> {
int _currentIndex = 0;
final List<Widget> pages = [
HomePage(
key: homePageKey,
),
const OrderPage(),
const ProfilePage()
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: pages,
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,
onTap: (index) {
setState(() {
_currentIndex = index;
});
if (_currentIndex == 0) {
homePageKey.currentState!.toMyLocation();
}
},
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: ''),
// BottomNavigationBarItem(icon: Icon(Icons.gas_meter), label: ''),
BottomNavigationBarItem(icon: Icon(Icons.note_alt), label: ''),
BottomNavigationBarItem(icon: Icon(Icons.person), label: ''),
],
),
);
}
}
```
阅读全文