easy_localization restart the whole app every time I using hot reload - flutter

I am using easy_localization for translations in my Flutter app. everything is fine but while developing every time I use hot reload the whole app is restarted.
The console shows that easy_localization is reinitialized when hot reload:
and this is my code:
runApp(
ProviderScope(
overrides: [
prefsProvider.overrideWithValue(prefs),
],
child: EasyLocalization(
supportedLocales: const [Locale('en')],
path: 'assets/translations',
fallbackLocale: const Locale('en', 'US'),
child: const RavenApp(),
saveLocale: true,
),
),
);
Note: I tried to remove EasyLocalization and the issue despaired.

Related

Changing SyncFusion Flutter calendar language

I am trying to include SyncFusion Flutter calendar in my Flutter app.
I need to change the locale for the calendar.
I have included following code just inside the MaterialApp widget
child: MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
SfGlobalLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('zh'),
const Locale('he'),
const Locale('ru'),
const Locale('fr', 'BE'),
const Locale('fr', 'CA'),
const Locale('ja'),
const Locale('de'),
const Locale('hi'),
const Locale('ar'),
],
locale: const Locale('zh'),
I have also included:
import 'package:syncfusion_localizations/syncfusion_localizations.dart';
But both lines below are marked as error:
Undefined name 'GlobalMaterialLocalizations
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

How I can set the default language in flutter using easy localization?

I'm trying to set the Arabic 'ar' the default language for my app, but it still launch in English.
Here's my code in the runApp in main.dart
runApp(
EasyLocalization(
supportedLocales: [
Locale('en'),
Locale('ar'),
],
fallbackLocale: Locale('en'),
assetLoader: CodegenLoader(),
path: 'assets/translations',
startLocale: Locale('ar'),
child: MyApp(),
),
);
You can read this, step by step :
https://blog.logrocket.com/internationalizing-app-flutter-easy-localization/
It is well explained.

Flutter web directionality unexpected null value

I am using flutter web. I am using GetX package to manage my states & navigation. When the app starts everything is working fine and I am able to navigate to other pages without any problems.
The problem is when I press reload on my chrome browser the app breaks I get this error.
[GETX] Instance "GetMaterialController" has been created
[GETX] Instance "GetMaterialController" has been initialized
════════ Exception caught by widgets library ═══════════════════════════════════
The following TypeErrorImpl was thrown building Directionality(textDirection: ltr):
Unexpected null value.
The relevant error-causing widget was
Directionality
../…/root/get_material_app.dart:328
GetMaterialApp code:
GetMaterialApp(
title: 'My Web App',
debugShowCheckedModeBanner: false,
textDirection: TextDirection.ltr,
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: SignIn.routeName,
getPages: [
GetPage(
name: Home.routeName,
page: () => const Home(),
middlewares: [AuthMiddleware()],
),
GetPage(
name: SignIn.routeName,
page: () => SignIn(),
middlewares: [AuthMiddleware()],
),
GetPage(
name: SignUp.routeName,
page: () => SignUp(),
middlewares: [AuthMiddleware()],
),
],
);
I have even added textDirection: TextDirection.ltr. No errors of any type when I first run the app. The app breaks after I click reload.
I think I have a similar setup to you. I'm using GetX for route management.
I am using a static const String routeName = '/_login_page'; field in my Login page.
Here is my GetMaterialApp method:
return GetMaterialApp(
debugShowCheckedModeBanner: false,
textDirection: TextDirection.ltr,
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: LoginPage.routeName,
getPages: [
GetPage(
name: LoginPage.routeName,
page: () => const LoginPage(),
),
],
);
If I change the value of the route field in my Login page while the app is running and reload the browser, it consistently throws that error for me. If I then stop my project and rerun it, my works fine. I suspect the routeName field is being cached and when it's changed during runtime, it no longer matches.
Solution: If you rename your routeName field, stop and then rerun your project.

How to change initial language of flutter app?

I am trying to create Arabic flutter app and the default language of flutter app is English , I want the app to start with Arabic language , So how can I achieve this ?
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('ar'),
],
locale: const Locale('ar'),
);

How to use provider beetween several classes in flutter?

I am creating a register app in flutter, but there is too much information tu use a single screen, so I decided to use tab views in the screens and separate the screens in objects of a drawer.
but I needed to use the information from diferent screens to saved it. so I think about using a Multiprovider. but when I try to use the information in the provider it throws:
Could not find the correct Provider<General> above this Baseformularios Widget
my implementation is like this:
Here is my drawer with the first field General, that is basic information about the client,
as you can see the provider is created here and the body: is supplied by a variable called bodycontent, that will be over written when a try to change the form, but when I try to print the name of the user it throws the error above.
MultiProvider(
providers: [
ChangeNotifierProvider<General>(
create: (context)=>General(),
)
],
child: Scaffold(
appBar: AppBar(
title: Text("Historias clinicas"),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.check),
onPressed: (){
print(Provider.of<General>(context).nombre);
Provider.of<General>(context).addCLiente();
},
)
],
),
body: bodycontent,
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
AspectRatio(
aspectRatio: 0.001/0.001,
child: DrawerHeader(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.white,Colors.blueAccent]
),
),
),
ListTile(
title: Text("General"),
onTap: (){
setState(() {
bodycontent = I_II_III_IV();
});
Navigator.pop(context);
},
),
],
),
),
),
);
and here is the usage on the form general:
Provider.of<General>(context).set(nombre.text,
"Apellido hay que quitar en la funcion",
edad.text,
_currentsexo,
estado_civil.text,
direccion.text,
emergencia.text,
procedencia.text,
telefono.text,
ocupacion.text,
referencia.text,
fecha_inicio.text,
"",userid);
this save well the information, I checked it in the debugger, but the problem is in the other side.
I tried using the multiprovider in the screen before the one with the drawer, but it throwed the same error but with "above generalform". notice that I removed the multiprovider from the screen with the drawer when I tried this.
so should I declare the multiprovider in every screen to use it into it's son? because I supposed that provider where variables that you could use in every screen after the one where it's declare, or am I missunderstanding something?... Every help is very appreciated, thanks before hand.
To get access to the Provider from every where in your app, you should declare it in the main:
void main() {
runApp(MultiProvider(
providers: [
ChangeNotifierProvider<General>(
create: (context) => General(),
),
],
child: MyApp(),
));
}