Index
以下のようなCupertinoTavScaffoldでタブ切り替えをしたときに表題のエラーが発生しました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
@override Widget build(BuildContext context) { return CupertinoTabScaffold( tabBar: CupertinoTabBar( currentIndex: _selectedIndex, onTap: (index) => setState( () { _selectedIndex = index; }, ), items: <BottomNavigationBarItem>[ BottomNavigationBarItem( icon: const Icon(CupertinoIcons.home), label: homeName, ), BottomNavigationBarItem( icon: const Icon(CupertinoIcons.book), label: diaryName, ), BottomNavigationBarItem( icon: const Icon(CupertinoIcons.settings), label: settingName, ), ], ), tabBuilder: (BuildContext context, int index) { return CupertinoTabView( builder: (BuildContext context) { return _widgetList[_selectedIndex]; }, ); }, ); } |
切り替えたときに表示されるwidgetは以下の通り
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
class _SettingViewState extends State<SettingView> { @override Widget build(BuildContext context) { return TextFormField( decoration: const InputDecoration( icon: Icon(Icons.person), hintText: 'What do people call you?', labelText: 'Name *', ), onSaved: (String? value) { // This optional block of code can be used to run // code when the user saves the form. }, validator: (String? value) { return (value != null && value.contains('@')) ? 'Do not use the @ char.' : null; }, ); } } |
Materialで囲ってあげれば良い!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
@override Widget build(BuildContext context) { //Materialで囲ってあげれば良い return Material( child: TextFormField( decoration: const InputDecoration( icon: Icon(Icons.person), hintText: 'What do people call you?', labelText: 'Name *', ), onSaved: (String? value) { // This optional block of code can be used to run // code when the user saves the form. }, validator: (String? value) { return (value != null && value.contains('@')) ? 'Do not use the @ char.' : null; }, ), ); } |