Skip to content

Commit

Permalink
add delay & retry on empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
ghassenbenzahra123 committed Jul 9, 2024
1 parent f88d06a commit 3890097
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
26 changes: 3 additions & 23 deletions lib/src/pages/onBoarding/widgets/Wifi_selector_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,12 @@ class _OnBoardingWifiSelectorState
super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) async {
if (_timeManager.deviceModel == "MAWAQITBOX V2") {
await addLocationPermission();
await addFineLocationPermission();

await ref.read(wifiScanNotifierProvider.notifier).retry();
} else {
await ref.read(wifiScanNotifierProvider.notifier).retry();
}
WidgetsBinding.instance.addPostFrameCallback((_) async {
await ref.read(wifiScanNotifierProvider.notifier).initializeScan();
});
});
}

Future<void> addLocationPermission() async {
try {
await platform.invokeMethod('addLocationPermission');
} on PlatformException catch (e) {
logger.e("kiosk mode: location permission: error: $e");
}
}

Future<void> addFineLocationPermission() async {
try {
await platform.invokeMethod('grantFineLocationPermission');
} on PlatformException catch (e) {
logger.e("kiosk mode: location permission: error: $e");
}
}

void _showToast(String message) {
Fluttertoast.showToast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,50 @@ import '../../../pages/onBoarding/widgets/onboarding_timezone_selector.dart';
class WifiScanNotifier extends AsyncNotifier<WifiScanState> {
final TimeShiftManager _timeManager = TimeShiftManager();

@override
@override
Future<WifiScanState> build() async {
state = AsyncData(WifiScanState(
accessPoints: [],
hasPermission: false,
status: Status.connecting,
));
await _scan();
await initializeScan();
return state.value!;
}

Future<void> initializeScan() async {
await _requestPermissions();
await Future.delayed(Duration(seconds: 2));
await _scan();
if (state.value!.accessPoints.isEmpty) {
await Future.delayed(Duration(seconds: 2));
await retry();
}
}

Future<void> _requestPermissions() async {
if (_timeManager.deviceModel == "MAWAQITBOX V2") {
await addLocationPermission();
await addFineLocationPermission();
}
}

Future<void> addLocationPermission() async {
try {
await platform.invokeMethod('addLocationPermission');
} on PlatformException catch (e) {
logger.e("kiosk mode: location permission: error: $e");
}
}

Future<void> addFineLocationPermission() async {
try {
await platform.invokeMethod('grantFineLocationPermission');
} on PlatformException catch (e) {
logger.e("kiosk mode: location permission: error: $e");
}
}

Future<void> _scan() async {
state = AsyncLoading();
try {
Expand Down

0 comments on commit 3890097

Please sign in to comment.