0

i add new data then reopen app not showing my last adding data. but if click input my data coming. how can solve this issue. My codes: https://github.com/basriyildiz/yildiz/blob/master/lib/screens/maliyet_hesaplama.dart

if you want check my db_helper: https://github.com/basriyildiz/yildiz/blob/master/lib/utils/db_helper.dart

thank you so much and sorry for my english.

11Themis
  • 3
  • 2

1 Answers1

0

I think the problem resides here.

_databaseHelper.tumMaliyetler().then((tumAnalizleriTutanMapListesi) {
  for (Map<String, dynamic> okunanAnalizMapi
      in tumAnalizleriTutanMapListesi) {
    maliyetListesi
        .add(Maliyet.dbdenOkudugunMapiObjeyeDonustur(okunanAnalizMapi));
  }

  debugPrint("adas");
  debugPrint(malzemeAdi.text.toString());
});

You are resolving a future here, which means that this code will be "sometime" executed in the future.

I would try the solution shown here: https://stackoverflow.com/a/51901192/9479695

@override
 void initState() {
   super.initState();
   asyncMethod();
}

void asyncMethod() async {
  final tumAnalizleriTutanMapListesi = await _databaseHelper.tumMaliyetler();
  // ... fill maliyetListesi here
}

I would also suggest reading about async / await in dart here https://dart.dev/codelabs/async-await

Also about how to use them in Flutter with the StreamBuilder here https://api.flutter.dev/flutter/widgets/StreamBuilder-class.html and FutureBuilder here https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html

smotastic
  • 388
  • 1
  • 11