Skip to content

Commit f0ea905

Browse files
committed
Remove connectivity
1 parent e50aed4 commit f0ea905

File tree

11 files changed

+66
-130
lines changed

11 files changed

+66
-130
lines changed

lib/main.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:connectivity_plus/connectivity_plus.dart';
21
import 'package:flutter/material.dart';
32
import 'package:open_weather_client/open_weather.dart';
43
import 'package:watch_it/watch_it.dart';
@@ -18,9 +17,7 @@ Future<void> main() async {
1817
locationsService,
1918
dispose: (s) => s.dispose(),
2019
);
21-
final appModel = AppModel(connectivity: Connectivity());
22-
await appModel.init();
23-
di.registerSingleton(appModel);
20+
di.registerSingleton(AppModel());
2421

2522
di.registerLazySingleton(
2623
() => WeatherModel(

lib/src/app/app.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import 'package:yaru/yaru.dart';
88
import '../../constants.dart';
99
import '../../weather.dart';
1010
import '../weather/weather_model.dart';
11-
import 'app_model.dart';
12-
import 'offline_page.dart';
1311
import 'side_bar.dart';
1412

1513
class App extends StatelessWidget {
@@ -59,8 +57,6 @@ class _AppPageState extends State<AppPage> {
5957

6058
@override
6159
Widget build(BuildContext context) {
62-
final isOnline = watchPropertyValue((AppModel m) => m.isOnline);
63-
6460
final weatherType = watchPropertyValue((WeatherModel m) => m.weatherType);
6561

6662
return LayoutBuilder(
@@ -79,11 +75,9 @@ class _AppPageState extends State<AppPage> {
7975
children: [
8076
if (constraints.maxWidth > kBreakPoint) const SideBar(),
8177
Expanded(
82-
child: !isOnline
83-
? const OfflinePage()
84-
: WeatherPage(
85-
showDrawer: constraints.maxWidth < kBreakPoint,
86-
),
78+
child: WeatherPage(
79+
showDrawer: constraints.maxWidth < kBreakPoint,
80+
),
8781
),
8882
],
8983
),

lib/src/app/app_model.dart

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
1-
import 'dart:async';
2-
3-
import 'package:connectivity_plus/connectivity_plus.dart';
41
import 'package:flutter/widgets.dart';
52
import 'package:safe_change_notifier/safe_change_notifier.dart';
63

74
class AppModel extends SafeChangeNotifier {
8-
AppModel({required Connectivity connectivity})
9-
: _connectivity = connectivity,
10-
_countryCode = WidgetsBinding
5+
AppModel()
6+
: _countryCode = WidgetsBinding
117
.instance.platformDispatcher.locale.countryCode
128
?.toLowerCase();
139

1410
final String? _countryCode;
1511
String? get countryCode => _countryCode;
1612

17-
final Connectivity _connectivity;
18-
StreamSubscription? _subscription;
19-
ConnectivityResult? _result;
20-
21-
bool get isOnline =>
22-
_result == ConnectivityResult.wifi ||
23-
_result == ConnectivityResult.ethernet ||
24-
_result == ConnectivityResult.vpn ||
25-
_result == ConnectivityResult.bluetooth ||
26-
_result == ConnectivityResult.mobile;
27-
28-
Future<void> init() async {
29-
_subscription ??=
30-
_connectivity.onConnectivityChanged.listen(_updateConnectivity);
31-
return _connectivity.checkConnectivity().then(_updateConnectivity);
32-
}
33-
34-
@override
35-
Future<void> dispose() async {
36-
await _subscription?.cancel();
37-
super.dispose();
38-
}
39-
40-
void _updateConnectivity(List<ConnectivityResult> result) {
41-
if (_result == result.firstOrNull) return;
42-
_result = result.firstOrNull;
43-
notifyListeners();
44-
}
45-
4613
int _tabIndex = 0;
4714
int get tabIndex => _tabIndex;
4815
set tabIndex(int value) {

lib/src/app/offline_page.dart

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,43 @@ class OfflinePage extends StatelessWidget {
2121
)
2222
: const SizedBox.shrink(),
2323
),
24-
body: Center(
25-
child: Column(
26-
mainAxisSize: MainAxisSize.min,
27-
children: [
28-
YaruAnimatedVectorIcon(
29-
YaruAnimatedIcons.no_network,
30-
size: 200,
31-
color: theme.disabledColor,
24+
body: const OfflineBody(),
25+
);
26+
}
27+
}
28+
29+
class OfflineBody extends StatelessWidget {
30+
const OfflineBody({
31+
super.key,
32+
});
33+
34+
@override
35+
Widget build(BuildContext context) {
36+
final theme = context.theme;
37+
return Center(
38+
child: Column(
39+
mainAxisSize: MainAxisSize.min,
40+
children: [
41+
YaruAnimatedVectorIcon(
42+
YaruAnimatedIcons.no_network,
43+
size: 200,
44+
color: theme.disabledColor,
45+
),
46+
Padding(
47+
padding: const EdgeInsets.only(
48+
top: kYaruPagePadding,
49+
left: 40,
50+
right: 40,
3251
),
33-
Padding(
34-
padding: const EdgeInsets.only(
35-
top: kYaruPagePadding,
36-
left: 40,
37-
right: 40,
38-
),
39-
child: Text(
40-
"It look's like your computer is not connected to the internet",
41-
textAlign: TextAlign.center,
42-
style: theme.textTheme.headlineMedium?.copyWith(
43-
color: theme.disabledColor,
44-
),
52+
child: Text(
53+
"It look's like your computer is not connected to the internet",
54+
textAlign: TextAlign.center,
55+
style: theme.textTheme.headlineMedium?.copyWith(
56+
color: theme.disabledColor,
4557
),
4658
),
47-
],
48-
),
59+
),
60+
],
4961
),
5062
);
5163
}

lib/src/weather/theme_x.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ extension ThemeX on ThemeData {
44
bool get light => brightness == Brightness.light;
55

66
TextStyle? get weatherBgTextStyle => textTheme.headlineSmall?.copyWith(
7-
color: Colors.white,
7+
color: colorScheme.onSurface,
88
fontSize: 20,
99
shadows: [
10-
Shadow(
11-
color: Colors.black.withOpacity(light ? 1 : 0.8),
12-
offset: const Offset(0, 0),
13-
blurRadius: light ? 2 : 3,
14-
),
10+
if (!light)
11+
Shadow(
12+
color: Colors.black.withOpacity(light ? 1 : 0.8),
13+
offset: const Offset(0, 0),
14+
blurRadius: light ? 2 : 3,
15+
),
1516
],
1617
);
1718
}

lib/src/weather/view/error_view.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:watch_it/watch_it.dart';
44
import 'package:yaru/yaru.dart';
55

66
import '../../../string_x.dart';
7+
import '../../app/offline_page.dart';
78
import '../../build_context_x.dart';
89
import '../weather_model.dart';
910
import 'city_search_field.dart';
@@ -36,6 +37,10 @@ class _ErrorViewState extends State<ErrorView> {
3637
Widget build(BuildContext context) {
3738
final model = di<WeatherModel>();
3839

40+
if (widget.error.networkProblem == true) {
41+
return const OfflineBody();
42+
}
43+
3944
return Center(
4045
child: Padding(
4146
padding: const EdgeInsets.all(kYaruPagePadding),

lib/src/weather/weather_model.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class WeatherModel extends SafeChangeNotifier {
9797
return weatherData;
9898
} catch (e) {
9999
error = e.toString();
100+
print(error);
100101
return null;
101102
}
102103
}

lib/string_x.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ extension StringExtension on String {
1313
bool get emptyCity => contains('Nothing to geocode');
1414
bool get cityNotFound => contains('city not found');
1515
bool get invalidKey => contains('Invalid API key');
16+
bool get networkProblem => contains('Failed host lookup');
1617
}

pubspec.lock

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ packages:
3333
url: "https://pub.dev"
3434
source: hosted
3535
version: "3.4.10"
36-
args:
37-
dependency: transitive
38-
description:
39-
name: args
40-
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
41-
url: "https://pub.dev"
42-
source: hosted
43-
version: "2.4.2"
4436
async:
4537
dependency: transitive
4638
description:
@@ -81,22 +73,6 @@ packages:
8173
url: "https://pub.dev"
8274
source: hosted
8375
version: "1.18.0"
84-
connectivity_plus:
85-
dependency: "direct main"
86-
description:
87-
name: connectivity_plus
88-
sha256: db7a4e143dc72cc3cb2044ef9b052a7ebfe729513e6a82943bc3526f784365b8
89-
url: "https://pub.dev"
90-
source: hosted
91-
version: "6.0.3"
92-
connectivity_plus_platform_interface:
93-
dependency: transitive
94-
description:
95-
name: connectivity_plus_platform_interface
96-
sha256: b6a56efe1e6675be240de39107281d4034b64ac23438026355b4234042a35adb
97-
url: "https://pub.dev"
98-
source: hosted
99-
version: "2.0.0"
10076
convert:
10177
dependency: transitive
10278
description:
@@ -113,14 +89,6 @@ packages:
11389
url: "https://pub.dev"
11490
source: hosted
11591
version: "3.0.3"
116-
dbus:
117-
dependency: transitive
118-
description:
119-
name: dbus
120-
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
121-
url: "https://pub.dev"
122-
source: hosted
123-
version: "0.7.10"
12492
equatable:
12593
dependency: transitive
12694
description:
@@ -329,14 +297,6 @@ packages:
329297
url: "https://pub.dev"
330298
source: hosted
331299
version: "1.11.0"
332-
nm:
333-
dependency: transitive
334-
description:
335-
name: nm
336-
sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254"
337-
url: "https://pub.dev"
338-
source: hosted
339-
version: "0.5.0"
340300
open_weather_client:
341301
dependency: "direct main"
342302
description:

pubspec.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,26 @@ environment:
1010
flutter: ">=3.19.5"
1111

1212
dependencies:
13+
animated_emoji: ^3.1.0
1314
collection: ^1.16.0
15+
fl_chart: ^0.67.0
1416
flutter:
1517
sdk: flutter
1618

17-
handy_window: ^0.4.0
18-
intl: ^0.19.0
19-
open_weather_client: ^2.3.2
20-
safe_change_notifier: ^0.3.0
21-
yaru: ^4.1.0
22-
2319
flutter_weather_bg_null_safety:
2420
git:
2521
url: https://github.com/Feichtmeier/flutter_weather_bg_null_safety
2622
ref: b9e3943904596809b957b44a3733b3794a43517b
23+
24+
handy_window: ^0.4.0
25+
intl: ^0.19.0
26+
open_weather_client: ^2.3.2
27+
path: ^1.9.0
28+
path_provider: ^2.1.3
29+
safe_change_notifier: ^0.3.0
2730
watch_it: ^1.4.1
2831
xdg_directories: ^1.0.4
29-
path_provider: ^2.1.3
30-
path: ^1.9.0
31-
connectivity_plus: ^6.0.3
32-
fl_chart: ^0.67.0
33-
animated_emoji: ^3.1.0
32+
yaru: ^4.1.0
3433

3534
dev_dependencies:
3635
flutter_lints: ^3.0.1

0 commit comments

Comments
 (0)