FutureBuilder运行两次错误

时间:2019-05-01 04:34:51

标签: dart flutter flutter-layout

我为

添加了调试点
  • future: _futureData
  • Future getRegister1() async{首先运行getRegister1(),然后运行future: _futureData,然后再次运行getRegister1()两次 屏幕上出现_mainCategory状态小部件

    class _mainCategory extends State<mainCategory3> {
      Future _futureData;
    
      @override
      void initState() {
          super.initState();    
          _futureData = getRegister1();
      }
    
      @override
      Widget build(BuildContext context) {
    
        return Scaffold(
    

    体内的FutureBuilder

    body: FutureBuilder(
      future: _futureData,
         builder: (BuildContext context, AsyncSnapshot snapshot) {
    

    getRegister1()

       Future getRegister1() async {
        //this data coming from cache (sqflite)
        List _catLocal = (await HelperDatabase1().displayRegisterCat());
        List _defCatLocal = (await HelperDatabase1().display());
    ...
    }
    

完整代码https://github.com/flutter/flutter/issues/31838

enter image description here

0 个答案:

没有答案