
Integrates the `toastification` package to provide clear and non-intrusive user feedback for operations like product not found. Refactors the reception scan page UI by extracting reusable widgets for the scan information text, the scan box, and the flash button. This improves code organization and readability. Switches the data source for reception details from API calls to the local ObjectBox database, improving performance and enabling offline access for this specific data. Corrects the display of scanned product information to show the barcode instead of a generic ID. Updates `go_router` to version 16.0.0.
85 lines
2.5 KiB
Dart
85 lines
2.5 KiB
Dart
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
export 'toastification.dart';
|
|
|
|
extension StatefulWidgetExtensions on State<StatefulWidget> {
|
|
/// Check if the widget exist before safely setting state.
|
|
void safeSetState(VoidCallback fn) {
|
|
if (mounted) {
|
|
// ignore: invalid_use_of_protected_member
|
|
setState(fn);
|
|
}
|
|
}
|
|
}
|
|
|
|
String? stringFromJson(dynamic json) {
|
|
if (json is String && json.isNotEmpty) return json;
|
|
return null;
|
|
}
|
|
|
|
double? doubleFromJson(dynamic json) {
|
|
if (json is double) return json;
|
|
return null;
|
|
}
|
|
|
|
int? intFromJson(dynamic json) {
|
|
if (json is int) return json;
|
|
return null;
|
|
}
|
|
|
|
T? objectFromJson<T>(dynamic json, T Function(Map<String, dynamic>) fromJson) {
|
|
if (json is Map<String, dynamic>) return fromJson(json);
|
|
return null;
|
|
}
|
|
|
|
List<T>? listFromJson<T>(
|
|
dynamic json,
|
|
T Function(Map<String, dynamic>) fromJson,
|
|
) {
|
|
if (json is List) {
|
|
return json
|
|
.whereType<Map<String, dynamic>>()
|
|
.map((e) => fromJson(e))
|
|
.toList();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Future<bool> checkInternetConnexion() async {
|
|
final List<ConnectivityResult> connectivityResult = await (Connectivity()
|
|
.checkConnectivity());
|
|
|
|
// This condition is for demo purposes only to explain every connection type.
|
|
// Use conditions which work for your requirements.
|
|
if (connectivityResult.contains(ConnectivityResult.mobile)) {
|
|
// Mobile network available.
|
|
return true;
|
|
} else if (connectivityResult.contains(ConnectivityResult.wifi)) {
|
|
// Wi-fi is available.
|
|
// Note for Android:
|
|
// When both mobile and Wi-Fi are turned on system will return Wi-Fi only as active network type
|
|
return true;
|
|
} else if (connectivityResult.contains(ConnectivityResult.ethernet)) {
|
|
// Ethernet connection available.
|
|
return true;
|
|
} else if (connectivityResult.contains(ConnectivityResult.vpn)) {
|
|
// Vpn connection active.
|
|
// Note for iOS and macOS:
|
|
// There is no separate network interface type for [vpn].
|
|
// It returns [other] on any device (also simulator)
|
|
return true;
|
|
} else if (connectivityResult.contains(ConnectivityResult.bluetooth)) {
|
|
// Bluetooth connection available.
|
|
return false;
|
|
} else if (connectivityResult.contains(ConnectivityResult.other)) {
|
|
// Connected to a network which is not in the above mentioned networks.
|
|
return false;
|
|
} else if (connectivityResult.contains(ConnectivityResult.none)) {
|
|
// No available network types
|
|
return false;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|