我想知道当我使用FutureProvider时如何获取更新的数据。
单击按钮后如何再次获取并显示更新的数据?
它有好的方法吗?还是我应该放弃使用FutureProvider?
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FutureProvider(
create: (_) async => TestDao().findAll(),
child: MyHomePage(title: 'Flutter Demo Home Page')),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var testData = Provider.of<List<String>>(context);
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
TestDao().insert('test');
});
},
child: Icon(Icons.add),
),
body: Text('$testData'),
);
}
}