mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-14 15:33:04 +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:flutter/material.dart';
|
||||||
|
import 'package:connectivity/connectivity.dart';
|
||||||
|
|
||||||
import 'package:git_bindings/git_bindings.dart';
|
import 'package:git_bindings/git_bindings.dart';
|
||||||
import 'package:gitjournal/appstate.dart';
|
import 'package:gitjournal/appstate.dart';
|
||||||
|
|
||||||
import 'package:gitjournal/utils.dart';
|
import 'package:gitjournal/utils.dart';
|
||||||
import 'package:gitjournal/state_container.dart';
|
import 'package:gitjournal/state_container.dart';
|
||||||
|
|
||||||
@ -11,14 +14,44 @@ class SyncButton extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SyncButtonState extends State<SyncButton> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final container = StateContainer.of(context);
|
final container = StateContainer.of(context);
|
||||||
final appState = container.appState;
|
final appState = container.appState;
|
||||||
|
|
||||||
|
if (_connectivity == ConnectivityResult.none) {
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(Icons.signal_wifi_off),
|
||||||
|
onPressed: () async {
|
||||||
|
_syncRepo();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
if (appState.syncStatus == SyncStatus.Loading) {
|
if (appState.syncStatus == SyncStatus.Loading) {
|
||||||
return RotatingIcon();
|
return RotatingIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
return IconButton(
|
return IconButton(
|
||||||
icon: Icon(_syncStatusIcon()),
|
icon: Icon(_syncStatusIcon()),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
@ -71,6 +71,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.14.11"
|
version: "1.14.11"
|
||||||
|
connectivity:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: connectivity
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.4.6+1"
|
||||||
convert:
|
convert:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -33,6 +33,7 @@ dependencies:
|
|||||||
git_bindings: ^0.0.6
|
git_bindings: ^0.0.6
|
||||||
fetch_app_logs: ^0.0.2
|
fetch_app_logs: ^0.0.2
|
||||||
flutter_runtime_env: ^0.0.1
|
flutter_runtime_env: ^0.0.1
|
||||||
|
connectivity: ^0.4.6+1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: "^0.7.2"
|
flutter_launcher_icons: "^0.7.2"
|
||||||
|
Reference in New Issue
Block a user