skip to Main Content

We are trying to upgrade our flutter project to null safety migration using the following link https://dart.dev/null-safety/migration-guide.

dart pub outdated –mode=null-safety – Successful dart pub get – Successful Migrate your code by hand- https://dart.dev/null-safety/migration-guide#migrating-by-hand – Successful dart migrate – Successful

Facing error in the below code while trying to run the flutter command(Flutter run)

 static Future<AppStrings> getAppText(String local) async {
    var appTextBox = await Hive.openBox("appTextBox");
    AppStrings appText = new AppStrings(
      mainPageTitle: appTextBox.get('mainPageTitle'),
      timeText: appTextBox.get('timeText'),
      minutesText: appTextBox.get('minutesText'),
      mainPageSubtitle: appTextBox.get('mainPageSubtitle'),
      mainPageParagraph: appTextBox.get('mainPageParagraph'),
      mainPageButton: appTextBox.get('mainPageButton'),
      restartButton: appTextBox.get('restartButton'),
      backButton: appTextBox.get('backButton'),
      profileTitle: appTextBox.get('profileTitle'),
      loadingPageSubtitle: appTextBox.get('loadingPageSubtitle'),
      loadingPageBottomText: appTextBox.get('loadingPageBottomText'),
      loadingPageTitle: appTextBox.get('loadingPageTitle'),
      profileButton: appTextBox.get('profileButton'),
      resultRestart: appTextBox.get('resultRestart'),
      resultTitle: appTextBox.get('resultTitle'),
      resultSwipe: appTextBox.get('resultSwipe'),
      secondaryTitle: appTextBox.get('secondaryTitle'),
      tretiaryProductTitle: appTextBox.get('tertiaryTitle'),
    );
    return appText;
  }

Update:-

This is how we are calling this method from main.dart file

AppStrings? appText = (await DatabaseUtils.getAppText(local ?? ''));
  return Data(
      allProfiles: allProfiles,...........
)

2

Answers


  1. change to
    getAppText(String? local)
    or
    getAppText(String local ?? ”)

    Login or Signup to reply.
  2. Try this:

     static Future<AppStrings?> getAppText(String local) async {
       var appTextBox = await Hive.openBox("appTextBox");
       AppStrings? appText = new AppStrings(
         mainPageTitle: appTextBox.get('mainPageTitle'),
         timeText: appTextBox.get('timeText'),
         minutesText: appTextBox.get('minutesText'),
         mainPageSubtitle: appTextBox.get('mainPageSubtitle'),
         mainPageParagraph: appTextBox.get('mainPageParagraph'),
         mainPageButton: appTextBox.get('mainPageButton'),
         restartButton: appTextBox.get('restartButton'),
         backButton: appTextBox.get('backButton'),
         profileTitle: appTextBox.get('profileTitle'),
         loadingPageSubtitle: appTextBox.get('loadingPageSubtitle'),
         loadingPageBottomText: appTextBox.get('loadingPageBottomText'),
         loadingPageTitle: appTextBox.get('loadingPageTitle'),
         profileButton: appTextBox.get('profileButton'),
         resultRestart: appTextBox.get('resultRestart'),
         resultTitle: appTextBox.get('resultTitle'),
         resultSwipe: appTextBox.get('resultSwipe'),
         secondaryTitle: appTextBox.get('secondaryTitle'),
         tretiaryProductTitle: appTextBox.get('tertiaryTitle'),
       );
    
       return appText;
     }
    

    And try leave the call like you showed above.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search