flutter_genuin_qa 1.0.1
flutter_genuin_qa: ^1.0.1 copied to clipboard
Genuin QA SDK comprises features such as brand feed, communities, and groups.
example/lib/main.dart
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_genuin_qa/genuin_carousel_embed_view.dart';
import 'package:flutter_genuin_qa/genuin_feed_embed_view.dart';
import 'package:flutter_genuin_qa/genuin_standard_wall_view.dart';
import 'package:flutter_genuin_qa/flutter_genuin_qa.dart';
import 'package:flutter_genuin_qa_example/firebase_options.dart';
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
if (kDebugMode) {
print("Handling a background message: ${message.messageId}");
print('Message data: ${message.data}');
print('Message notification: ${message.notification?.title}');
print('Message notification: ${message.notification?.body}');
}
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
name: 'sml-demo-41620',
options: DefaultFirebaseOptions.currentPlatform,
);
final messaging = FirebaseMessaging.instance;
final helloTestPlugin = HelloTest();
final settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
String? token = await messaging.getToken();
if (token != null) {
await helloTestPlugin.registerFCMToken(token);
}
}
// Check for initial notification that opened the app
RemoteMessage? initialMessage =
await FirebaseMessaging.instance.getInitialMessage();
if (initialMessage != null) {
// Handle navigation or actions
final notificationData = {
'title': initialMessage.notification?.title,
'body': initialMessage.notification?.body,
'data': initialMessage.data,
};
var willHandleNotification = await helloTestPlugin
.willHandleBackgroundNotifications(notificationData);
if (willHandleNotification == true) {
helloTestPlugin.handleBackgroundNotifications(notificationData);
} else {
// Your notification handling
}
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
if (kDebugMode) {
print('Handling a foreground message: ${message.messageId}');
print('Message data: ${message.data}');
print('Message notification: ${message.notification?.title}');
print('Message notification: ${message.notification?.body}');
}
final notificationData = {
'title': message.notification?.title,
'body': message.notification?.body,
'data': message.data,
'icon': 'mipmap/ic_notification'
// OR 'icon':'drawable/ic_notification'[if image put under drawable folder]
};
var willHandleNotification = await helloTestPlugin
.willHandleForegroundNotifications(notificationData);
if (willHandleNotification == true) {
helloTestPlugin.handleForegroundNotifications(notificationData);
} else {
// Your notification handling
}
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
// Navigate to a specific screen
final notificationData = {
'title': message.notification?.title,
'body': message.notification?.body,
'data': message.data,
};
var willHandleNotification = await helloTestPlugin
.willHandleBackgroundNotifications(notificationData);
if (willHandleNotification == true) {
helloTestPlugin.handleBackgroundNotifications(notificationData);
} else {
// Your notification handling
}
});
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
);
}
}
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {
final _genuinSdkPlugin = HelloTest();
@override
void initState() {
super.initState();
}
int _selectedIndex = 0;
bool _standardWallLoaded = false;
bool _feedLoaded = false;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
// Load data only when switching to that tab for the first time
if (index == 1 && !_standardWallLoaded) {
_standardWallLoaded = true;
} else if (index == 2 && !_feedLoaded) {
_feedLoaded = true;
}
final carouselConfig = {
'embedId': "6669791ba927da9734f4ad9d",
'uniqueId': "111"
};
final standardWallConfig = {
'embedId': "6669791ba927da9734f4ad99",
'uniqueId': "112"
};
final feedConfig = {
'embedId': "6745b75a3d2ce5a7e4e1a73a",
'uniqueId': "113"
};
if (_selectedIndex == 0) {
_genuinSdkPlugin.resumeCarousel(carouselConfig);
} else {
_genuinSdkPlugin.pauseCarousel(carouselConfig);
}
if (_selectedIndex == 1) {
_genuinSdkPlugin.resumeStandWall(standardWallConfig);
} else {
_genuinSdkPlugin.pauseStandWall(standardWallConfig);
}
if (_selectedIndex == 2) {
_genuinSdkPlugin.resumeFeed(feedConfig);
} else {
_genuinSdkPlugin.pauseFeed(feedConfig);
}
});
}
@override
Widget build(BuildContext context) {
final List<Widget> screens = [
Center(
child: SizedBox(
height: 300,
width: MediaQuery.of(context).size.width,
child: const Carousel(
embedId: "6669791ba927da9734f4ad9d",
uniqueId: "111",
isShowProfileEnabled: false,
isDirectDeepLinkEnabled: false,
),
),
),
_standardWallLoaded
? SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: const StandardWall(
embedId: "6669791ba927da9734f4ad99",
uniqueId: "112",
isShowProfileEnabled: true,
isDirectDeepLinkEnabled: false,
),
)
: const Center(
child: Text("Loading..."),
),
_feedLoaded
? SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: const Feed(
embedId: "6745b75a3d2ce5a7e4e1a73a",
uniqueId: "113",
isShowProfileEnabled: false,
isDirectDeepLinkEnabled: false,
),
)
: const Center(
child: Text("Loading..."),
),
];
return Scaffold(
resizeToAvoidBottomInset: false,
body: Platform.isAndroid ? SafeArea(child: _buildBody(screens)) : _buildBody(screens),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
onTap: _onItemTapped,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.view_carousel), label: 'Carousel'),
BottomNavigationBarItem(
icon: Icon(Icons.wallet), label: 'StandardWall'),
BottomNavigationBarItem(icon: Icon(Icons.feed), label: 'Feed'),
],
),
);
}
Widget _buildBody(List<Widget> screens){
return IndexedStack(
index: _selectedIndex,
children: screens,
);
}
}