Se me presentó este inconveniente para cambiar el idioma del control month_year_picker. Este es mi código:
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:month_year_picker/month_year_picker.dart';
import 'package:provider/provider.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:worker_attendance/services/auth_service.dart';
import 'package:worker_attendance/services/db_service.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => AuthService()),
ChangeNotifierProvider(create: (context) => DbService()),
ChangeNotifierProvider(create: (context) => AttendanceService()),
],
child: MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('es')
],
debugShowCheckedModeBanner: false,
title: 'Asistencia de Operarios',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const SplashScreen(),),
);
}
}
Aqui hago el llamado:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
attendanceService.attendanceHistoryMonth,
style: const TextStyle(fontSize: 25),
),
OutlinedButton(
onPressed: () async {
final selectedDate =
await showMonthYearPicker( locale: const Locale("es", "Es"),
context: context,initialDate: DateTime.now(),firstDate: DateTime(2019),lastDate:DateTime.now());
String pickedMonth =
DateFormat('MMMM yyyy').format(selectedDate!);
attendanceService.attendanceHistoryMonth = pickedMonth;
},
child: const Text("Seleccionar mes")),
],
),
Me sale el siguiente error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: No MonthYearPickerLocalizations found.
E/flutter (24868): CalenderScreen widgets require MonthYearPickerLocalizations to be provided by a Localizations widget ancestor.