Skyost / RateMyApp

This plugin allows to kindly ask users to rate your app if custom conditions are met (eg. install time, number of launches, etc...).
https://pub.dev/packages/rate_my_app
MIT License
273 stars 111 forks source link

LateInitializationError: Field 'minimumDate' has not been initialized #116

Closed gestshb closed 2 years ago

gestshb commented 2 years ago

Hi I get the error when i invoke rate dialge -> rate us The Exception :

E/flutter (30349): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: LateInitializationError: Field 'minimumDate' has not been initialized. E/flutter (30349): #0 MinimumDaysCondition.minimumDate (package:rate_my_app/src/conditions.dart) E/flutter (30349): #1 MinimumDaysCondition.saveToPreferences (package:rate_my_app/src/conditions.dart:60:44) E/flutter (30349): #2 RateMyApp.save (package:rate_my_app/src/core.dart:67:23) E/flutter (30349): <asynchronous suspension> E/flutter (30349): #3 RateMyApp.callEvent (package:rate_my_app/src/core.dart:268:7) E/flutter (30349): <asynchronous suspension> E/flutter (30349): #4 RateMyAppRateButton.onButtonClicked (package:rate_my_app/src/dialogs.dart:376:5) E/flutter (30349): <asynchronous suspension> E/flutter (30349): #5 _RateMyAppDialogButton.build.<anonymous closure> (package:rate_my_app/src/dialogs.dart:344:11) E/flutter (30349): <asynchronous suspension>

I have edited the method that throws the exception and the issue solved File : condition.dart

befor: @override Future<void> saveToPreferences( SharedPreferences preferences, String preferencesPrefix) { return preferences.setInt( preferencesPrefix + 'minimumDate', minimumDate.millisecondsSinceEpoch); }

After: @override Future<void> saveToPreferences( SharedPreferences preferences, String preferencesPrefix) { minimumDate = _now(); return preferences.setInt( preferencesPrefix + 'minimumDate', minimumDate.millisecondsSinceEpoch); }

Skyost commented 2 years ago

I think you should call rateMyApp.init() before using it.