diff --git a/android/app/local.properties b/android/app/local.properties new file mode 100644 index 0000000..9bdf3cb --- /dev/null +++ b/android/app/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Fri May 07 10:39:41 IST 2021 +sdk.dir=C\:\\Users\\HP\\AppData\\Local\\Android\\Sdk diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 7387ee0..ea1b259 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> _firebaseMessagingBackgroundHandler(RemoteMessage message) async { + await Firebase.initializeApp(); + print('Handling a background message ${message.messageId}'); +} + +const AndroidNotificationChannel channel = AndroidNotificationChannel( + 'high_importance_channel', // id + 'High Importance Notifications', // title + 'This channel is used for important notifications.', // description + importance: Importance.high, +); + +final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = +FlutterLocalNotificationsPlugin(); + Future main() async { //firebase Initialization WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); + //AdMob Initialization final Future initFuture = MobileAds.instance.initialize(); @@ -27,6 +49,11 @@ Future main() async { //Initialize remote config _remoteConfigService = await RemoteConfigService.getInstance(); await _remoteConfigService.initialize(); + FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.createNotificationChannel(channel); runApp( Provider.value( @@ -36,7 +63,45 @@ Future main() async { ); } -class MyApp extends StatelessWidget { +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + + String token; + + @override + void initState() { + super.initState(); + var initialzationSettingsAndroid = + AndroidInitializationSettings('@mipmap/ic_launcher'); + var initializationSettings = + InitializationSettings(android: initialzationSettingsAndroid); + + flutterLocalNotificationsPlugin.initialize(initializationSettings); + + FirebaseMessaging.onMessage.listen((RemoteMessage message) { + RemoteNotification notification = message.notification; + AndroidNotification android = message.notification?.android; + if (notification != null && android != null) { + flutterLocalNotificationsPlugin.show( + notification.hashCode, + notification.title, + notification.body, + NotificationDetails( + android: AndroidNotificationDetails( + channel.id, + channel.name, + channel.description, + icon: android?.smallIcon, + ), + )); + } + }); + getToken(); + } @override Widget build(BuildContext context) { return GestureDetector( @@ -84,6 +149,13 @@ class MyApp extends StatelessWidget { onGenerateRoute: RoutePage.generateRoute, )); } + getToken() async { + token = await FirebaseMessaging.instance.getToken(); + setState(() { + token = token; + }); + print(token); + } } class CustomScrollBehavior extends ScrollBehavior { diff --git a/lib/services/product_service.dart b/lib/services/product_service.dart index 3a2eb41..718d357 100644 --- a/lib/services/product_service.dart +++ b/lib/services/product_service.dart @@ -5,14 +5,14 @@ import 'package:relic_bazaar/model/product_model.dart'; class ProductService { Future> getProducts() async { final http.Response response = await http.get( - 'https://himanshusharma89-api.herokuapp.com/api/relic_bazaar/products', + Uri.parse('https://himanshusharma89-api.herokuapp.com/api/relic_bazaar/products'), ); final List fetchedData = - json.decode(response.body) as List; + json.decode(response.body) as List; return fetchedData .map( (dynamic productData) => Product.fromJson(productData), - ) + ) .toList(); } } diff --git a/lib/services/remote_config.dart b/lib/services/remote_config.dart index 715f2ad..ea18d13 100644 --- a/lib/services/remote_config.dart +++ b/lib/services/remote_config.dart @@ -33,7 +33,7 @@ class RemoteConfigService { try { await _remoteConfig.setDefaults(defaults); await _fetchAndActivate(); - } on FetchThrottledException catch (e) { + } on Exception catch (e) { debugPrint('Remote config fetch throttled : $e'); } catch (e) { debugPrint('Unable to fecth'); @@ -41,7 +41,7 @@ class RemoteConfigService { } Future _fetchAndActivate() async { - await _remoteConfig.fetch(expiration: const Duration(hours: 4)); - await _remoteConfig.activateFetched(); + await _remoteConfig.fetch(); + await _remoteConfig.activate(); } } diff --git a/lib/views/profile/settings/faqs_screen.dart b/lib/views/profile/settings/faqs_screen.dart index af6d292..e3c89fa 100644 --- a/lib/views/profile/settings/faqs_screen.dart +++ b/lib/views/profile/settings/faqs_screen.dart @@ -1,5 +1,5 @@ -import 'package:advance_pdf_viewer/advance_pdf_viewer.dart'; import 'package:flutter/material.dart'; +import 'package:native_pdf_view/native_pdf_view.dart'; import 'package:relic_bazaar/helpers/constants.dart'; import 'package:relic_bazaar/widgets/back_button.dart'; @@ -9,55 +9,93 @@ class FaqsScreen extends StatefulWidget { } class _FaqsScreenState extends State { - bool _loading = true; - PDFDocument _doc; + static final int _initialPage = 1; + int _actualPageNumber = _initialPage, _allPagesCount = 0; + bool isSampleDoc = true; + PdfController _pdfController; @override void initState() { - // TODO: implement initState + _pdfController = PdfController( + document: PdfDocument.openAsset('assets/FAQ.pdf'), + initialPage: _initialPage, + ); super.initState(); - loadDocument(); - } - - Future loadDocument() async { - _doc = await PDFDocument.fromAsset('assets/FAQ.pdf'); - - setState(() => _loading = false); } - Future changePDF(int value) async { - setState(() => _loading = true); - if (value == 1) { - _doc = await PDFDocument.fromAsset('assets/FAQ.pdf'); - } else if (value == 2) { - _doc = await PDFDocument.fromURL( - 'http://conorlastowka.com/book/CitationNeededBook-Sample.pdf', - ); - } else { - _doc = await PDFDocument.fromAsset('assets/FAQ.pdf'); - } - setState(() => _loading = false); + @override + void dispose() { + _pdfController.dispose(); + super.dispose(); } @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: RelicColors.backgroundColor, - leading: appBarBackButton(context), - title: const Text('FAQs'), - centerTitle: true, - elevation: 0.0, - ), - body: Center( - child: _loading - ? const Center(child: CircularProgressIndicator()) - : PDFViewer( - document: _doc, - zoomSteps: 1, - scrollDirection: Axis.vertical, + Widget build(BuildContext context) => MaterialApp( + debugShowCheckedModeBanner: false, + theme: ThemeData(primaryColor: Colors.white), + home: Scaffold( + appBar: AppBar( + backgroundColor: RelicColors.backgroundColor, + leading: appBarBackButton(context), + title: const Text('FAQs'), + centerTitle: true, + elevation: 0.0, + actions: [ + IconButton( + icon: Icon(Icons.navigate_before), + onPressed: () { + _pdfController.previousPage( + curve: Curves.ease, + duration: Duration(milliseconds: 100), + ); + }, ), - ), - ); - } + Container( + alignment: Alignment.center, + child: Text( + '$_actualPageNumber/$_allPagesCount', + style: TextStyle(fontSize: 22), + ), + ), + IconButton( + icon: Icon(Icons.navigate_next), + onPressed: () { + _pdfController.nextPage( + curve: Curves.ease, + duration: Duration(milliseconds: 100), + ); + }, + ), + IconButton( + icon: Icon(Icons.refresh), + onPressed: () { + if (isSampleDoc) { + _pdfController.loadDocument( + PdfDocument.openAsset('assets/dummy.pdf')); + } else { + _pdfController.loadDocument( + PdfDocument.openAsset('assets/sample.pdf')); + } + isSampleDoc = !isSampleDoc; + }, + ) + ], + ), + body: PdfView( + documentLoader: Center(child: CircularProgressIndicator()), + pageLoader: Center(child: CircularProgressIndicator()), + controller: _pdfController, + onDocumentLoaded: (document) { + setState(() { + _allPagesCount = document.pagesCount; + }); + }, + onPageChanged: (page) { + setState(() { + _actualPageNumber = page; + }); + }, + ), + ), + ); } diff --git a/pubspec.yaml b/pubspec.yaml index 42f803a..9cb46b4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,22 +26,25 @@ dependencies: fluttertoast: ^7.1.8 flutter_html: ^1.3.0 - firebase_remote_config: ^0.6.0 - firebase_core: any - google_fonts: ^1.1.0 + firebase_remote_config: ^0.10.0-dev.2 + google_fonts: ^2.0.0 razorpay_flutter: 1.1.0 google_mobile_ads: ^0.11.0+3 geolocator: 5.3.2+2 geocoder: 0.2.1 flutter_svg: ^0.20.0-nullsafety.3 provider: - advance_pdf_viewer: - firebase_auth: 0.20.1 + native_pdf_view: ^4.0.1 + firebase_auth: ^1.1.3 + http_parser: ^4.0.0 google_sign_in: 4.5.9 webview_flutter: ^1.0.7 - cloud_firestore: ^0.16.0+1 modal_progress_hud: ^0.1.3 carousel_slider: ^3.0.0 + firebase_messaging: ^9.1.0 + flutter_local_notifications: ^5.0.0 + cloud_firestore: ^1.0.5 + firebase_core: ^1.0.2 http: any dev_dependencies: