flutter_linkid_mmp 1.1.63 flutter_linkid_mmp: ^1.1.63 copied to clipboard
Airflex.io is a Mobile Marketing Platform that offers tools for analyzing and optimizing user experiences on mobile and web platforms. It features real-time data analytics, audience segmentation, frau [...]
import 'dart:async';
import 'dart:io';
// import 'package:firebase_core/firebase_core.dart';
// import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_linkid_mmp/flutter_linkid_mmp.dart';
import 'package:flutter_linkid_mmp/user_info.dart';
import 'package:flutter_linkid_mmp_example/common/tracking_helper.dart';
import 'package:flutter_linkid_mmp_example/screens/chat_page.dart';
import 'package:flutter_linkid_mmp_example/screens/contact.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'common/theme.dart';
// import 'firebase_options.dart';
import 'models/cart.dart';
import 'models/catalog.dart';
import 'screens/cart.dart';
import 'screens/catalog.dart';
import 'screens/login.dart';
import 'package:window_size/window_size.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
var fcmToken = "";
void main() {
Airflex.runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}, (error, stackTrace) async {
});
}
const double windowWidth = 400;
const double windowHeight = 800;
void setupWindow() {
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
WidgetsFlutterBinding.ensureInitialized();
setWindowTitle('Provider Demo');
setWindowMinSize(const Size(windowWidth, windowHeight));
setWindowMaxSize(const Size(windowWidth, windowHeight));
getCurrentScreen().then((screen) {
setWindowFrame(Rect.fromCenter(
center: screen!.frame.center,
width: windowWidth,
height: windowHeight,
));
});
}
}
GoRouter router() {
return GoRouter(
initialLocation: '/login',
routes: [
GoRoute(
path: '/login',
builder: (context, state) => MyLogin(),
),
GoRoute(
path: '/catalog',
builder: (context, state) => MyCatalog(),
routes: [
GoRoute(
path: 'cart',
builder: (context, state) => MyCart(),
),
GoRoute(
path: 'chat',
builder: (context, state) => const ChatPage(),
),
GoRoute(
path: 'contact',
builder: (context, state) => const ContactScreen(),
),
],
),
],
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// Future<void> initFcm(BuildContext context) async {
// await FirebaseMessaging.instance.requestPermission(
// alert: true,
// announcement: false,
// badge: true,
// carPlay: false,
// criticalAlert: false,
// provisional: false,
// sound: true,
// );
// fcmToken = await FirebaseMessaging.instance.getToken() ?? "";
// print("fcmToken ${fcmToken}");
// FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// print('Got a message whilst in the foreground!');
// print('Message data: ${message.data}');
//
// if (message.notification != null) {
// print('Message also contained a notification: ${message.notification}');
// try {
// EasyLoading.instance
// ..toastPosition = EasyLoadingToastPosition.bottom
// ..displayDuration = const Duration(milliseconds: 2000)
// ..indicatorType = EasyLoadingIndicatorType.fadingCircle
// ..loadingStyle = EasyLoadingStyle.dark
// ..indicatorSize = 45.0
// ..radius = 10.0
// ..progressColor = Colors.yellow
// ..backgroundColor = Colors.green
// ..indicatorColor = Colors.yellow
// ..textColor = Colors.yellow
// ..maskColor = Colors.blue.withOpacity(0.5)
// ..userInteractions = true
// ..dismissOnTap = false;
// EasyLoading.showInfo(
// '${message.notification?.title}\n${message.notification?.body}');
// } catch (e) {
// print(e);
// }
// }
// });
// }
Future<void> init(BuildContext context) async {
Airflex.shared.setDevMode(true);
await Airflex.shared.initSDK(
partnerCode: "myvpbank_uat",
appSecret:
"7fe95468c204397de9bcda2d702d4501a174976b1d003d92d1e5550b03f9fcb5",
);
Airflex.shared.deepLinkHandler(
onReceivedDeepLink: (url) {
print('onReceivedDeepLink in dart $url');
}
);
// await initFcm(context);
Airflex().setUserInfo(UserInfo(deviceToken: fcmToken));
}
@override
Widget build(BuildContext context) {
// Using MultiProvider is convenient when providing multiple objects.
if (fcmToken == "") {
init(context);
}
print('Main init');
TrackingHelper.logEvent(event: "StartApp");
return MultiProvider(
providers: [
// In this sample app, CatalogModel never changes, so a simple Provider
// is sufficient.
Provider(create: (context) => CatalogModel()),
// CartModel is implemented as a ChangeNotifier, which calls for the use
// of ChangeNotifierProvider. Moreover, CartModel depends
// on CatalogModel, so a ProxyProvider is needed.
ChangeNotifierProxyProvider<CatalogModel, CartModel>(
create: (context) => CartModel(),
update: (context, catalog, cart) {
if (cart == null) throw ArgumentError.notNull('cart');
cart.catalog = catalog;
return cart;
},
),
],
child: MaterialApp.router(
title: 'Provider Demo',
theme: appTheme,
routerConfig: router(),
builder: EasyLoading.init(),
),
);
}
}