Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index out of range on Web #21

Closed
Dahleh opened this issue May 11, 2021 · 4 comments
Closed

Index out of range on Web #21

Dahleh opened this issue May 11, 2021 · 4 comments

Comments

@Dahleh
Copy link

Dahleh commented May 11, 2021

Everything is working fine with me on iOS and Android but once I run my app on the web (Chrome) I got this error from the widget LocalizedApp

════════ Exception caught by widgets library ═══════════════════════════════════
The following IndexError was thrown building MyApp(dirty):
RangeError (index): Index out of range: no indices are valid: 0

The relevant error-causing widget was
MyApp
lib/main.dart:54
When the exception was thrown, this was the stack
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 236:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 581:7             _get]
packages/localize_and_translate/src/main.dart 192:51                          get locale
packages/UnitedPalestine/main.dart 85:28                                      build
packages/flutter/src/widgets/framework.dart 4569:28                           build
...

Any extra steps I need to do to make it works on the web?

@msayed-net
Copy link
Owner

msayed-net commented May 12, 2021

No extra steps needed,

I can see the problem in MyApp not LocalizedApp

please share more details about implementation and issue

and test LocalizedApp with empty project to see if it has errors

@Dahleh
Copy link
Author

Dahleh commented May 12, 2021

I already did that here is my code

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  //await Firebase.initializeApp();
  // ignore: unused_local_variable
  
    await translator.init(
      localeDefault: LocalizationDefaultType.device,
      languagesList: <String>['ar', 'en'],
      assetsDirectory: 'assets/language/',
      apiKeyGoogle: '<Key>',
    );
  }

  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
    //runApp(MyApp());
    runApp(
      LocalizedApp(
        child: MyApp(),
      ),
    );
  });
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        Provider<AuthenticationService>(
          create: (_) => AuthenticationService(FirebaseAuth.instance),
        ),
        StreamProvider(
          create: (context) =>
              context.read<AuthenticationService>().authStateChanges,
        )
      ],
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        initialRoute: SplashScreen.routName,
        routes: {
          SplashScreen.routName: (ctx) => SplashScreen(),
          SigninScreen.routName: (ctx) => SigninScreen(),
          SignupScreen.routName: (ctx) => SignupScreen(),
          OTPScreen.routName: (ctx) => OTPScreen(),
        },
        localizationsDelegates: translator.delegates,
        locale: translator.locale,
        supportedLocales: translator.locals(),
      ),
    );
  }
}

@msayed-net
Copy link
Owner

did you try to start with empty widget screen like Container() to see if the error belongs to another code,
plus, is asset files exists !

We use this plugin in active projects right now, all cool.

@msayed-net
Copy link
Owner

closing this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants