It seems to be downloading the assets from the url as i can see it in the response, but the .tr() method fails to read the key from the file. Please find the below implementation
This is the code i m using
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:easy_localization_loader/easy_localization_loader.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
runApp(
EasyLocalization(
supportedLocales: [Locale('en'), Locale('hi')],
startLocale: Locale('en'),
useOnlyLangCode: true,
path:
'https://translations-web-three.vercel.app/assets', // <-- change the path of the translation files
fallbackLocale: Locale('en'),
assetLoader: HttpAssetLoader(),
child: MyApp()),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@OverRide
State createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@OverRide
Widget build(BuildContext context) {
print(context.locale.toString());
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(context.tr('title')), // => This doesn't seem to work
),
body: Center(
child: Text(
'This is a localization example',
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
The error in debug console
Restarted application in 99ms.
[log] easy localization loader: load http https://translations-web-three.vercel.app/assets
[🌎 Easy Localization] [DEBUG] Localization initialized
[🌎 Easy Localization] [DEBUG] Start
[🌎 Easy Localization] [DEBUG] Init state
[🌎 Easy Localization] [INFO] Start locale loaded en
[🌎 Easy Localization] [DEBUG] Build
[🌎 Easy Localization] [DEBUG] Init Localization Delegate
[🌎 Easy Localization] [DEBUG] Init provider
[🌎 Easy Localization] [DEBUG] Load Localization Delegate
https://translations-web-three.vercel.app/assets/en.json
26
{'title: Hello!}
en
[🌎 Easy Localization] [WARNING] Localization key [title] not found