notification_flutter 1.0.0-alpha03 copy "notification_flutter: ^1.0.0-alpha03" to clipboard
notification_flutter: ^1.0.0-alpha03 copied to clipboard

A flutter plug-in for the native Teko Notification library (Android and iOS).

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:notification_flutter/model/get_notification_list_query.dart';
import 'package:notification_flutter/terra_notification.dart';
import 'package:terra_flutter/model/app_config.dart';
import 'package:terra_flutter/terra_api.dart';
import 'package:terra_flutter/terra_app.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  static const APP_NAME = "NotificationFlutterExample";

  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool isInitialized = false;
  late TerraNotification terraNotification;
  final deviceToken = "TestDeviceToken_${DateTime.now().millisecond}";

  @override
  void initState() {
    super.initState();
    init();
  }

  void init() async {
    await TerraApp.initTerraApp(
      appName: MyApp.APP_NAME,
      terraConfig: InitAppConfig(
        terraClientId: "niowallet:android:playstore:1.3.0-CNIO-3200",
        terraEnvironment: TerraEnv.Develop,
      ),
    );
    terraNotification = await TerraNotification.getInstance(MyApp.APP_NAME);
    setState(() {
      isInitialized = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Notification flutter example'),
        ),
        body: isInitialized
            ? body(context)
            : const Center(
                child: SizedBox.square(
                  dimension: 50,
                  child: CircularProgressIndicator(
                    color: Colors.blueAccent,
                  ),
                ),
              ),
      ),
    );
  }

  Widget body(BuildContext context) {
    return Center(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          TextButton(
            onPressed: () async {
              terraNotification.registerToken(deviceToken);
            },
            child: const Text("Register Device Token"),
          ),
          const SizedBox(
            height: 15,
          ),
          TextButton(
            onPressed: () async {
              terraNotification.unregisterToken(deviceToken);
            },
            child: const Text("Unregister Device Token"),
          ),
          const SizedBox(
            height: 15,
          ),
          TextButton(
            onPressed: () async {
              final query = GetNotificationListQuery(appId: "appId", deviceToken: deviceToken, pageSize: 10, page: 1);
              terraNotification.getNotificationList(query);
            },
            child: const Text("Get Notification List"),
          ),
          const SizedBox(
            height: 15,
          ),
          TextButton(
            onPressed: () async {
              terraNotification.countUnreadNotifications(deviceToken);
            },
            child: const Text("Count Unread Notifications"),
          ),
          const SizedBox(
            height: 15,
          ),
          TextButton(
            onPressed: () async {
              const notificationId = 1;
              terraNotification.markReadNotification(notificationId);
            },
            child: const Text("Mark Read Notification"),
          ),
          const SizedBox(
            height: 15,
          ),
          TextButton(
            onPressed: () async {
              terraNotification.markReadAllNotification(deviceToken);
            },
            child: const Text("Mark Read All Notification"),
          ),
          const SizedBox(
            height: 15,
          ),
        ],
      ),
    );
  }
}
0
likes
140
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter plug-in for the native Teko Notification library (Android and iOS).

Repository

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on notification_flutter