Created
September 23, 2019 14:07
-
-
Save Liyuu8/ccdfeaa81e05d83711facea4e7a83cd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:cloud_firestore/cloud_firestore.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: '貸し借りめも', | |
theme: ThemeData( | |
primarySwatch: Colors.orange, | |
), | |
home: MyListPage(), | |
); | |
} | |
} | |
class MyListPage extends StatefulWidget { | |
@override | |
_MyListPageState createState() => _MyListPageState(); | |
} | |
class _MyListPageState extends State<MyListPage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("リスト画面"), | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(10.0), | |
child: StreamBuilder<QuerySnapshot>( | |
stream: Firestore.instance.collection('kasikari-memo').snapshots(), | |
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) { | |
if(!snapshot.hasData) { | |
return const Text('Loading...'); | |
} | |
return ListView.builder( | |
itemCount: snapshot.data.documents.length, | |
padding: const EdgeInsets.only(top: 10.0), | |
itemBuilder: (context, index) => _buildListItem(context, snapshot.data.documents[index]), | |
); | |
}, | |
), | |
), | |
); | |
} | |
Widget _buildListItem(BuildContext context, DocumentSnapshot documentSnapshot) { | |
return Card( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
ListTile( | |
leading: const Icon(Icons.android), | |
title: Text("【" + (documentSnapshot['borrowOrLend'] == "lend" ? "貸" : "借") + "】" | |
+ documentSnapshot['stuff']), | |
subtitle: Text('期限: ' + documentSnapshot['data'].toString().substring(0, 10) | |
+ "\n相手: " + documentSnapshot['user']), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment