0

I added debug point for

  • future: _futureData
  • Future getRegister1() async{ first run getRegister1() and then future: _futureData and again two times run getRegister1() after that screen comes _mainCategory State Widget

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

    FutureBuilder inside Body

    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());
    ...
    }
    

full code https://github.com/flutter/flutter/issues/31838

enter image description here

primo
  • 1,340
  • 3
  • 12
  • 40
  • what is `getRegister()` used for (not `getRegister1`)? or is it just a typo? also add some `print()`s to your app and post the log output, as i am completely lost in your current control flow description – pskink May 01 '19 at 04:39
  • why don't you remove the code inside initState and just use getRegister1() instead of _futureData ? – diegoveloper May 01 '19 at 04:42
  • @diegoveloper actually what he does is better https://stackoverflow.com/a/52249579/679553 – Gazihan Alankus May 01 '19 at 04:52
  • Yeah I know but looks like it isn't working. I would use setState or streambuilder instead of FutureBuilder – diegoveloper May 01 '19 at 04:55
  • @pskink two times run on my FutureBuilder –  May 01 '19 at 05:04
  • @diegoveloper do you have any idea to solve this problem? –  May 01 '19 at 05:05
  • @GazihanAlankus do you have any idea to solve this problem? –  May 01 '19 at 05:05
  • would you post the logs? are you saying that `getRegister1()` method is called twice? or `State#build()` method is called twice? add some `print()`s in those two methods and post your logs – pskink May 01 '19 at 05:12
  • `build()` method calling again and again –  May 01 '19 at 05:15
  • where do you use `subCategory` widget? also try to name you classes [UpperCamelCase](https://www.dartlang.org/guides/language/effective-dart/style#do-name-types-using-uppercamelcase) way – pskink May 01 '19 at 05:22
  • the subCategory is next page. It's a new Stateful Widget same like this class –  May 01 '19 at 05:24
  • `_mainCategory` is a `State` for `subCategory`? right? your class naming is just horrible – pskink May 01 '19 at 05:27
  • no. this is full code. https://github.com/flutter/flutter/issues/31838 –  May 01 '19 at 05:30
  • ok @pskink I change my class name, before that, I need to fix this issue –  May 01 '19 at 05:32
  • so what is `_mainCategory` actually? `class _mainCategory extends State` or `class _mainCategory extends State` - i am lost... – pskink May 01 '19 at 05:35
  • @pskink any solution? –  May 01 '19 at 06:12
  • i have no idea where you use your `mainCategory3` and where you are rebuilding it – pskink May 01 '19 at 06:14
  • `mainCategory3` is my StatefullWidget. `subCategory` is next page StatefullWidget. –  May 01 '19 at 06:20
  • next page? what next page? why dont you simply post the complete code? whee is `mainCategory3` used? – pskink May 01 '19 at 06:42
  • @diegoveloper if you remove futureData in `initState` it will loose scroll position when you come back(one examoke) right?. – Blasanka May 01 '19 at 06:50

0 Answers0