anilcancakir / flutter-internationalization

Flutter Internationalization by Using JSON Files
19 stars 5 forks source link

Widget testing not working #3

Open DhudumVishal opened 5 years ago

DhudumVishal commented 5 years ago

Your solution solved my problem of translation per module explained here. I did that by adding multiple JSONs per module. But this caused all my unit and widget testing to fail. Couldn't find any solution for this.

Below is the test case I have written for your repository, which is not working, but if I remove localization from material widget and Text widget it works fine. This also works with the flutters usual Localization. Please let me know what can be done to fix this.

    import 'package:flutter/material.dart';
    import 'package:flutter_localizations/flutter_localizations.dart';
    import 'package:flutter_test/flutter_test.dart';
    import 'package:internationalization/main.dart';

    void main() {
      Future<Null> _buildMainPage(WidgetTester tester) async {
        await tester.pumpWidget(
          MaterialApp(
          supportedLocales: [
            const Locale('tr', 'TR'),
            const Locale('en', 'US')
          ],
          localizationsDelegates: [
            const DemoLocalizationsDelegate(),
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate
          ],
          localeResolutionCallback: (Locale locale, Iterable<Locale> supportedLocales) {
            for (Locale supportedLocale in supportedLocales) {
              if (supportedLocale.languageCode == locale.languageCode || supportedLocale.countryCode == locale.countryCode) {
                return supportedLocale;
              }
            }
            return supportedLocales.first;
          },
          title: 'Flutter Internationalization',
          home: new MyPage(),
        )
        );
      }

      testWidgets('test for MyPage', (WidgetTester tester) async {
        //Setup
        //load email_form page
        await _buildMainPage(tester);

        //check if button appears
        expect(find.byType(Scaffold), findsOneWidget);
        expect(find.text('Hello world'), findsOneWidget);
      });
    }
AntonFloh commented 4 years ago

It doesn't work :(