Flutterでよく使うウィジェット一覧とコードまとめ
※随時更新します
ボタン
テキスト
アイテム
レイアウト
FloatingActionButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('ボタンが押されました!'),
),
);
},
child: const Icon(Icons.add),
);
TextButton
TextButton(
onPressed: () {},
child: const Text('テキストボタン'),
);
ElevatedButton(
onPressed: () {},
child: const Text('ボタン'),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.favorite_sharp),
);
Text
Text(
"テキスト"
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
TextField
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'テキストフィールド',
),
),
AppBar
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: const Text('ウィジェット一覧'),
),
Drawer
Drawer(
child: ListView(
children: <Widget>[
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text('上部'),
),
ListTile(
title: const Text('アイテム1'),
onTap: () {},
),
ListTile(
title: const Text('アイテム2'),
onTap: () {},
),
],
),
);
BottomNavigationBar
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'タブ1',
),
BottomNavigationBarItem(
icon: Icon(Icons.message),
label: 'タブ2',
),
BottomNavigationBarItem(
icon: Icon(Icons.brightness_5_sharp),
label: 'タブ3',
),
],
selectedItemColor: Colors.blue,
),
Card
Card(
child: ListTile(
leading: Icon(Icons.photo),
title: Text('カード'),
subtitle: Text('カードのサブタイトル'),
),
),
Container
Container(
height: 100,
width: double.infinity,
color: Colors.blue,
);
Image
Image(
image: NetworkImage(
'URL',
),
width: 100,
height: 100,
),
Discussion