前提
flutter始めたてでCRUD機能の学習をしています。
参考URLのコードをコピペしたところ、エラーが発生しました。
参考URL:https://kimuralog.com/?p=2283
発生している問題・エラーメッセージ
error: The named parameter 'floatingActionButton' isn't defined. (undefined_named_parameter at [irregular_shogi] lib/main.dart:164)
該当のソースコード
main.dart
dart
1import 'package:flutter/material.dart'; 2 3import 'NoteViewModel.dart'; 4 5void main() { 6 runApp(const MyApp()); 7} 8 9class MyApp extends StatelessWidget { 10 const MyApp({Key? key}) : super(key: key); 11 12 13 Widget build(BuildContext context) { 14 return MaterialApp( 15 debugShowCheckedModeBanner: false, 16 title: 'Note', 17 theme: ThemeData( 18 primarySwatch: Colors.deepPurple, 19 ), 20 home: const HomePage()); 21 } 22} 23 24class HomePage extends StatefulWidget { 25 const HomePage({Key? key}) : super(key: key); 26 27 28 _HomePageState createState() => _HomePageState(); 29} 30 31class _HomePageState extends State<HomePage> { 32 List<Map<String, dynamic>> _memo = []; 33 34 bool _isLoading = true; 35 36 void _refreshJournals() async { 37 final data = await NoteViewModel.getNotes(); 38 setState(() { 39 _memo = data; 40 _isLoading = false; 41 }); 42 } 43 44 45 void initState() { 46 super.initState(); 47 _refreshJournals(); 48 } 49 50 final TextEditingController _titleController = TextEditingController(); 51 final TextEditingController _descriptionController = TextEditingController(); 52 53 void _showForm(int? id) async { 54 if (id != null) { 55 final existingJournal = 56 _memo.firstWhere((element) => element['id'] == id); 57 _titleController.text = existingJournal['title']; 58 _descriptionController.text = existingJournal['description']; 59 } 60 showModalBottomSheet( 61 context: context, 62 elevation: 5, 63 isScrollControlled: true, 64 builder: (_) => Container( 65 padding: EdgeInsets.only( 66 top: 15, 67 left: 15, 68 right: 15, 69 bottom: MediaQuery.of(context).viewInsets.bottom + 120, 70 ), 71 child: Column( 72 mainAxisSize: MainAxisSize.min, 73 crossAxisAlignment: CrossAxisAlignment.end, 74 children: [ 75 TextField( 76 controller: _titleController, 77 decoration: const InputDecoration(hintText: 'Title'), 78 ), 79 const SizedBox( 80 height: 10, 81 ), 82 TextField( 83 controller: _descriptionController, 84 decoration: const InputDecoration(hintText: 'Description'), 85 ), 86 const SizedBox( 87 height: 20, 88 ), 89 ElevatedButton( 90 onPressed: () async { 91 if (id == null) { 92 await _addItem(); 93 } 94 95 if (id != null) { 96 await _updateItem(id); 97 } 98 _titleController.text = ''; 99 _descriptionController.text = ''; 100 101 Navigator.of(context).pop(); 102 }, 103 child: Text(id == null ? 'Create New' : 'Update'), 104 ) 105 ], 106 ), 107 )); 108 } 109 110 Future<void> _addItem() async { 111 await NoteViewModel.createItem( 112 _titleController.text, _descriptionController.text); 113 _refreshJournals(); 114 } 115 116 Future<void> _updateItem(int id) async { 117 await NoteViewModel.updateItem( 118 id, _titleController.text, _descriptionController.text); 119 _refreshJournals(); 120 } 121 122 void _deleteItem(int id) async { 123 await NoteViewModel.deleteItem(id); 124 ScaffoldMessenger.of(context).showSnackBar(const SnackBar( 125 content: Text('Successfully deleted a journal!'), 126 )); 127 _refreshJournals(); 128 } 129 130 131 Widget build(BuildContext context) { 132 return Scaffold( 133 appBar: AppBar( 134 title: const Text('Notes'), 135 ), 136 body: _isLoading 137 ? const Center( 138 child: CircularProgressIndicator(), 139 ) 140 : ListView.builder( 141 itemCount: _memo.length, 142 itemBuilder: (context, index) => Card( 143 color: Colors.deepPurple[200], 144 margin: const EdgeInsets.all(15), 145 child: ListTile( 146 title: Text(_memo[index]['title']), 147 subtitle: Text(_memo[index]['description']), 148 trailing: SizedBox( 149 width: 100, 150 child: Row( 151 children: [ 152 IconButton( 153 icon: const Icon(Icons.edit), 154 onPressed: () => _showForm(_memo[index]['id']), 155 ), 156 IconButton( 157 icon: const Icon(Icons.delete), 158 onPressed: () => _deleteItem(_memo[index]['id']), 159 ), 160 ], 161 ), 162 )), 163 ), 164 floatingActionButton: FloatingActionButton( 165 child: const Icon(Icons.add), 166 onPressed: () => _showForm(null), 167 ), 168 ), 169 ); 170 } 171}
試したこと
エラー文で調べましたが、それらしき情報が見当たりませんでした。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/12/22 01:52