Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 42 #229

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions android/app/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
Copy link
Owner

@himanshusharma89 himanshusharma89 May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add the auto-generated files in the PR.

# 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
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name=".Application"
Copy link
Owner

@himanshusharma89 himanshusharma89 May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Flutter version is already greater than 1.12, so no need to integrate FCM in such a way, revert back to io.Flutter.app.FlutterApplcation

android:label="retro_shopping"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the below android:label to Relic Bazaar

android:icon="@mipmap/ic_launcher">
<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tech.himanshusharma.relicbazaar
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Flutter version is already greater than 1.12, so no need to integrate FCM in such a way.

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.view.FlutterMain
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService;

class Application : FlutterApplication(), PluginRegistrantCallback {

override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingBackgroundService.setPluginRegistrant(this);
FlutterMain.startInitialization(this)
}

override fun registerWith(registry: PluginRegistry?) {
}
}
74 changes: 73 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:provider/provider.dart';
Expand All @@ -9,15 +13,33 @@ import 'package:relic_bazaar/helpers/ad_state.dart';
import 'package:relic_bazaar/helpers/constants.dart';
import 'package:relic_bazaar/helpers/route_page.dart';
import 'package:relic_bazaar/views/auth/login_view.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

import 'services/remote_config.dart';

RemoteConfigService _remoteConfigService;


Future<void> _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<void> main() async {
//firebase Initialization
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

//AdMob Initialization
final Future<InitializationStatus> initFuture =
MobileAds.instance.initialize();
Expand All @@ -27,6 +49,11 @@ Future<void> main() async {
//Initialize remote config
_remoteConfigService = await RemoteConfigService.getInstance();
await _remoteConfigService.initialize();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);

runApp(
Provider<AdState>.value(
Expand All @@ -36,7 +63,45 @@ Future<void> main() async {
);
}

class MyApp extends StatelessWidget {
class MyApp extends StatefulWidget {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't convert the MyApp to stateful, shift the token generation and initialization of push notification in dashboard.dart

@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

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(
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions lib/services/product_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import 'package:relic_bazaar/model/product_model.dart';
class ProductService {
Future<List<Product>> 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<dynamic> fetchedData =
json.decode(response.body) as List<dynamic>;
json.decode(response.body) as List<dynamic>;
return fetchedData
.map(
(dynamic productData) => Product.fromJson(productData),
)
)
.toList();
}
}
6 changes: 3 additions & 3 deletions lib/services/remote_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class RemoteConfigService {
try {
await _remoteConfig.setDefaults(defaults);
await _fetchAndActivate();
} on FetchThrottledException catch (e) {
} on Exception catch (e) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert back to FetchThrottledException, as every other exception will be caught by the cath block below.

debugPrint('Remote config fetch throttled : $e');
} catch (e) {
debugPrint('Unable to fecth');
}
}

Future<void> _fetchAndActivate() async {
await _remoteConfig.fetch(expiration: const Duration(hours: 4));
await _remoteConfig.activateFetched();
await _remoteConfig.fetch();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use _remoteConfig.fetchAndActivate(), instead of 2 different command.

await _remoteConfig.activate();
}
}
122 changes: 80 additions & 42 deletions lib/views/profile/settings/faqs_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
import 'package:flutter/material.dart';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have done a lot of changes in this file, attach a video of this new view in the comments

import 'package:native_pdf_view/native_pdf_view.dart';
import 'package:relic_bazaar/helpers/constants.dart';
import 'package:relic_bazaar/widgets/back_button.dart';

Expand All @@ -9,55 +9,93 @@ class FaqsScreen extends StatefulWidget {
}

class _FaqsScreenState extends State<FaqsScreen> {
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<void> loadDocument() async {
_doc = await PDFDocument.fromAsset('assets/FAQ.pdf');

setState(() => _loading = false);
}

Future<void> 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: <Widget>[
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;
});
},
),
),
);
}
15 changes: 9 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use pre-release versions.

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
Copy link
Owner

@himanshusharma89 himanshusharma89 May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http_parser is not being used anywhere, so remove it.

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:
Expand Down