1
0
mirror of https://github.com/nisrulz/flutter-examples.git synced 2026-08-25 01:05:36 +00:00

refactor: split app wrapper from focused example code (complex apps)

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
This commit is contained in:
Nishant Srivastava
2026-08-18 00:55:18 +02:00
parent 6e3ff94bfe
commit bcb3629907
24 changed files with 429 additions and 283 deletions

View File

@@ -0,0 +1,31 @@
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
// Example: Two buttons to test Crashlytics custom logging and crash reporting.
class Example extends StatelessWidget {
const Example({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
//custom Crashlytics log message
FirebaseCrashlytics.instance.log("It's a bug");
},
child: Text("Custom Log")),
const SizedBox(height: 10),
ElevatedButton(
child: Text('Crash the app'),
onPressed: () {
FirebaseCrashlytics.instance.crash();
},
),
],
),
);
}
}

View File

@@ -4,6 +4,8 @@ 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(() {
@@ -17,12 +19,12 @@ void main() {
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(
@@ -40,7 +42,7 @@ class App extends StatelessWidget {
}
//firebase and crashlytics initialise complete
if (snapshot.connectionState == ConnectionState.done) {
return CrashApp();
return const Example();
}
return Center(
child: Column(
@@ -56,31 +58,3 @@ class App extends StatelessWidget {
);
}
}
class CrashApp extends StatelessWidget {
const CrashApp({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
//custom Crashlytics log message
FirebaseCrashlytics.instance.log("It's a bug");
},
child: Text("Custom Log")),
const SizedBox(height: 10),
ElevatedButton(
child: Text('Crash the app'),
onPressed: () {
FirebaseCrashlytics.instance.crash();
},
),
],
),
);
}
}