nations 0.0.4 nations: ^0.0.4 copied to clipboard
queen support for localization in flutter, part of queen framework
import 'package:example/config/lang.dart';
import 'package:example/page2.dart';
import 'package:flutter/material.dart';
import 'package:nations/nations.dart';
Future<void> main() async {
// TODO :: (2)
await Nations.boot(AppLangConfig());
// wrap your `MaterialApp` with NationsRoot
runApp(
// NationsRoot(
// child: const MyApp(),
// ),
NationsBuilder(
builder: (ctx) => const MyApp(),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
// TODO :: (3) pass these parameters
locale: Nations.locale,
localizationsDelegates: Nations.delegates,
supportedLocales: Nations.supportedLocales,
builder: (context, child) => child!,
/// end ot Nations params
home: const MySc(),
);
}
}
class MySc extends StatelessWidget {
const MySc({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
void _updateLocale() {
// TODO ::(5) update the locale
// Nations.updateLocale(Locale(
// Nations.locale.languageCode == 'ar' ? 'en' : 'ar',
// ));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const PageTwo(),
));
}
return Scaffold(
appBar: AppBar(title: const Text('امم Nations')),
body: const Center(
child: Text('Go To Page 2'),
),
floatingActionButton: FloatingActionButton(
onPressed: _updateLocale,
child: const Icon(Icons.translate),
),
);
}
}