Skip to content

Instantly share code, notes, and snippets.

@shriharip
Created January 8, 2020 12:10
Show Gist options
  • Save shriharip/a04ee144b5395f4285b3bfc3f3edb3e6 to your computer and use it in GitHub Desktop.
Save shriharip/a04ee144b5395f4285b3bfc3f3edb3e6 to your computer and use it in GitHub Desktop.
Flutter issue: Blank Screen.

main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'minlandsby.dart';
import 'package:hive/hive.dart';

void main() async {
  // Crashlytics.instance.enableInDevMode = true;

  // Pass all uncaught errors from the framework to Crashlytics.
  FlutterError.onError = Crashlytics.instance.recordFlutterError;

  WidgetsFlutterBinding.ensureInitialized();

  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

  var dir = await getTemporaryDirectory(); //neeed to change this later
  Hive.init(dir.path);

  runApp(MinLandsby());
  // runZoned(() {
  //   runApp(MinLandsby());
  // }, onError: Crashlytics.instance.recordError);
}

minlandsby.dart

import 'package:flutter/material.dart';
import 'package:minlandsbyv2/config/provider.dart';
import 'package:minlandsbyv2/core/utils/global_translations.dart';
import 'package:minlandsbyv2/ui/router.dart';
import 'package:provider/provider.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:minlandsbyv2/ui/common/theme.dart';
import 'core/constants/app_constants.dart';

class MinLandsby extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: providers,
      child: MaterialApp(
        title: 'MinLandsby',
        localizationsDelegates: [
          GlobalTranslations
              .delegate, // https://resocoder.com/2019/06/01/flutter-localization-the-easy-way-internationalization-with-json/
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: [const Locale('en'), const Locale('da')],
        localeResolutionCallback: (locale, supportedLocales) {
          // Check if the current device locale is supported
          for (var supportedLocale in supportedLocales) {
            if (supportedLocale.languageCode == locale.languageCode) {
              return supportedLocale;
            }
          }
          // If the locale of the device is not supported, use the first one
          // from the list (English, in this case).
          return supportedLocales.first;
        },
        theme: myTheme,
        debugShowCheckedModeBanner: false,
        showPerformanceOverlay: false,
        initialRoute: RoutePaths.Home,
        onGenerateRoute: Router.generateRoute,
      ),
    );
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment