mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-24 16:50:47 +00:00
Convert the final 12 multi-screen apps to the validated pattern: lib/main.dart keeps only the MaterialApp bootstrap (plus firebase init where that is genuine bootstrap), and a new lib/example.dart holds the entry screen and focused example code, importing existing supporting files. firebase_crash keeps its runZonedGuarded bootstrap in main.dart and extracts only CrashApp. Apps: bmi_calculator, covid19_mobile_app, expense_planner, firebase_crash_reporting, firebase_google_authentication, lunch_app, navigation_drawer, news_memes_app, save_data_locally_with_sqlite, todo_list_using_provider, unit_testing, using_firebase_db
61 lines
1.6 KiB
Dart
61 lines
1.6 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'example.dart';
|
|
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
runZonedGuarded(() {
|
|
runApp(App());
|
|
}, (error, stackTrace) {
|
|
// Pass all uncaught errors from the framework to Crashlytics.
|
|
FirebaseCrashlytics.instance.recordError(error, stackTrace);
|
|
});
|
|
}
|
|
|
|
class App extends StatelessWidget {
|
|
const App({super.key});
|
|
|
|
//initialise firebase and crashlytics
|
|
Future<void> _initializeFirebase() async {
|
|
await Firebase.initializeApp();
|
|
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("Crash App"),
|
|
),
|
|
body: FutureBuilder(
|
|
future: _initializeFirebase(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasError) {
|
|
return Center(
|
|
child: Text("Unable to initialise Firebase"),
|
|
);
|
|
}
|
|
//firebase and crashlytics initialise complete
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
return const Example();
|
|
}
|
|
return Center(
|
|
child: Column(
|
|
children: [
|
|
CircularProgressIndicator(),
|
|
Text("Initialising Firebase")
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|