feature/localeDate #45

Merged
v4l3n71n merged 4 commits from feature/localeDate into main 2025-06-25 19:16:51 +00:00
5 changed files with 76 additions and 24 deletions

View File

@ -12,10 +12,15 @@ import 'package:intl/date_symbol_data_local.dart';
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 {
@ -24,6 +29,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 ListItemOrganizers(organizer: "default"),
debugShowCheckedModeBanner: false,
);
@ -81,6 +94,8 @@ class _MyHomePageState extends State<ListItemOrganizers> {
// function to fetch data from api and return future list of posts
static Future<List<Events>> getPosts(organizer, {count = 0}) async {
await initializeDateFormatting("fr_FR", null);
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = [];
@ -160,12 +175,13 @@ class _MyHomePageState extends State<ListItemOrganizers> {
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,

View File

@ -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<ListItemTags> {
// function to fetch data from api and return future list of posts
static Future<List<Events>> getPosts(tags, {count = 0}) async {
await initializeDateFormatting("fr_FR", null);
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = [];
@ -162,12 +177,12 @@ class _MyHomePageState extends State<ListItemTags> {
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,

View File

@ -19,11 +19,15 @@ import 'package:camera/camera.dart';
import '../classes/ad_helper.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import '../classes/auth_service.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await MobileAds.instance.initialize();
initializeDateFormatting("fr_FR", null).then((_) => runApp(const MyApp()));
await initializeDateFormatting("fr_FR", null);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
@ -32,6 +36,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 ListItemMenu(),
debugShowCheckedModeBanner: false,
);
@ -74,6 +86,7 @@ class _MyHomePageState extends State<ListItemMenu> {
bool showInputTag = true;
// Fetching events from API
static Future<List<Events>> getPosts() async {
await initializeDateFormatting("fr_FR");
PermissionStatus status = await Permission.location.status;
final List<Events> body = [];
var url = Uri.parse("${globals.api}/events");
@ -471,15 +484,13 @@ class _MyHomePageState extends State<ListItemMenu> {
// Update state after getting the response
setState(() {
if (body.isNotEmpty) {
int counter = filteredPosts.length;
// If we have results, map them to Events
filteredPosts = body
.map((e) => Events.fromJson(e as Map<String, dynamic>))
.toList();
if (counter == filteredPosts.length) {
_fetchCount--;
}
int counter = filteredPosts.length;
// If we have results, map them to Events
filteredPosts = body
.map((e) => Events.fromJson(e as Map<String, dynamic>))
.toList();
if (counter == filteredPosts.length) {
_fetchCount--;
}
});
} else {
@ -842,12 +853,13 @@ class _MyHomePageState extends State<ListItemMenu> {
}
final post = displayedPosts[index];
final startDate = DateTime.parse(post.startDate!);
final date = DateFormat.yMd().format(startDate);
final time = DateFormat.Hm().format(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,

View File

@ -270,6 +270,11 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
flutter_localizations:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:

View File

@ -29,6 +29,9 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
@ -69,6 +72,7 @@ dev_dependencies:
# The following section is specific to Flutter packages.
flutter:
generate: true
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in