flutter: DatePicker を日本語化する

[Flutter] DatePicker を日本語化する方法 │ Web備忘録 https://webbibouroku.com/Blog/Article/flutter-datepicker-ja#outline__1

【2021年12月版】Flutterの多言語化対応のベストプラクティスとハマりどころ – Flutter Salon https://flutter.salon/flutter/l10n/

▼今の予定一覧画面のソース

import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
import 'package:flutter/material.dart';
import 'package:care_smile/data/schedule_list_model.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:intl/intl.dart';

class ScheduleListHeader extends HookConsumerWidget {
  final ScheduleListResponse scRes; //予定一覧が格納されたレスポンス
  const ScheduleListHeader({Key? key, required this.scRes}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    ScheduleListRequest scReq =  scRes.req.copyWith(); //ディープコピーしておく
    List<Schedule> schedules = [...scRes.schedules]; //...は、spread operator
    return Column(
      children: [
        Row (
          children: [
            const SizedBox(width: 12.0),
            Expanded(flex:5,child:_dateField(scRes.req.dateFrom,'開始')),
            Expanded(flex:5,child:_dateField(scRes.req.dateTo,'終了')),
          ]
        ),

        Expanded(
          child: ListView.builder(
            itemCount: schedules.length,
            itemBuilder: (BuildContext context, int index) {
              return GestureDetector( //タップできないWidgetをタップできるようにする
                onTap: () {},
                child: ListTile(
                  title: Text(
                      "${scRes.schedules[index].receiverName}(${scRes
                          .schedules[index].receiverCode})"),
                  subtitle: Text(scRes.schedules[index].serviceName),
                ),
              );
            },
          ),
        )
      ],
    );
  }

  Widget _dateField(rdt, String lbl) => DateTimeField(
      format: DateFormat("yy/MM/dd"),
      decoration: InputDecoration(labelText: lbl),
      initialValue: rdt ?? DateTime.now(),
      onChanged: (dt) => (rdt) ,
      onShowPicker: (context, currentValue) async {
        final date = await showDatePicker(
            context: context,
            locale: const Locale("ja"),
            initialDate: currentValue ?? DateTime.now(),
            firstDate: DateTime(2020),
            lastDate: DateTime(2100));
      }
  );

}


pubspec.yamlに追記の所が解りにくかった

▼現在のpubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  font_awesome_flutter: ^9.2.0
  freezed_annotation: ^1.1.0
  build_runner: ^2.1.7
  freezed: ^1.1.0
  json_serializable: ^6.1.3
  json_annotation: ^4.4.0
  crypto: ^3.0.1
  http: ^0.13.4
  flutter_secure_storage: ^5.0.2
  hooks_riverpod: ^1.0.3
  flutter_hooks: ^0.18.2
  flutter_datetime_picker: ^1.5.1
  intl: ^0.17.0
  datetime_picker_formfield: ^2.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter
/* -----codeの行番号----- */