Skip to content

Commit

Permalink
Added signup with location, category. Added Firebase Analytics. Impro…
Browse files Browse the repository at this point in the history
…ved navigations
  • Loading branch information
piyushchauhan committed Jun 7, 2020
1 parent 4e506d7 commit 9591a93
Show file tree
Hide file tree
Showing 28 changed files with 536 additions and 129 deletions.
3 changes: 2 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ android {
flutter {
source '../..'
}

apply plugin: 'com.google.gms.google-services'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
40 changes: 40 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"project_info": {
"project_number": "529765195046",
"firebase_url": "https://q-me-firebase.firebaseio.com",
"project_id": "q-me-firebase",
"storage_bucket": "q-me-firebase.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:529765195046:android:6f13c69c165d5e7fa5f5e7",
"android_client_info": {
"package_name": "com.vaapso.qme_subscriber"
}
},
"oauth_client": [
{
"client_id": "529765195046-poqfs5rquifvfgse571ckescge4umbtc.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBTFxT93BVHqwLcEbuuYbLkx7L9Dd3HZSA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "529765195046-poqfs5rquifvfgse571ckescge4umbtc.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCIwJoNY1gMHq-qITR81zDv_z--z9xlOlo"/>
</application>
</manifest>
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
}
}

Expand Down
4 changes: 4 additions & 0 deletions android/key.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
storePassword=QMeSubscriber
keyPassword=QMeSubscriber
keyAlias=key
storeFile=/media/pi/Pi/Code/android/q_me/subscriber/key.jks
6 changes: 4 additions & 2 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("AIzaSyCIwJoNY1gMHq-qITR81zDv_z--z9xlOlo")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
}
8 changes: 8 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,13 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>
<key>io.flutter.embedded_views_preview</key>
<true/>
</dict>
</plist>
2 changes: 2 additions & 0 deletions lib/api/keys.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const String mapsApiKey = 'AIzaSyCIwJoNY1gMHq-qITR81zDv_z--z9xlOlo';
const String mapsApiKey2 = 'AIzaSyDYQDjIO0E-tHnSFHDEmaYb_wzWEWiDqEc';
18 changes: 10 additions & 8 deletions lib/bloc/poeple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'dart:developer';
class PeopleBloc extends ChangeNotifier {
UserRepository _peopleRepository;

String queueId, status, _accessToken;
String queueId, tokenStatus, _accessToken;
List<User> peopleList;
User person;

Expand All @@ -26,8 +26,8 @@ class PeopleBloc extends ChangeNotifier {
_peopleListController.stream;
Stream<ApiResponse<User>> get personStream => _personController.stream;

PeopleBloc({@required this.queueId, @required this.status}) {
log('PeopleBloc initializes with queueId:$queueId and status:$status');
PeopleBloc({@required this.queueId, @required this.tokenStatus}) {
log('PeopleBloc initializes with queueId:$queueId and status:$tokenStatus');
_peopleListController = StreamController<ApiResponse<List<User>>>();
_personController = StreamController<ApiResponse<User>>();

Expand All @@ -36,18 +36,20 @@ class PeopleBloc extends ChangeNotifier {
}

fetchPeopleList({String status}) async {
this.status = status != null ? status : this.status;
this.tokenStatus = status != null ? status : this.tokenStatus;
peopleListSink.add(ApiResponse.loading('Fetching people\'s list'));
personSink.add(ApiResponse.loading('Loading persons\'s details'));
try {
log('Fetching users data for queue:$queueId and status:${this.status}');
log('Fetching users data for queue:$queueId and status:${this.tokenStatus}');
_accessToken = _accessToken == null
? await SubscriberRepository().getAccessTokenFromStorage()
: _accessToken;

// call api repository with the status
final response = await _peopleRepository.getQueueUser(
queueId: queueId, status: this.status, accessToken: _accessToken);
queueId: queueId,
status: this.tokenStatus,
accessToken: _accessToken);
log('People Repository API response:' + response.toString());
peopleList = Users.fromJson(response).user;

Expand Down Expand Up @@ -83,7 +85,7 @@ class PeopleBloc extends ChangeNotifier {
}

// fetch new people list
fetchPeopleList(status: status);
fetchPeopleList(status: tokenStatus);
}

nextToken() async {
Expand All @@ -102,7 +104,7 @@ class PeopleBloc extends ChangeNotifier {
}

// fetch new people list
fetchPeopleList(status: status);
fetchPeopleList(status: tokenStatus);
}

addPersonDetails(User user) {
Expand Down
3 changes: 3 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ final kDropdownList = kQueueStatusList
child: Text(value),
))
.toList();

final kLabelStyle = TextStyle(
fontFamily: 'Montserrat', fontWeight: FontWeight.bold, color: Colors.grey);
34 changes: 6 additions & 28 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
import 'package:flutter/material.dart';
import 'views/people.dart';
import 'views/viewQueue.dart';
import 'views/signup.dart';
import 'package:qme_subscriber/services/analytics.dart';
import 'views/signin.dart';
import 'views/profile.dart';
import 'views/queues.dart';
import 'views/createQueue.dart';
import 'repository/subscriber.dart';
import 'router.dart' as router;

var analytics = AnalyticsService();
String initialHome = SignInScreen.id;
void main() async {
// Get result of the login function.
// bool _result = await appAuth.login();
WidgetsFlutterBinding.ensureInitialized();
// SubscriberRepository subscriberRepo = SubscriberRepository();
//
// if (await subscriberRepo.isTokenExpired()) {
// if (await subscriberRepo.isRefreshTokenSet()) {
// // Get new accessToken
// final newAccessToken = await subscriberRepo.getAccessToken();
// if (newAccessToken != '-1') {
// initialHome = QueuesPage.id;
// }
// }
// }

if (await SubscriberRepository().isSessionReady()) {
initialHome = QueuesPage.id;
initialHome = QueuesScreen.id;
}

runApp(MyApp());
Expand All @@ -38,16 +23,9 @@ class MyApp extends StatelessWidget {
return MaterialApp(
theme: ThemeData.light().copyWith(primaryColor: Colors.green),
debugShowCheckedModeBanner: false,
routes: <String, WidgetBuilder>{
SignUpScreen.id: (BuildContext context) => SignUpScreen(),
SignInScreen.id: (BuildContext context) => SignInScreen(),
ProfileScreen.id: (BuildContext context) => ProfileScreen(),
QueuesPage.id: (BuildContext context) => QueuesPage(),
CreateQueueScreen.id: (BuildContext context) => CreateQueueScreen(),
ViewQueueScreen.id: (BuildContext context) => ViewQueueScreen(),
PeopleScreen.id: (BuildContext context) => PeopleScreen(),
},
onGenerateRoute: router.generateRoute,
initialRoute: initialHome,
navigatorObservers: [analytics.getAnalyticsObserver()],
);
}
}
31 changes: 25 additions & 6 deletions lib/model/subscriber.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// To parse this JSON data, do
//
// final subscriber = subscriberFromJson(jsonString);

import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:developer';

Subscriber subscriberFromJson(String str) =>
Subscriber.fromJson(json.decode(str));
Expand All @@ -20,6 +14,11 @@ class Subscriber {
String accessToken;
String refreshToken;
String address;
String category;
double latitude;
double longitude;
int verified;
DateTime tokenExpiry;

Subscriber({
this.id,
Expand All @@ -30,6 +29,11 @@ class Subscriber {
this.accessToken,
this.refreshToken,
this.address,
this.latitude,
this.longitude,
this.verified,
this.tokenExpiry,
this.category,
});

factory Subscriber.fromJson(Map<String, dynamic> json) => Subscriber(
Expand All @@ -39,16 +43,31 @@ class Subscriber {
email: json["email"],
phone: json["phone"],
address: json["address"],
latitude:
json["latitude"] != null ? double.parse(json["latitude"]) : null,
longitude:
json["longitude"] != null ? double.parse(json["longitude"]) : null,
verified: json["verified"] == 'true' ? 1 : 0,
category: json["category"],
accessToken: json['accessToken'],
tokenExpiry: json["tokenExpiry"] != null
? DateTime.parse(json["tokenExpiry"])
: null,
refreshToken: json['refreshToken'],
);

Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"owner": owner,
"email": email,
"phone": phone,
"address": address,
"latitude": latitude,
"longitude": longitude,
"verified": verified == 1 ? true : false,
"category": category,
"tokenExpiry": tokenExpiry.toString(),
"accessToken": accessToken,
"refreshToken": refreshToken,
};
Expand Down
8 changes: 4 additions & 4 deletions lib/model/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class User {
String userId;
String firstName;
String lastName;
String email;
// String email;
String phone;
int tokenNo;

User({
this.userId,
@required this.firstName,
this.lastName,
this.email,
// this.email,
this.phone,
this.tokenNo,
});
Expand All @@ -49,7 +49,7 @@ class User {
userId: json["user_id"],
firstName: splitName[0],
lastName: splitName.length > 1 ? splitName[1] : null,
email: json["email"],
// email: json["email"],
phone: json["phone"],
tokenNo: json["token_no"],
);
Expand All @@ -58,7 +58,7 @@ class User {
Map<String, dynamic> toJson() => {
"user_id": userId,
"name": firstName,
"email": email,
// "email": email,
"phone": phone,
"token_no": tokenNo,
};
Expand Down
51 changes: 51 additions & 0 deletions lib/repository/database.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'dart:async';

import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import '../model/subscriber.dart';

Future<void> addProfile(Subscriber subscriber, Database db) async {
await db.insert(
'profile',
subscriber.toJson(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
}

Future<void> initDB(Subscriber subscriber) async {
final Future<Database> database = openDatabase(
join(await getDatabasesPath(), 'subscriber.db'),
onCreate: (db, version) {
return db.execute('DROP TABLE IF EXISTS profile;'
'CREATE TABLE profile('
'id TEXT PRIMARY KEY, '
'name TEXT, '
'owner TEXT,'
'email TEXT, '
'phone TEXT, '
'address TEXT, '
'latitude REAL, '
'longitude REAL, '
'verified INTEGER, '
'category TEXT, '
'expiry TEXT'
'refreshToken TEXT)');
},
version: 1,
);
await addProfile(subscriber, await database);
}

Future<Subscriber> getProfileFromDB() async {
final Database database =
await openDatabase(join(await getDatabasesPath(), 'subscriber.db'));
final List<Map<String, dynamic>> maps = await database.query('profile');
return Subscriber.fromJson(maps[0]);
}

Future<void> updateProfile(Subscriber subscriber) async {
final Database db =
await openDatabase(join(await getDatabasesPath(), 'subscriber.db'));
await db.update('profile', subscriber.toJson(),
where: "id = ?", whereArgs: [subscriber.id]);
}
Loading

1 comment on commit 9591a93

@piyushchauhan
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixes #6

Please sign in to comment.