Fakultas Ilmu Komputer UI

Commit d31b0f09 authored by Muhammad Ariq Basyar's avatar Muhammad Ariq Basyar
Browse files

Merge branch 'dev-yoga-3' into 'PBI-13-notifikasi'

Done PBI-13-notifikasi

See merge request !47
parents 1117de4f f7061b7b
Pipeline #80339 passed with stages
in 13 minutes and 44 seconds
import 'package:bisaGo/get_it.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:bisaGo/app.dart';
import 'package:intl/date_symbol_data_local.dart';
......@@ -6,14 +7,24 @@ import 'package:intl/intl.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'flavor/flavor.dart';
import 'globalnetwork.dart';
import 'package:bisaGo/get_it.dart';
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
await Firebase.initializeApp();
print('Handling a background message: ${message.messageId}');
}
Future main() async {
AppGetIt().initialize();
await DotEnv().load('.env');
getDioInstance('build');
await initializeDateFormatting('id_ID', null);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
Intl.defaultLocale = 'id_ID';
dio.options.receiveTimeout = 15000;
ApiFlavor.flavor = BuildFlavor.production.toString();
ApiFlavor.flavor = BuildFlavor.development.toString();
runApp(BisaGo());
}
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:bisaGo/app.dart';
import 'package:intl/date_symbol_data_local.dart';
......@@ -7,13 +9,22 @@ import 'flavor/flavor.dart';
import 'globalnetwork.dart';
import 'package:bisaGo/get_it.dart';
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
await Firebase.initializeApp();
print('Handling a background message: ${message.messageId}');
}
Future main() async {
AppGetIt().initialize();
await DotEnv().load('.env');
getDioInstance('build');
await initializeDateFormatting('id_ID', null);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
Intl.defaultLocale = 'id_ID';
dio.options.receiveTimeout = 15000;
ApiFlavor.flavor = BuildFlavor.staging.toString();
ApiFlavor.flavor = BuildFlavor.development.toString();
runApp(BisaGo());
}
\ No newline at end of file
}
import 'dart:async';
import 'dart:convert';
import 'package:bisaGo/bloc/cloud_messaging_bloc.dart';
import 'package:bisaGo/bloc/new_user_bloc.dart';
import 'package:bisaGo/bloc/user_bloc.dart';
import 'package:bisaGo/model/new_user.dart';
import 'package:bisaGo/page/dashboard/dashboard.dart';
import 'package:bisaGo/page/login/pilih_disabilitas.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
......@@ -35,6 +38,10 @@ class LoginState extends State<Login> {
GoogleSignInAccount _currentUser;
SharedPreferences sharedPreferences;
FirebaseMessaging _firebaseMessaging;
CloudMessagingBloc cloudMessagingBloc = CloudMessagingBloc();
@override
void initState() {
super.initState();
......@@ -159,12 +166,12 @@ class LoginState extends State<Login> {
height: 64.0,
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
side: const BorderSide(color: greenPrimary)),
padding: const EdgeInsets.symmetric(vertical: 10.0)
),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
side: const BorderSide(color: greenPrimary)),
padding:
const EdgeInsets.symmetric(vertical: 10.0)),
onPressed: () async {
Navigator.of(context).pop(true);
await _updateUser(newUser);
......@@ -189,11 +196,11 @@ class LoginState extends State<Login> {
height: 64.0,
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: greenPrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
padding: const EdgeInsets.symmetric(vertical: 10.0)
),
backgroundColor: greenPrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0)),
padding:
const EdgeInsets.symmetric(vertical: 10.0)),
onPressed: () {
Navigator.of(context).pop(true);
_navigateToPilihDisabilitas(context);
......@@ -286,12 +293,15 @@ class LoginState extends State<Login> {
final response = await http
.post('${ApiFlavor.getBaseUrl()}/api-token-auth/', body: data);
if (response.statusCode == 200) {
print('here');
final tokenMap = jsonDecode(response.body);
setState(() {
sharedPreferences
..setString('token', tokenMap['token'])
..setString('email', email);
});
await _requestFCMToken();
successDialog(context);
_navigateToDashboard(context);
} else {
......@@ -372,6 +382,7 @@ class LoginState extends State<Login> {
await googleSignInAccount.authentication;
final token = googleSignInAuthentication.accessToken;
print(token);
await login(
_currentUser.email, '', 'true', token, _currentUser.displayName);
sharedPreferences = await SharedPreferences.getInstance();
......@@ -384,6 +395,19 @@ class LoginState extends State<Login> {
}
}
Future<void> _requestFCMToken() async {
await Firebase.initializeApp();
_firebaseMessaging = FirebaseMessaging.instance;
final fcmToken = await _firebaseMessaging.getToken();
final sharedPreferences = await SharedPreferences.getInstance();
final token = sharedPreferences.getString('token');
if (token != null) {
await cloudMessagingBloc.sendFCMToken(fcmToken, token);
}
}
Future<void> _handleSignOut() async {
await _googleSignIn.signOut();
}
......
......@@ -9,13 +9,14 @@ abstract class BaseUserRepository {
Future<Response> createUser(NewUser newUser);
Future<Response> updateUser(NewUser newUser);
}
class UserRepository implements BaseUserRepository {
final NetworkInterface _network = NetworkInterface();
@override
Future<User> fetchUserDetail(String email) async {
final response =
await _network.get(url: '/api/user-detail/$email', isLogin: true);
await _network.get(url: '/api/user/$email/', isLogin: true);
final data = [response];
return User(
data.map<UserModel>((user) => UserModel.fromJson(user)).toList());
......
import 'dart:io';
import 'package:bisaGo/model/user.dart';
import 'package:bisaGo/repository/cloud_messaging_repository.dart';
import 'package:bisaGo/repository/user_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -13,6 +14,14 @@ import 'package:shared_preferences/shared_preferences.dart';
class MockNetwork extends Mock implements NetworkInterface {}
class MockCloudMessagingRepository extends Fake
implements CloudMessagingRepository {
@override
Future<bool> sendFCMToken(String fcmToken, String token) async {
return Future.value(true);
}
}
class MockUserRepository extends Fake implements UserRepository {
final userData = {
'is_login': true,
......@@ -41,6 +50,9 @@ void main() {
.registerLazySingleton<BaseUserRepository>(() => MockUserRepository());
SharedPreferences.setMockInitialValues(
{'email': 'test@gmail.com', 'token': 'token'});
_getIt.registerLazySingleton<BaseCloudMessagingRepository>(
() => MockCloudMessagingRepository());
// mockNetwork = MockNetwork();
// when(mockNetwork.get(isLogin: false, url: anyNamed('url')))
// .thenAnswer((_) async {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment