I am trying to migrate an old Flutter project to Null Safety.
This is the main.dart code:
import 'dart:async';
import 'dart:convert';
import 'package:capenergy_ns/pantallas/my_home_screen.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:riverpod/riverpod.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:splashscreen/splashscreen.dart';
import 'constantes/constantes.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
var email = prefs.getString('email');
runApp(
ProviderScope(
child: EasyLocalization(
path: "assets/translations",
saveLocale: true,
supportedLocales: [Locale('en', 'EN'), Locale('es', 'ES')],
child: MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('es', 'ES'),
const Locale('en', 'EN'),
],
home: email == null || email == '' ? Splash2() : MyHomePage())),
),
);
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Capenergy',
theme: ThemeData(
backgroundColor: Colors.white,
),
home: MyHomePage(),
);
}
}
My current issue is that the line ProviderScope(
is marked as error with this explanation:
The function 'ProviderScope' isn't defined
I think ProviderScope belongs to the package Riverpod, which is already installed.
What am I doing wrong?
CodePudding user response:
And flutter_riverpod
on pubspec.yaml
, and import package:flutter_riverpod
.
import 'package:flutter_riverpod/flutter_riverpod.dart';