path_provider: Unhandled Exception: Null check operator used on a null value

643

Resolved! I was doing hive the old way. The program worked when I called Hive.initFlutter(), not Hive.init(). By the way,

import 'package: hive_flutter / hive_flutter.dart';

and

import 'package: hive / hive.dart';

Don't forget to import both,

Current code:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Hive.initFlutter(); 
  runApp(CoozinCustomerApp());
}
Share:
643
Rustam Usmanov
Author by

Rustam Usmanov

Flutter Developer

Updated on January 01, 2023

Comments

  • Rustam Usmanov
    Rustam Usmanov over 1 year

    I have a problem while working with pat_provider.

    Error: Unhandled Exception: Null check operator used on a null value

    Code:

    void main() async {
      final appDocumentDirectory =
          await path_provider.getApplicationDocumentsDirectory();
      Hive.init(appDocumentDirectory.path);
      runApp(MyApp());
    }
    

    For more, I am using the non-nullsafety app, Right now I want to take the path to hive. what would you advise in such a case. Or should I downgrade the path_provider version?

  • padaleiana
    padaleiana over 2 years
    Please mark your answer as accepted instead of writing "resolved".