From bc9e308971751b305a54287c99daef5c818c9a06 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 26 Dec 2019 20:48:54 +0100 Subject: [PATCH] Move SyncButton to its own file --- lib/screens/journal_listing.dart | 94 +----------------------------- lib/widgets/sync_button.dart | 98 ++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 93 deletions(-) create mode 100644 lib/widgets/sync_button.dart diff --git a/lib/screens/journal_listing.dart b/lib/screens/journal_listing.dart index 1197618c..761aa0e7 100644 --- a/lib/screens/journal_listing.dart +++ b/lib/screens/journal_listing.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:git_bindings/git_bindings.dart'; -import 'package:gitjournal/appstate.dart'; import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/notes_folder.dart'; @@ -11,6 +10,7 @@ import 'package:gitjournal/state_container.dart'; import 'package:gitjournal/widgets/app_drawer.dart'; import 'package:gitjournal/widgets/app_bar_menu_button.dart'; import 'package:gitjournal/widgets/journal_list.dart'; +import 'package:gitjournal/widgets/sync_button.dart'; import 'package:gitjournal/themes.dart'; class JournalListingScreen extends StatelessWidget { @@ -165,95 +165,3 @@ class NoteSearch extends SearchDelegate { return journalList; } } - -class SyncButton extends StatefulWidget { - @override - _SyncButtonState createState() => _SyncButtonState(); -} - -class _SyncButtonState extends State { - @override - Widget build(BuildContext context) { - final container = StateContainer.of(context); - final appState = container.appState; - - if (appState.syncStatus == SyncStatus.Loading) { - return RotatingIcon(); - } - return IconButton( - icon: Icon(_syncStatusIcon()), - onPressed: () async { - _syncRepo(); - }, - ); - } - - void _syncRepo() async { - final container = StateContainer.of(context); - try { - await container.syncNotes(); - } on GitException catch (exp) { - showSnackbar(context, exp.cause); - } - } - - IconData _syncStatusIcon() { - final container = StateContainer.of(context); - final appState = container.appState; - switch (appState.syncStatus) { - case SyncStatus.Error: - return Icons.cloud_off; - - case SyncStatus.Unknown: - case SyncStatus.Done: - default: - return Icons.cloud_done; - } - } -} - -class RotatingIcon extends StatefulWidget { - @override - _RotatingIconState createState() => _RotatingIconState(); -} - -class _RotatingIconState extends State - with SingleTickerProviderStateMixin { - AnimationController _controller; - Animation _animation; - - @override - void initState() { - super.initState(); - - _controller = AnimationController( - vsync: this, - duration: const Duration(milliseconds: 1800), - ); - _animation = CurvedAnimation( - parent: _controller, - curve: Curves.linear, - ); - - _controller.repeat(reverse: true); - } - - @override - void dispose() { - _controller.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - var button = IconButton( - icon: const Icon(Icons.loop), - onPressed: () {}, - ); - - return RotationTransition( - child: button, - turns: _animation, - ); - } -} diff --git a/lib/widgets/sync_button.dart b/lib/widgets/sync_button.dart new file mode 100644 index 00000000..fa8c80cb --- /dev/null +++ b/lib/widgets/sync_button.dart @@ -0,0 +1,98 @@ +import 'package:flutter/material.dart'; +import 'package:git_bindings/git_bindings.dart'; +import 'package:gitjournal/appstate.dart'; + +import 'package:gitjournal/utils.dart'; +import 'package:gitjournal/state_container.dart'; + +class SyncButton extends StatefulWidget { + @override + _SyncButtonState createState() => _SyncButtonState(); +} + +class _SyncButtonState extends State { + @override + Widget build(BuildContext context) { + final container = StateContainer.of(context); + final appState = container.appState; + + if (appState.syncStatus == SyncStatus.Loading) { + return RotatingIcon(); + } + return IconButton( + icon: Icon(_syncStatusIcon()), + onPressed: () async { + _syncRepo(); + }, + ); + } + + void _syncRepo() async { + final container = StateContainer.of(context); + try { + await container.syncNotes(); + } on GitException catch (exp) { + showSnackbar(context, exp.cause); + } + } + + IconData _syncStatusIcon() { + final container = StateContainer.of(context); + final appState = container.appState; + switch (appState.syncStatus) { + case SyncStatus.Error: + return Icons.cloud_off; + + case SyncStatus.Unknown: + case SyncStatus.Done: + default: + return Icons.cloud_done; + } + } +} + +class RotatingIcon extends StatefulWidget { + @override + _RotatingIconState createState() => _RotatingIconState(); +} + +class _RotatingIconState extends State + with SingleTickerProviderStateMixin { + AnimationController _controller; + Animation _animation; + + @override + void initState() { + super.initState(); + + _controller = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 1800), + ); + _animation = CurvedAnimation( + parent: _controller, + curve: Curves.linear, + ); + + _controller.repeat(reverse: true); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + var button = IconButton( + icon: const Icon(Icons.loop), + onPressed: () {}, + ); + + return RotationTransition( + child: button, + turns: _animation, + ); + } +}