I'm trying to getData from database with the help of sqflite.

Even though , I use async and await, it always returns a list of instance of my Model.

I have check in the db file , but it's fine. just get problem in this .

late StoryDatabase storyDatabase = StoryDatabase();

  @override

     void initState() {
        // TODO: implement initState
        super.initState();
         storyDatabase = StoryDatabase();

        getDataTest();
      }

     void getDataTest() async {
        test = await storyDatabase.getData();
        print("test result1 $test");

        setState(() {
          print("test result $test");
        });
      }

Can anyone explain it for me , please ? @@


Solution 1: Abhinav kumar sintoo

Use DichangeDependencies for Async Function not initState

late StoryDatabase storyDatabase = StoryDatabase();

bool _isinit = true;

  @override
     void initState() {
        // TODO: implement initState
        super.initState();
         storyDatabase = StoryDatabase();

      }

      void didChangeDependencies() async{
        if (_isinit) {
            await getDataTest();
          _isinit = false;
        }
        super.didChangeDependencies();
      }

     void getDataTest() async {
        test = await storyDatabase.getData();
        print("test result1 $test");

        setState(() {
          print("test result $test");
        });
      }