From 4f4b0b609cc4495df4bfeff65d3f48d729c167ca Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Mon, 23 Jun 2025 23:25:34 +0200 Subject: [PATCH] add date locale in list by tags --- covas_mobile/lib/pages/ListItemByTags.dart | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/covas_mobile/lib/pages/ListItemByTags.dart b/covas_mobile/lib/pages/ListItemByTags.dart index 475b4ed..900e93d 100644 --- a/covas_mobile/lib/pages/ListItemByTags.dart +++ b/covas_mobile/lib/pages/ListItemByTags.dart @@ -13,10 +13,15 @@ import '../variable/globals.dart' as globals; import '../classes/MyDrawer.dart'; import '../classes/auth_service.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; // app starting point -void main() { - initializeDateFormatting("fr_FR", null).then((_) => (const MyApp())); +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + + await initializeDateFormatting("fr_FR", null); + + runApp(const MyApp()); } class MyApp extends StatelessWidget { @@ -25,6 +30,14 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( + localizationsDelegates: [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: [ + const Locale('fr', 'FR'), + ], home: const ListItemTags(tags: "default"), debugShowCheckedModeBanner: false, ); @@ -82,6 +95,8 @@ class _MyHomePageState extends State { // function to fetch data from api and return future list of posts static Future> getPosts(tags, {count = 0}) async { + await initializeDateFormatting("fr_FR", null); + SharedPreferences prefs = await SharedPreferences.getInstance(); var accessToken = prefs.getString("access_token") ?? ""; final List body = []; @@ -162,12 +177,12 @@ class _MyHomePageState extends State { itemBuilder: (context, index) { final post = posts[index]; final startDate = DateTime.parse(post.startDate!); - final date = DateFormat.yMd().format(startDate); - final time = DateFormat.Hm().format(startDate); + final dateLongue = + DateFormat('EEEE d MMMM y', 'fr_FR').format(startDate); return ListTile( title: Text('${post.name!}'), - subtitle: Text('${post.place!}\n${date} ${time}'), + subtitle: Text('${post.place!}\n${dateLongue}'), onTap: () { Navigator.push( context,