pushportal_package 0.0.2 copy "pushportal_package: ^0.0.2" to clipboard
pushportal_package: ^0.0.2 copied to clipboard

Push notification project.

example/lib/main.dart

// ignore_for_file: avoid_print

import 'dart:async';

import 'package:example/controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:pushportal_package/pushportal_package.dart';
// import 'package:uuid/uuid.dart';
import 'app_config.dart';
import 'app_data.dart';
import 'widgets/alert_button.dart';
import 'widgets/mailbox.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  initializeDateFormatting();
  await PushPortal.instance.initializeApp(
    username: username,
    password: password,
  );

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  final textTheme = const TextTheme(
    bodyText1: TextStyle(
        fontSize: 16.0, fontWeight: FontWeight.normal, color: Colors.black),
    bodyText2: TextStyle(
        fontSize: 18.0, fontWeight: FontWeight.normal, color: Colors.black),
    headline1: TextStyle(
        fontSize: 36.0, fontWeight: FontWeight.normal, color: Colors.black),
    headline2: TextStyle(
        fontSize: 34.0, fontWeight: FontWeight.w700, color: Colors.black),
    headline3: TextStyle(
        fontSize: 32.0, fontWeight: FontWeight.normal, color: Colors.black),
    headline4: TextStyle(
        fontSize: 30.0, fontWeight: FontWeight.normal, color: Colors.black),
    headline5: TextStyle(
        fontSize: 24.0, fontWeight: FontWeight.w500, color: Colors.black),
    headline6: TextStyle(
        fontSize: 24.0, fontWeight: FontWeight.w500, color: Colors.black),
    subtitle1: TextStyle(
        fontSize: 20.0, fontWeight: FontWeight.w500, color: Colors.black),
    subtitle2: TextStyle(
        fontSize: 18.0, fontWeight: FontWeight.normal, color: Colors.black),
    caption: TextStyle(
        fontSize: 16.0, fontWeight: FontWeight.normal, color: Colors.black),
    button: TextStyle(
        fontSize: 18.0, fontWeight: FontWeight.w500, color: Colors.white),
    overline: TextStyle(
        fontSize: 14.0, fontWeight: FontWeight.normal, color: Colors.black),
  );

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.yellow,
        textTheme: textTheme,
        fontFamily: 'DBHeaven',
        dialogTheme: DialogTheme(
            alignment: Alignment.center,
            contentTextStyle: Theme.of(context).textTheme.bodyText1),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
      navigatorKey: AppConfig.navigatorKey,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<void> prepareData() async {
    await AppController.current.prepareAccessToken();
    var uuid = "6b964fa0-7b26-11ed-a950-71a59683d1eb"; //Uuid();
    await AppController.current.registerFirebaseMessagingToken(uuid);
    await AppController.current.getUnreadCount();
    PushPortal.instance.setCallbackShowFlutterNotification((message) {
      print("----\nhandle show flutter notification\n----");
    });
    PushPortal.instance.setCallbackReceivePayload((message) {
      print("----\ncallback Receive Payload\n----");
    });
    PushPortal.instance.setCallbackInitialMessage((massage) async {
      print("----\ncallback Initial Message\n----");
      WidgetsBinding.instance.addPostFrameCallback((_) async {
        Get.to(const Mailbox());
      });
    });
    setState(() {});
  }

  @override
  void initState() {
    super.initState();
    prepareData();

    PushPortal.handleReceivePayload.listen((event) async {
      Get.to(const Mailbox());
    });
  }

  @override
  Widget build(BuildContext context) {
    final appWidth = MediaQuery.of(context).size.width;
    final appHeight = MediaQuery.of(context).size.height;
    return Scaffold(
      backgroundColor: AppConfig.primary_color,
      body: Container(
        margin: const EdgeInsets.only(top: 34),
        width: appWidth,
        height: appHeight,
        decoration: const BoxDecoration(
            // color: Colors.green,
            image: DecorationImage(
                fit: BoxFit.fitWidth,
                image: AssetImage('assets/images/event_copy_2.jpg'))),
        child: Stack(
          children: <Widget>[
            Padding(
                padding: const EdgeInsets.only(left: 5, top: 5),
                child: SizedBox(
                    // color: Colors.green,
                    width: 50,
                    height: 38,
                    child: MailboxAlertButton())),
          ],
        ),
      ),
    );
  }
}
1
likes
0
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

Push notification project.

License

unknown (license)

Dependencies

dio, firebase_core, firebase_messaging, flutter

More

Packages that depend on pushportal_package