mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 01:02:14 +08:00
SyncButton: Disable if no connectivity
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:connectivity/connectivity.dart';
|
||||
|
||||
import 'package:git_bindings/git_bindings.dart';
|
||||
import 'package:gitjournal/appstate.dart';
|
||||
|
||||
import 'package:gitjournal/utils.dart';
|
||||
import 'package:gitjournal/state_container.dart';
|
||||
|
||||
@ -11,14 +14,44 @@ class SyncButton extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SyncButtonState extends State<SyncButton> {
|
||||
StreamSubscription<ConnectivityResult> subscription;
|
||||
ConnectivityResult _connectivity;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
subscription = Connectivity()
|
||||
.onConnectivityChanged
|
||||
.listen((ConnectivityResult result) {
|
||||
setState(() {
|
||||
_connectivity = result;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
subscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final container = StateContainer.of(context);
|
||||
final appState = container.appState;
|
||||
|
||||
if (_connectivity == ConnectivityResult.none) {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.signal_wifi_off),
|
||||
onPressed: () async {
|
||||
_syncRepo();
|
||||
},
|
||||
);
|
||||
}
|
||||
if (appState.syncStatus == SyncStatus.Loading) {
|
||||
return RotatingIcon();
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
icon: Icon(_syncStatusIcon()),
|
||||
onPressed: () async {
|
||||
|
@ -71,6 +71,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.14.11"
|
||||
connectivity:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: connectivity
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.6+1"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -33,6 +33,7 @@ dependencies:
|
||||
git_bindings: ^0.0.6
|
||||
fetch_app_logs: ^0.0.2
|
||||
flutter_runtime_env: ^0.0.1
|
||||
connectivity: ^0.4.6+1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.7.2"
|
||||
|
Reference in New Issue
Block a user