createNotficationSystemMainWithoutOnboarding static method

Future<void> createNotficationSystemMainWithoutOnboarding(
  1. String projectName
)

Implementation

static Future<void> createNotficationSystemMainWithoutOnboarding(
    String projectName) async {
  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';
import 'package:$projectName/features/notification/services/notification_services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
await FirebaseMessaging.instance.requestPermission();
final token = await FirebaseMessaging.instance.getToken();
await NotificationService.initLocalNotifications();

  FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  print('Got a message whilst in the foreground!');
  print('Message data: \${message.data}');
  print(message.data['body']);

  NotificationService.showLocalNotification(message);


  if (message.notification != null) {
    print('Message also contained a notification: \$+{message.notification}');
  }

});
}

final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
  FlutterLocalNotificationsPlugin();


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(),
        );
      },
    ),
  );
}
}


''');
}