Wasiq Hussain
Wasiq Hussain

Reputation: 69

Flutter Push Notification

I am a beginner in Flutter. When I tried to make IOS Push Notification in my app using cloud functions. I don't why I don't get any Push Notifications in my IOS device. This is the file which is was used in my code for notifications. file It works fine for Android but didn't work in IOS. main.dart file

void main() async => {
      WidgetsFlutterBinding.ensureInitialized(),
      if (Platform.isAndroid)
        {
          await Firebase.initializeApp(),
        },
      SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
          .then(
        (_) {
          runApp(new MyApp());
        },
      )
    };

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Splash(),
      theme: ThemeData(accentColor: Colors.black38),
    );
  }
}

Upvotes: 1

Views: 280

Answers (1)

nvoigt
nvoigt

Reputation: 77285

I'm pretty sure your app has to initialize Firebase, even if the app is running on iOS. Right now, you have restricted it to Android only.

if (Platform.isAndroid) // <<==
{
  await Firebase.initializeApp(),
},

By the way, why are there commas at the end of each line? Is that a copy/paste error?

This is what it should look like if you want it Android and iOS specific:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  if (Platform.isAndroid || Platform.isIOS) {
     await Firebase.initializeApp();
  }
      
  await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

  runApp(new MyApp());
}

Upvotes: 1

Related Questions