万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    flutterでローカライズ系のテスト

    import 'dart:ui';
    import 'package:app_name/generated/l10n.dart';
    import 'package:app_name/utils/utils.dart';
    import 'package:flutter/material.dart';
    import 'package:flutter_localizations/flutter_localizations.dart';
    import 'package:flutter_test/flutter_test.dart';
    import 'package:intl/date_symbol_data_local.dart';
    
    // ローカライズ系のテストのため
    Widget buildFrame({
      Locale locale,
      Iterable<LocalizationsDelegate<dynamic>> delegates,
      WidgetBuilder buildContent,
      LocaleResolutionCallback localeResolutionCallback,
    }) {
      return WidgetsApp(
        color: Colors.white,
        locale: locale,
        localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          S.delegate,
        ],
        localeResolutionCallback: localeResolutionCallback,
        supportedLocales: S.delegate.supportedLocales,
        onGenerateRoute: (settings) {
          return PageRouteBuilder<void>(pageBuilder: (context, _, __) {
            return buildContent(context);
          });
        },
      );
    }
    
    void main() {
      testWidgets('Localizations.localeFor in a WidgetsApp with system locale',
          (tester) async {
        BuildContext pageContext;
        await tester.pumpWidget(buildFrame(buildContent: (context) {
          pageContext = context;
    
          return Column(
            children: [
              Text(
                DateUtil.fromTimeFormat(
                  pageContext,
                  DateTime(2021, 4, 12, 11, 00),
                ),
              ),
              Text(
                DateUtil.dateWithDayFormat(
                  pageContext,
                  DateTime(2021, 4, 12, 11, 00),
                ),
              ),
            ],
          );
        }));
    
        await tester.idle();
        // The async delegator load will require build on the next frame. Thus, pump
        await tester.pump();
    
        debugPrint('fromTimeFormatをテスト');
        expect(find.text('4/12(月) 11:00~'), findsOneWidget);
    
        debugPrint('dateWithDayFormatをテスト');
        expect(find.text('4/12 (月)'), findsOneWidget);
      });