add date locale in list by tags

This commit is contained in:
Valentin CZERYBA 2025-06-23 23:25:34 +02:00
parent 2e6814c33d
commit 4f4b0b609c

View File

@ -13,10 +13,15 @@ import '../variable/globals.dart' as globals;
import '../classes/MyDrawer.dart'; import '../classes/MyDrawer.dart';
import '../classes/auth_service.dart'; import '../classes/auth_service.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
// app starting point // app starting point
void main() { void main() async {
initializeDateFormatting("fr_FR", null).then((_) => (const MyApp())); WidgetsFlutterBinding.ensureInitialized();
await initializeDateFormatting("fr_FR", null);
runApp(const MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@ -25,6 +30,14 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('fr', 'FR'),
],
home: const ListItemTags(tags: "default"), home: const ListItemTags(tags: "default"),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
); );
@ -82,6 +95,8 @@ class _MyHomePageState extends State<ListItemTags> {
// function to fetch data from api and return future list of posts // function to fetch data from api and return future list of posts
static Future<List<Events>> getPosts(tags, {count = 0}) async { static Future<List<Events>> getPosts(tags, {count = 0}) async {
await initializeDateFormatting("fr_FR", null);
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? ""; var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = []; final List<Events> body = [];
@ -162,12 +177,12 @@ class _MyHomePageState extends State<ListItemTags> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
final post = posts[index]; final post = posts[index];
final startDate = DateTime.parse(post.startDate!); final startDate = DateTime.parse(post.startDate!);
final date = DateFormat.yMd().format(startDate); final dateLongue =
final time = DateFormat.Hm().format(startDate); DateFormat('EEEE d MMMM y', 'fr_FR').format(startDate);
return ListTile( return ListTile(
title: Text('${post.name!}'), title: Text('${post.name!}'),
subtitle: Text('${post.place!}\n${date} ${time}'), subtitle: Text('${post.place!}\n${dateLongue}'),
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,