Last active
December 24, 2019 12:43
-
-
Save nmaruy27/c8de7361e86e76d4bdf199c2aeedbeb0 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'; | |
class ListViewWidget extends StatefulWidget { | |
@override | |
_ListViewWidgetState createState() => _ListViewWidgetState(); | |
} | |
class _ListViewWidgetState extends State<ListViewWidget> { | |
Future<List<String>> _data; | |
@override | |
void initState() { | |
super.initState(); | |
_data = HogeData().getHogeData(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('List'), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon(Icons.swap_vert), | |
onPressed: () => _reload(), | |
), | |
body: FutureBuilder<List<String>>( | |
future: _data, | |
builder: (context, snapshot) { | |
switch (snapshot.connectionState) { | |
case ConnectionState.none: | |
break; | |
case ConnectionState.active: | |
case ConnectionState.waiting: | |
return Center(child: SizedBox(height: 50.0, width: 50.0, child: CircularProgressIndicator())); | |
case ConnectionState.done: | |
if (snapshot.hasError) { | |
return Text('${snapshot.error}'); | |
} | |
if (snapshot.hasData) { | |
return ListView.builder( | |
itemCount: snapshot.data.length, | |
itemBuilder: (context, index) => ListItem(snapshot.data[index]), | |
); | |
} | |
} | |
return null; | |
}), | |
); | |
} | |
void _reload() { | |
_data = HogeData().getHogeData(); | |
setState(() {}); // ★これ! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment