diff --git a/lib/domain/manage_network/i_manage_network_repository.dart b/lib/domain/manage_network/i_manage_network_repository.dart index 29fb092f..2ebc3093 100644 --- a/lib/domain/manage_network/i_manage_network_repository.dart +++ b/lib/domain/manage_network/i_manage_network_repository.dart @@ -24,7 +24,7 @@ abstract interface class IManageNetworkRepository { static ManageNetworkEntity? manageWiFiEntity; - Future loadWifi(); + Future loadWifi(); Future> doesWiFiEnabled(); diff --git a/lib/infrastructure/manage_wifi_repository.dart b/lib/infrastructure/manage_wifi_repository.dart index b512ded0..ab05247e 100644 --- a/lib/infrastructure/manage_wifi_repository.dart +++ b/lib/infrastructure/manage_wifi_repository.dart @@ -127,7 +127,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository { } @override - Future loadWifi() async { + Future loadWifi() async { final NetworkInfo info = NetworkInfo(); if (Platform.isLinux) { @@ -135,7 +135,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository { final String? wifiName = await info.getWifiName(); final String? ip = await info.getWifiIP(); if (bssid == null || wifiName == null || ip == null) { - return; + return false; } final String subnet = ipToSubnet(ip); @@ -150,7 +150,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository { ); NetworksManager().addNetwork(network); NetworksManager().setCurrentNetwork(network.uniqueId); - return; + return true; } final PermissionStatus locationStatus = await Permission.location.status; @@ -166,7 +166,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository { if (!isWifiEnabled || !isWifiConnected) { logger.w('Not connected to WiFi'); - exit(0); + return false; } String bssid; @@ -176,12 +176,12 @@ class _ManageWiFiRepository implements IManageNetworkRepository { logger.w( 'Location is not on or user-allowed approximate location instead of precise location', ); - exit(0); + return false; } bssid = bssidTemp; } else { logger.w('Missing location permission'); - exit(0); + return false; } final String? ssid = await WiFiForIoTPlugin.getSSID(); final String? ip = await WiFiForIoTPlugin.getIP(); @@ -190,7 +190,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository { if (ssid == null || ip == null) { logger.w('Ssid is null'); - exit(0); + return false; } final String subNet = ipToSubnet(ip); @@ -206,6 +206,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository { ); NetworksManager().addNetwork(network); NetworksManager().setCurrentNetwork(network.uniqueId); + return true; } String ipToSubnet(String ip) { diff --git a/lib/presentation/core/theme_data.dart b/lib/presentation/core/theme_data.dart index a5c3057a..35cedfd0 100644 --- a/lib/presentation/core/theme_data.dart +++ b/lib/presentation/core/theme_data.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; -// TODO: Add at least 4 more colors ///List of all the GradientColors to iterate on final Set> gradientColorsList = { GradientColors.sky, diff --git a/lib/presentation/molecules/permissions_dialog_molecule.dart b/lib/presentation/molecules/permissions_dialog_molecule.dart new file mode 100644 index 00000000..83e6e72a --- /dev/null +++ b/lib/presentation/molecules/permissions_dialog_molecule.dart @@ -0,0 +1,47 @@ +import 'dart:io'; + +import 'package:cybearjinni/presentation/atoms/button_atom.dart'; +import 'package:cybearjinni/presentation/atoms/separator_atom.dart'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; + +void permsissionsDialog(BuildContext context) => showDialog( + context: context, + barrierDismissible: false, + builder: (_) => const PermsissionsDialogMolecule(), + ); + +class PermsissionsDialogMolecule extends StatelessWidget { + const PermsissionsDialogMolecule({super.key}); + + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final TextTheme textTheme = themeData.textTheme; + + return AlertDialog( + content: SizedBox( + width: MediaQuery.of(context).size.width, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + '1. Make sure you are connected to home WiFi\n' + '2. Please make sure location is on and permission grented.', + style: textTheme.labelLarge, + textAlign: TextAlign.center, + ).tr(), + const SeparatorAtom(), + ButtonWidgetAtom( + variant: ButtonVariant.primary, + onPressed: () async { + exit(0); + }, + text: 'exit', + ), + ], + ), + ), + ); + } +} diff --git a/lib/presentation/pages/splash_page.dart b/lib/presentation/pages/splash_page.dart index 28ea0a1c..d6146c2d 100644 --- a/lib/presentation/pages/splash_page.dart +++ b/lib/presentation/pages/splash_page.dart @@ -10,6 +10,7 @@ import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:cybearjinni/infrastructure/mqtt.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; +import 'package:cybearjinni/presentation/molecules/permissions_dialog_molecule.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; @@ -32,7 +33,13 @@ class _SplashPageState extends State { await Hive.initFlutter(); await IDbRepository.instance.asyncConstactor(); NetworksManager().loadFromDb(); - await IManageNetworkRepository.instance.loadWifi(); + final bool sucess = await IManageNetworkRepository.instance.loadWifi(); + if (!sucess) { + if (mounted) { + permsissionsDialog(context); + } + return; + } final String? bssid = NetworksManager().currentNetwork?.bssid; if (bssid == null) { logger.e('Please set up network'); diff --git a/pubspec.yaml b/pubspec.yaml index 402a70c2..4413603e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: cybearjinni description: CyBear Jinni app to interact with your CyBear Jinni Smart Devices -version: 1.4.10+74 +version: 1.4.11+75 homepage: https://cybearjinni.com publish_to: 'none'