mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
SyncButton: Always show the number of changes
Even when pulling/pushing
This commit is contained in:
@ -42,37 +42,38 @@ class _SyncButtonState extends State<SyncButton> {
|
|||||||
final appState = Provider.of<StateContainer>(context).appState;
|
final appState = Provider.of<StateContainer>(context).appState;
|
||||||
|
|
||||||
if (_connectivity == ConnectivityResult.none) {
|
if (_connectivity == ConnectivityResult.none) {
|
||||||
return IconButton(
|
return GitPendingChangesBadge(
|
||||||
icon: Icon(Icons.signal_wifi_off),
|
child: IconButton(
|
||||||
onPressed: () async {
|
icon: Icon(Icons.signal_wifi_off),
|
||||||
_syncRepo();
|
onPressed: () async {
|
||||||
},
|
_syncRepo();
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (appState.syncStatus == SyncStatus.Pulling) {
|
if (appState.syncStatus == SyncStatus.Pulling) {
|
||||||
return BlinkingIcon(
|
return BlinkingIcon(
|
||||||
icon: Icon(Icons.cloud_download),
|
child: GitPendingChangesBadge(
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(Icons.cloud_download),
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appState.syncStatus == SyncStatus.Pushing) {
|
if (appState.syncStatus == SyncStatus.Pushing) {
|
||||||
return BlinkingIcon(
|
return BlinkingIcon(
|
||||||
icon: Icon(Icons.cloud_upload),
|
child: GitPendingChangesBadge(
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(Icons.cloud_upload),
|
||||||
|
onPressed: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var theme = Theme.of(context);
|
return GitPendingChangesBadge(
|
||||||
var darkMode = theme.brightness == Brightness.dark;
|
|
||||||
var style = theme.textTheme.caption.copyWith(
|
|
||||||
fontSize: 6.0,
|
|
||||||
color: darkMode ? Colors.black : Colors.white,
|
|
||||||
);
|
|
||||||
|
|
||||||
return Badge(
|
|
||||||
badgeContent: Text(appState.numChanges.toString(), style: style),
|
|
||||||
showBadge: appState.numChanges != 0,
|
|
||||||
badgeColor: theme.iconTheme.color,
|
|
||||||
position: BadgePosition.topRight(top: 10.0, right: 4.0),
|
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: Icon(_syncStatusIcon()),
|
icon: Icon(_syncStatusIcon()),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
@ -109,10 +110,10 @@ class _SyncButtonState extends State<SyncButton> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BlinkingIcon extends StatefulWidget {
|
class BlinkingIcon extends StatefulWidget {
|
||||||
final Icon icon;
|
final Widget child;
|
||||||
final int interval;
|
final int interval;
|
||||||
|
|
||||||
BlinkingIcon({@required this.icon, this.interval = 500, Key key})
|
BlinkingIcon({@required this.child, this.interval = 500, Key key})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -150,10 +151,33 @@ class _BlinkingIconState extends State<BlinkingIcon>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FadeTransition(
|
return FadeTransition(
|
||||||
opacity: _animation,
|
opacity: _animation,
|
||||||
child: IconButton(
|
child: widget.child,
|
||||||
icon: widget.icon,
|
);
|
||||||
onPressed: () {},
|
}
|
||||||
),
|
}
|
||||||
|
|
||||||
|
class GitPendingChangesBadge extends StatelessWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
GitPendingChangesBadge({@required this.child});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var theme = Theme.of(context);
|
||||||
|
var darkMode = theme.brightness == Brightness.dark;
|
||||||
|
var style = theme.textTheme.caption.copyWith(
|
||||||
|
fontSize: 6.0,
|
||||||
|
color: darkMode ? Colors.black : Colors.white,
|
||||||
|
);
|
||||||
|
|
||||||
|
final appState = Provider.of<StateContainer>(context).appState;
|
||||||
|
|
||||||
|
return Badge(
|
||||||
|
badgeContent: Text(appState.numChanges.toString(), style: style),
|
||||||
|
showBadge: appState.numChanges != 0,
|
||||||
|
badgeColor: theme.iconTheme.color,
|
||||||
|
position: BadgePosition.topRight(top: 10.0, right: 4.0),
|
||||||
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user