check null safety
This commit is contained in:
@@ -20,8 +20,8 @@ Future<dynamic> requestAPI(
|
||||
String path,
|
||||
method, {
|
||||
dynamic payload,
|
||||
String token,
|
||||
String url,
|
||||
String? token,
|
||||
String? url,
|
||||
}) async {
|
||||
DevInfo devInfo = await DevInfo.getDevInfo();
|
||||
|
||||
@@ -33,7 +33,7 @@ Future<dynamic> requestAPI(
|
||||
headers["Token"] = token;
|
||||
}
|
||||
if (devInfo != null && devInfo.deviceID != null && deviceName != null) {
|
||||
headers["Device"] = devInfo.deviceID + ":" + deviceName;
|
||||
headers["Device"] = devInfo.deviceID??"" + ":" + deviceName;
|
||||
}
|
||||
headers["Project-ID"] = Config.instance.reportProjectID;
|
||||
|
||||
@@ -66,7 +66,7 @@ Future<dynamic> requestAPI(
|
||||
// request makes http request
|
||||
// if token is null
|
||||
Future<dynamic> requestDownloadAPI(String path, method,
|
||||
{dynamic payload, String token, String url, String filePath}) async {
|
||||
{dynamic payload, String? token, String? url, String? filePath}) async {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
String deviceName = "${androidInfo.model}(${androidInfo.id})";
|
||||
@@ -81,7 +81,7 @@ Future<dynamic> requestDownloadAPI(String path, method,
|
||||
log.info("Path:$baseUrl$path");
|
||||
HttpClient client = new HttpClient();
|
||||
var _downloadData = StringBuffer();
|
||||
var fileSave = new File(filePath);
|
||||
var fileSave = new File(filePath!);
|
||||
var request = await client.getUrl(Uri.parse("$baseUrl$path"));
|
||||
request.headers.set("Project-ID", Config.instance.reportProjectID);
|
||||
request.headers
|
||||
@@ -108,7 +108,7 @@ Future<dynamic> requestDownloadAPI(String path, method,
|
||||
// request makes http request
|
||||
// if token is null
|
||||
Future<dynamic> requestDownloadPDFAPI(String path, method,
|
||||
{dynamic payload, String token, String url, String filePath}) async {
|
||||
{dynamic payload, String? token, String? url, String? filePath}) async {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
String deviceName = "${androidInfo.model}(${androidInfo.id})";
|
||||
@@ -123,7 +123,7 @@ Future<dynamic> requestDownloadPDFAPI(String path, method,
|
||||
log.info("Path:$baseUrl$path");
|
||||
HttpClient client = new HttpClient();
|
||||
// var _downloadData = StringBuffer();
|
||||
var fileSave = new File(filePath);
|
||||
var fileSave = new File(filePath!);
|
||||
var request = await client.getUrl(Uri.parse("$baseUrl$path"));
|
||||
request.headers.set("Project-ID", Config.instance.reportProjectID);
|
||||
if (token != null) {
|
||||
@@ -135,7 +135,7 @@ Future<dynamic> requestDownloadPDFAPI(String path, method,
|
||||
request.headers.set("payload", escapePayload);
|
||||
var response = await request.close();
|
||||
print("headers:${response.headers}");
|
||||
var _downloadData = List<int>();
|
||||
List<int> _downloadData = [];
|
||||
|
||||
response.listen((d) => _downloadData.addAll(d), onDone: () {
|
||||
fileSave.writeAsBytes(_downloadData);
|
||||
@@ -155,10 +155,10 @@ typedef OnDownloadDone(File file);
|
||||
// if token is null
|
||||
Future<dynamic> requestDownload(String path, method,
|
||||
{dynamic payload,
|
||||
String token,
|
||||
String url,
|
||||
String filePath,
|
||||
OnDownloadDone onDownloadDone}) async {
|
||||
required String token,
|
||||
required String url,
|
||||
required String filePath,
|
||||
OnDownloadDone? onDownloadDone}) async {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
String deviceName = "${androidInfo.model}(${androidInfo.id})";
|
||||
@@ -188,7 +188,7 @@ Future<dynamic> requestDownload(String path, method,
|
||||
// request.write(escapePayload);
|
||||
var response = await request.close();
|
||||
print("headers:${response.headers}");
|
||||
var _downloadData = List<int>();
|
||||
List<int> _downloadData = [];
|
||||
var cd = response.headers.value("content-disposition");
|
||||
String fileName = "download.csv";
|
||||
if (cd != null && cd.contains("filename=")) {
|
||||
|
||||
@@ -2,13 +2,13 @@ import 'package:device_info/device_info.dart';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
class DevInfo {
|
||||
bool isAndroid;
|
||||
bool isIOS;
|
||||
String deviceID;
|
||||
String id;
|
||||
String model;
|
||||
bool? isAndroid;
|
||||
bool? isIOS;
|
||||
String? deviceID;
|
||||
String? id;
|
||||
String? model;
|
||||
|
||||
static DevInfo _instance;
|
||||
static DevInfo? _instance;
|
||||
|
||||
static Future<DevInfo> getDevInfo() async {
|
||||
if (_instance != null) return Future.value(_instance);
|
||||
@@ -18,14 +18,14 @@ class DevInfo {
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
_instance.deviceID = androidInfo.androidId;
|
||||
_instance.id = androidInfo.id;
|
||||
_instance.model = androidInfo.model;
|
||||
_instance!.deviceID = androidInfo.androidId;
|
||||
_instance!.id = androidInfo.id;
|
||||
_instance!.model = androidInfo.model;
|
||||
} else if (Platform.isIOS) {
|
||||
IosDeviceInfo iosDeviceInfo = await deviceInfo.iosInfo;
|
||||
_instance.deviceID = iosDeviceInfo.identifierForVendor;
|
||||
_instance.id = iosDeviceInfo.utsname.release;
|
||||
_instance.model = iosDeviceInfo.model;
|
||||
_instance!.deviceID = iosDeviceInfo.identifierForVendor;
|
||||
_instance!.id = iosDeviceInfo.utsname.release;
|
||||
_instance!.model = iosDeviceInfo.model;
|
||||
}
|
||||
return Future.value(_instance);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/config.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart' as fb;
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
final log = Logger('firebaseHelper');
|
||||
|
||||
final FirebaseAuth auth = FirebaseAuth.instance;
|
||||
final fb.FirebaseAuth auth = fb.FirebaseAuth.instance;
|
||||
|
||||
Future<String> getToken() async {
|
||||
FirebaseUser firebaseUser = await auth.currentUser();
|
||||
IdTokenResult token = await firebaseUser.getIdToken();
|
||||
return token.token;
|
||||
fb.User? firebaseUser = fb.FirebaseAuth.instance.currentUser;
|
||||
String token = await firebaseUser?.getIdToken() ?? "";
|
||||
return token;
|
||||
}
|
||||
|
||||
Future<Map> getClaims({bool refreshIdToken = false}) async {
|
||||
FirebaseUser firebaseUser = await auth.currentUser();
|
||||
Future<Map?> getClaims({bool refreshIdToken = false}) async {
|
||||
fb.User? firebaseUser = auth.currentUser;
|
||||
if (firebaseUser == null) return null;
|
||||
IdTokenResult idToken =
|
||||
await firebaseUser.getIdToken(refresh: refreshIdToken);
|
||||
fb.IdTokenResult idToken =
|
||||
await firebaseUser.getIdTokenResult(refreshIdToken);
|
||||
return idToken.claims;
|
||||
}
|
||||
|
||||
// returns list of url
|
||||
Future<List<String>> uploadFiles(String path, List<File> files,
|
||||
{String fileName}) async {
|
||||
{String? fileName}) async {
|
||||
List<Future<String>> fu = [];
|
||||
for (File f in files) {
|
||||
Future<String> u = uploadStorage(path, f);
|
||||
@@ -35,22 +34,27 @@ Future<List<String>> uploadFiles(String path, List<File> files,
|
||||
return Future.wait(fu);
|
||||
}
|
||||
|
||||
Future<String> uploadStorage(String path, File file, {String fileName}) async {
|
||||
Future<String> uploadStorage(String path, File file, {String? fileName}) async {
|
||||
if (fileName == null) {
|
||||
fileName = Uuid().v4();
|
||||
}
|
||||
StorageReference storageReference =
|
||||
FirebaseStorage(storageBucket: Config.instance.bucketName)
|
||||
.ref()
|
||||
.child('$path/$fileName');
|
||||
StorageUploadTask uploadTask = storageReference.putFile(file);
|
||||
await uploadTask.onComplete;
|
||||
String downloadUrl = await storageReference.getDownloadURL();
|
||||
print("name:${await storageReference.getName()}");
|
||||
print("bucket:${await storageReference.getBucket()}");
|
||||
print("path:${await storageReference.getPath()}");
|
||||
print("meta:${await storageReference.getMetadata()}");
|
||||
Reference ref = FirebaseStorage.instance.ref().child('$path/$fileName');
|
||||
UploadTask uploadTask = ref.putFile(file);
|
||||
await uploadTask.resume();
|
||||
String downloadUrl = await ref.getDownloadURL();
|
||||
return downloadUrl;
|
||||
// StorageReference storageReference =
|
||||
// FirebaseStorage(storageBucket: Config.instance.bucketName)
|
||||
// .ref()
|
||||
// .child('$path/$fileName');
|
||||
// StorageUploadTask uploadTask = storageReference.putFile(file);
|
||||
// await uploadTask.onComplete;
|
||||
// String downloadUrl = await storageReference.getDownloadURL();
|
||||
// print("name:${await storageReference.getName()}");
|
||||
// print("bucket:${await storageReference.getBucket()}");
|
||||
// print("path:${await storageReference.getPath()}");
|
||||
// print("meta:${await storageReference.getMetadata()}");
|
||||
// return downloadUrl;
|
||||
}
|
||||
|
||||
Future<void> deleteStorageFromUrls(List<String> urls) async {
|
||||
@@ -62,10 +66,12 @@ Future<void> deleteStorageFromUrls(List<String> urls) async {
|
||||
|
||||
Future<void> deleteStorageFromUrl(String url) async {
|
||||
try {
|
||||
StorageReference storageReference =
|
||||
await FirebaseStorage(storageBucket: Config.instance.bucketName)
|
||||
.getReferenceFromUrl(url);
|
||||
await storageReference.delete();
|
||||
Reference ref = FirebaseStorage.instance.refFromURL(url);
|
||||
await ref.delete();
|
||||
// StorageReference storageReference =
|
||||
// await FirebaseStorage(storageBucket: Config.instance.bucketName)
|
||||
// .getReferenceFromUrl(url);
|
||||
// await storageReference.delete();
|
||||
} catch (e) {
|
||||
log.warning("deleteStorage:$e");
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class NetworkConnectivity {
|
||||
final log = Logger('NetworkConnectivity');
|
||||
|
||||
static final NetworkConnectivity instance = NetworkConnectivity._internal();
|
||||
static String hostName;
|
||||
static String? hostName;
|
||||
NetworkConnectivity._internal() {
|
||||
_initialise();
|
||||
var uri = Uri.parse(Config.instance.apiURL);
|
||||
@@ -38,7 +38,7 @@ class NetworkConnectivity {
|
||||
// lookup if connectivity is not none
|
||||
if (result != ConnectivityResult.none) {
|
||||
try {
|
||||
final hostNameLookup = await InternetAddress.lookup(hostName);
|
||||
final hostNameLookup = await InternetAddress.lookup(hostName ?? "");
|
||||
if (hostNameLookup.isNotEmpty &&
|
||||
hostNameLookup[0].rawAddress.isNotEmpty) {
|
||||
if (await checkHeartbeat()) {
|
||||
|
||||
@@ -13,7 +13,7 @@ class Paginator<T> {
|
||||
final log = Logger('Paginator');
|
||||
|
||||
final int rowPerLoad;
|
||||
DocumentSnapshot prev;
|
||||
DocumentSnapshot? prev;
|
||||
bool ended = false;
|
||||
bool isLoading = false;
|
||||
List<T> values = [];
|
||||
@@ -21,7 +21,7 @@ class Paginator<T> {
|
||||
|
||||
Query pageQuery;
|
||||
|
||||
Paginator(this.pageQuery, {this.rowPerLoad = 20, this.toObj}) {
|
||||
Paginator(this.pageQuery, {this.rowPerLoad = 20, required this.toObj}) {
|
||||
_clearState();
|
||||
}
|
||||
|
||||
@@ -36,27 +36,27 @@ class Paginator<T> {
|
||||
_clearState();
|
||||
}
|
||||
|
||||
Future<void> refresh({CallBack onFinished}) async {
|
||||
Future<void> refresh({CallBack? onFinished}) async {
|
||||
_clearState();
|
||||
await load();
|
||||
if (onFinished != null) onFinished();
|
||||
}
|
||||
|
||||
Future<bool> load({CallBack onFinished}) async {
|
||||
Future<bool?> load({CallBack? onFinished}) async {
|
||||
if (ended) return null;
|
||||
isLoading = true;
|
||||
Query _query =
|
||||
prev != null ? pageQuery.startAfterDocument(prev) : pageQuery;
|
||||
prev != null ? pageQuery.startAfterDocument(prev!) : pageQuery;
|
||||
try {
|
||||
await _query
|
||||
.limit(rowPerLoad)
|
||||
.getDocuments(source: Source.server)
|
||||
.get(GetOptions(source: Source.server))
|
||||
.then((QuerySnapshot snapshot) {
|
||||
int count = snapshot.documents.length;
|
||||
int count = snapshot.docs.length;
|
||||
ended = count < rowPerLoad;
|
||||
prev = count > 0 ? snapshot.documents[count - 1] : prev;
|
||||
snapshot.documents.forEach((e) {
|
||||
values.add(toObj(e.data, e.documentID));
|
||||
prev = count > 0 ? snapshot.docs[count - 1] : prev;
|
||||
snapshot.docs.forEach((e) {
|
||||
values.add(toObj(e.data() as Map<String, dynamic>, e.id));
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
@@ -7,17 +7,17 @@ class SharedPref {
|
||||
static final SharedPref instance = SharedPref._();
|
||||
SharedPref._();
|
||||
|
||||
static Future<bool> isFirstLaunch() async {
|
||||
static Future<bool?> isFirstLaunch() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool('first_launch');
|
||||
}
|
||||
|
||||
static Future<void> finishFirstLaunch() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
return prefs.setBool('first_launch', false);
|
||||
prefs.setBool('first_launch', false);
|
||||
}
|
||||
|
||||
static Future<String> getLang() async {
|
||||
static Future<String?> getLang() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString('language');
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class SharedPref {
|
||||
prefs.setString('language', lang);
|
||||
}
|
||||
|
||||
static Future<bool> getStaffMode() async {
|
||||
static Future<bool?> getStaffMode() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool('staff_mode_on');
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class SharedPref {
|
||||
await _save("user", user.toJson());
|
||||
}
|
||||
|
||||
static Future<User> getUser() async {
|
||||
static Future<User?> getUser() async {
|
||||
try {
|
||||
return User.fromJson(await _read("user"));
|
||||
} catch (e) {
|
||||
@@ -57,7 +57,7 @@ class SharedPref {
|
||||
await _save("skipped_recovery_email", skipped);
|
||||
}
|
||||
|
||||
static Future<bool> getSkippedRecoverEmail() async {
|
||||
static Future<bool?> getSkippedRecoverEmail() async {
|
||||
try {
|
||||
bool _skipped = await _read("skipped_recovery_email");
|
||||
return _skipped;
|
||||
@@ -69,7 +69,7 @@ class SharedPref {
|
||||
static _read(String key) async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return json.decode(prefs.getString(key));
|
||||
return json.decode(prefs.getString(key) ?? "");
|
||||
} catch (e) {
|
||||
print("Error:$e");
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ const TextStyle labelStyleMM = TextStyle(
|
||||
fontFamily: "Myanmar3");
|
||||
const TextStyle subMenuStyle =
|
||||
TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.w500);
|
||||
const TextStyle subMenuStyleMM =
|
||||
TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.w500,
|
||||
const TextStyle subMenuStyleMM = TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontFamily: "Myanmar3");
|
||||
|
||||
const TextStyle welcomeLabelStyle =
|
||||
@@ -31,11 +33,10 @@ const TextStyle welcomeSubLabelStyle =
|
||||
const TextStyle siginButtonStyle =
|
||||
TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w500);
|
||||
|
||||
|
||||
TextStyle newLabelStyle(
|
||||
{Color color,
|
||||
double fontSize,
|
||||
FontWeight fontWeight,
|
||||
{Color? color,
|
||||
double? fontSize,
|
||||
FontWeight? fontWeight,
|
||||
bool underline = false}) {
|
||||
return TextStyle(
|
||||
fontSize: fontSize == null ? 14 : fontSize,
|
||||
@@ -45,9 +46,9 @@ TextStyle newLabelStyle(
|
||||
}
|
||||
|
||||
TextStyle newLabelStyleMM(
|
||||
{Color color,
|
||||
double fontSize,
|
||||
FontWeight fontWeight,
|
||||
{Color? color,
|
||||
double? fontSize,
|
||||
FontWeight? fontWeight,
|
||||
bool underline = false}) {
|
||||
return TextStyle(
|
||||
fontSize: fontSize == null ? 13 : fontSize,
|
||||
@@ -59,8 +60,8 @@ TextStyle newLabelStyleMM(
|
||||
|
||||
const TextStyle photoLabelStyle =
|
||||
TextStyle(color: Colors.black, fontSize: 13.0);
|
||||
const TextStyle photoLabelStyleMM = TextStyle(
|
||||
color: Colors.black, fontSize: 13.0, fontFamily: "Myanmar3");
|
||||
const TextStyle photoLabelStyleMM =
|
||||
TextStyle(color: Colors.black, fontSize: 13.0, fontFamily: "Myanmar3");
|
||||
const TextStyle textStyle =
|
||||
TextStyle(fontSize: 14, color: Colors.black87, fontWeight: FontWeight.w500);
|
||||
const TextStyle textStyleOdd = TextStyle(
|
||||
|
||||
Reference in New Issue
Block a user