This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:firebase_database/firebase_database.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import '../utilities/constants.dart'; | |
import '../widgets/order_map.dart'; | |
class HomeScreen extends StatefulWidget { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cloud_firestore/cloud_firestore.dart'; | |
class MockFirestore extends Mock implements FirebaseFirestore {} | |
class MockCollectionReference extends Mock implements CollectionReference {} | |
class MockDocumentReference extends Mock implements DocumentReference {} | |
class MockDocumentSnapshot extends Mock implements DocumentSnapshot {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cloud_firestore/cloud_firestore.dart'; | |
class MockFirestore extends Mock implements FirebaseFirestore {} | |
class MockCollectionReference extends Mock implements CollectionReference {} | |
class MockDocumentReference extends Mock implements DocumentReference {} | |
class MockDocumentSnapshot extends Mock implements DocumentSnapshot {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cloud_firestore/cloud_firestore.dart'; | |
class MockFirestore extends Mock implements FirebaseFirestore {} | |
class MockCollectionReference extends Mock implements CollectionReference {} | |
class MockDocumentReference extends Mock implements DocumentReference {} | |
class MockDocumentSnapshot extends Mock implements DocumentSnapshot {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies: | |
flutter: | |
sdk: flutter | |
flutter_localizations: | |
sdk: flutter | |
cupertino_icons: ^0.1.3 | |
#caching | |
hive: ^1.4.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
await Hive.initFlutter(); | |
runApp(MyApp()); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> saveEventToHive() async { | |
try { | |
var box = Hive.openBox('first_box'); | |
box.put('event', 'Cache User'); | |
var event = box.get('event') | |
box.close(); | |
} on Exception catch (e) { | |
throw CacheException(message: e.toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> saveUserToken(String token) async { | |
try { | |
//BOX_NAME is any string key for you box name. | |
final secureKey = Hive.generateSecureKey(); | |
final encryptedBox = await Hive.openBox(BOX_NAME, encryptionKey: secureKey); | |
await encryptedBox.put('token', token); | |
//SECURE_STORAGE_KEY is any string key. | |
await secureStorage.write( | |
key: SECURE_STORAGE_KEY, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<String> retrieveUserToken() async { | |
try { | |
final secureKey = await secureStorage.read(key: SECURE_STORAGE_KEY); | |
List<int> encryptionKey = (json.decode(secureKey) as List<dynamic>).cast<int>(); | |
final encryptedBox = await hive.openBox(BOX_NAME, encryptionKey: encryptionKey); | |
String token = encryptedBox.get('token'); | |
encryptedBox.close(); | |
return token; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CacheUserModel { | |
final String email; | |
final String name; | |
final String phone; | |
final String role; |
OlderNewer