「Flutter/UI/ListView/基本」の版間の差分
提供: 初心者エンジニアの簡易メモ
行48: | 行48: | ||
); | ); | ||
}, | }, | ||
+ | ), | ||
+ | ); | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | 枠線あり、クリック可能 | ||
+ | <pre> | ||
+ | class _MyHomePageState extends State<MyHomePage> { | ||
+ | void _click() { | ||
+ | print("click"); | ||
+ | } | ||
+ | @override | ||
+ | Widget build(BuildContext context) { | ||
+ | const data = [ | ||
+ | "taro", "jiro", "saburo", | ||
+ | ]; | ||
+ | return Scaffold( | ||
+ | appBar: AppBar( | ||
+ | title: Text(widget.title), | ||
+ | ), | ||
+ | body: ListView.builder( | ||
+ | itemCount: data.length, | ||
+ | itemBuilder: (context, int index) { | ||
+ | return InkWell( | ||
+ | child: Card( | ||
+ | child: Padding( | ||
+ | child: Text(data[index],), | ||
+ | padding: EdgeInsets.all(20.0),), | ||
+ | ), | ||
+ | onTap: | ||
+ | _click, | ||
+ | ); | ||
+ | }, | ||
+ | ), | ||
+ | floatingActionButton: FloatingActionButton( | ||
+ | onPressed:() {}, | ||
+ | tooltip: 'Increment', | ||
+ | child: Icon(Icons.add), | ||
), | ), | ||
); | ); |
2019年4月30日 (火) 03:33時点における版
枠線なし
class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { const data = [ "taro", "jiro", "saburo", ]; return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: ListView.builder( itemCount: data.length, itemBuilder: (context, int index) { return Padding( padding: EdgeInsets.all(8.0), child: Text( data[index], )); }, ), ); }
https://nzigen.com/flutter-reference/2018-04-17-list-view.html
枠線あり
class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { const data = [ "taro", "jiro", "saburo", ]; return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: ListView.builder( itemCount: data.length, itemBuilder: (context, int index) { return Card( child: Padding( child: Text(data[index],), padding: EdgeInsets.all(20.0),), ); }, ), ); } }
枠線あり、クリック可能
class _MyHomePageState extends State<MyHomePage> { void _click() { print("click"); } @override Widget build(BuildContext context) { const data = [ "taro", "jiro", "saburo", ]; return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: ListView.builder( itemCount: data.length, itemBuilder: (context, int index) { return InkWell( child: Card( child: Padding( child: Text(data[index],), padding: EdgeInsets.all(20.0),), ), onTap: _click, ); }, ), floatingActionButton: FloatingActionButton( onPressed:() {}, tooltip: 'Increment', child: Icon(Icons.add), ), ); } }