diff --git a/lib/card_list.dart b/lib/card_list.dart new file mode 100644 index 0000000..0340941 --- /dev/null +++ b/lib/card_list.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; + +class CardList extends StatelessWidget { + final String _text; + + CardList(this._text); + + @override + Widget build(BuildContext context) { + return Card( + child: Column(mainAxisSize: MainAxisSize.max, children: [ + ListTile( + leading: FlutterLogo(), + title: Text(_text), + subtitle: Text( + "This is subtitle. Subtitle is very long and use three lines."), + selected: true, + ) + ]), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index d04fa1b..343ea68 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_list_app/card_list.dart'; void main() { runApp(MyApp()); @@ -20,15 +21,55 @@ class MyApp extends StatelessWidget { } class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({Key key, this.title, this.thumbnail}) : super(key: key); final String title; + final thumbnail; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State { + var _cardList = List(); + + @override + void initState() { + _cardList.add(CardList( + 'Text1', + )); + _cardList.add(CardList( + 'Text2', + )); + _cardList.add(CardList( + 'Text3', + )); + _cardList.add(CardList( + 'Text4', + )); + _cardList.add(CardList( + 'Text5', + )); + _cardList.add(CardList( + 'Text6', + )); + _cardList.add(CardList( + 'Text7', + )); + _cardList.add(CardList( + 'Text8', + )); + _cardList.add(CardList( + 'Text9', + )); + _cardList.add(CardList( + 'Text10', + )); + _cardList.add(CardList( + 'Text11', + )); + super.initState(); + } @override Widget build(BuildContext context) { @@ -37,39 +78,14 @@ class _MyHomePageState extends State { appBar: AppBar( title: Text('ListViewApp'), ), - body: ListView( - children: [ - _menueItem('メニュー1'), - _menueItem('メニュー2'), - _menueItem('メニュー3'), - _menueItem('メニュー4'), - _menueItem('メニュー5'), - _menueItem('メニュー6'), - _menueItem('メニュー7'), - ] - ), - ), - ); - } - - Widget _menueItem(String title) { - return GestureDetector( - child: Container( - padding: EdgeInsets.all(8.0), - decoration: new BoxDecoration( - border: new Border(bottom: BorderSide(width: 1.0, color: Colors.red)) - ), - child: Row( - children: [ - Text( - title, - style: TextStyle( - color: Colors.black, - fontSize: 20.0 - ) - ), - ], - ), + body: Container( + child: ListView.builder( + itemCount: _cardList.length, + itemBuilder: (BuildContext context, int index) { + return _cardList[index]; + }, + ), + ) ), ); }