createFirebaseMainWithoutOnBoarding static method
Future<void>
createFirebaseMainWithoutOnBoarding(
- String projectName
)
Implementation
static Future<void> createFirebaseMainWithoutOnBoarding(
String projectName) async {
// change the content of main.dart
final File mainFile = File('lib/main.dart');
mainFile.writeAsStringSync('''
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:$projectName/firebase_options.dart';
import 'package:$projectName/features/auth/ui/auth_screen.dart';
import 'package:$projectName/shared/nav_bar.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasError) {
return Text(snapshot.error.toString());
}
if (snapshot.connectionState == ConnectionState.active) {
if (snapshot.data == null) {
return const AuthScreen();
} else {
return const NavigationScreen();
}
}
return const Center(
child: CircularProgressIndicator(),
);
},
),
);
}
}
''');
}