Skip to content

Commit

Permalink
refactor: improve code and decrease delay to 1.5s in `connectToESP826…
Browse files Browse the repository at this point in the history
…6` to open app settings wifi panel
  • Loading branch information
mediocre9 committed Jan 6, 2024
1 parent 88acf56 commit 92b9ea4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
10 changes: 5 additions & 5 deletions lib/screens/wifi_home_screen/cubit/wifi_home_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:app_settings/app_settings.dart';
import 'package:bloc/bloc.dart';
import 'package:http/http.dart';

import '../../../config/strings/app_strings.dart';
import 'package:app_settings/app_settings.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:smart_link/config/config.dart';
part 'wifi_home_state.dart';

class WifiHomeCubit extends Cubit<WifiHomeState> {
WifiHomeCubit() : super(Initial());
String? baseUrl;

Future<void> connectToESP8266() async {
baseUrl = "http://${AppStrings.deviceServerIP}/";
baseUrl = "http://${AppStrings.deviceServerIP}";
emit(Connecting());
try {
Response response = await get(Uri.parse(baseUrl!));
Expand All @@ -20,7 +20,7 @@ class WifiHomeCubit extends Cubit<WifiHomeState> {
} catch (e) {
emit(NotConnected("Connection failed!"));
emit(Initial());
await Future.delayed(const Duration(seconds: 2));
await Future.delayed(1.5.seconds);
await AppSettings.openAppSettingsPanel(AppSettingsPanelType.wifi);
}
}
Expand Down
18 changes: 5 additions & 13 deletions lib/screens/wifi_home_screen/wifi_home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:smart_link/config/index.dart';
import '../../common/app_drawer.dart';
import '../../common/standard_app_widgets.dart';
import 'cubit/wifi_home_cubit.dart';
import 'package:smart_link/common/common.dart';
import 'package:smart_link/config/config.dart';
import 'package:smart_link/screens/wifi_home_screen/cubit/wifi_home_cubit.dart';

class WifiHomeScreen extends StatelessWidget with StandardAppWidgets {
const WifiHomeScreen({super.key});
Expand All @@ -16,14 +15,7 @@ class WifiHomeScreen extends StatelessWidget with StandardAppWidgets {
appBar: AppBar(
title: const Text("Locker Home"),
actions: [
IconButton(
icon: const Icon(Icons.bug_report_rounded),
onPressed: () => Navigator.pushNamed(context, Routes.feedback),
),
IconButton(
icon: const Icon(Icons.info_outline_rounded),
onPressed: () => showAboutDialogWidget(context),
),
popupMenuButtonWidget(context),
],
),
drawer: AppDrawer(),
Expand Down Expand Up @@ -77,7 +69,7 @@ class WifiHomeScreen extends StatelessWidget with StandardAppWidgets {
case Connected():
Navigator.pushNamed(
context,
Routes.wifiRemote,
AppRoutes.wifiRemote,
arguments: state.baseUrl,
);
break;
Expand Down

0 comments on commit 92b9ea4

Please sign in to comment.