1
class _ProfilePageState extends State<ProfilePage> {
  String tmpimage;

  Uint8List TmpBytesImage;
  File pimage;

  void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      TmpBytesImage= profileimage();
    });
  }

  profileimage() async {
    var userimage1 = await DBHelper().getuserIMAGE1('roro');
    print(userimage1);
    if (userimage1 == Null) {
      print('Empty');
    } else {
      setState(() {
        userimage1.map((e) {
          tmpimage = e['image0'];
        }).toList();
        print(tmpimage);
        return Base64Decoder().convert(tmpimage);
      });
    }
  }

The first error was:

Only static members can be accessed in initializers

I added :

void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      TmpBytesImage= profileimage();
    });
  }

Then it seemed to be working normally.

But there is a null value in the TmpBytesImage. How to fix it?

1 Answer 1

1

That's because you were not awaiting on your future method. Just replace your initState with this:

void initState() {
  super.initState();
  Future.delayed(Duration.zero, () async{
    TmpBytesImage = await profileimage();
  });
}
Sign up to request clarification or add additional context in comments.

5 Comments

still Null,,,,,
Can you tell me what print(userimage1); is printing on console?
when I use print(userimage1);, it's NULL on the console.
Which actually means there is something your database returns you null, and you return this null to your TmpBytesImage, so there is no problem in above solution, all you need to do is debug your app and check why database is returning null for roro
In the profileimage() , it contains values, but onTap:() print(userimage1); is not contained in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.