From ecb5c2f437915698b347ab59135672e4a88715ce Mon Sep 17 00:00:00 2001 From: Vishnu Mohandas Date: Sat, 6 Jun 2020 19:18:29 +0530 Subject: [PATCH] Add text to indicate syncing state --- lib/ui/gallery.dart | 32 +++++++++++++++++++++++++++----- pubspec.lock | 7 +++++++ pubspec.yaml | 1 + 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/ui/gallery.dart b/lib/ui/gallery.dart index 2649f7be6..ec88b9cdc 100644 --- a/lib/ui/gallery.dart +++ b/lib/ui/gallery.dart @@ -4,9 +4,11 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:photos/models/photo.dart'; +import 'package:photos/photo_sync_manager.dart'; import 'package:photos/ui/detail_page.dart'; import 'package:photos/ui/thumbnail_widget.dart'; import 'package:photos/utils/date_time_util.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; class Gallery extends StatefulWidget { final List photos; @@ -27,6 +29,8 @@ class _GalleryState extends State { final List> _collatedPhotos = List>(); Set _selectedPhotos = HashSet(); List _photos; + RefreshController _refreshController = + RefreshController(initialRefresh: false); @override Widget build(BuildContext context) { @@ -36,11 +40,29 @@ class _GalleryState extends State { _deduplicatePhotos(); _collatePhotos(); - return ListView.builder( - itemCount: _collatedPhotos.length, - itemBuilder: _buildListItem, - controller: _scrollController, - cacheExtent: 1000, + return SmartRefresher( + controller: _refreshController, + enablePullUp: true, + child: ListView.builder( + itemCount: _collatedPhotos.length, + itemBuilder: _buildListItem, + controller: _scrollController, + cacheExtent: 1000, + ), + header: ClassicHeader( + idleText: "Pull down to sync.", + refreshingText: "Syncing...", + releaseText: "Release to sync.", + completeText: "Sync completed.", + failedText: "Sync unsuccessful.", + ), + onRefresh: () async { + PhotoSyncManager.instance.sync().then((value) { + _refreshController.refreshCompleted(); + }).catchError((e) { + _refreshController.refreshFailed(); + }); + }, ); } diff --git a/pubspec.lock b/pubspec.lock index 762295f8c..7c3a80170 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -331,6 +331,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.2.0" + pull_to_refresh: + dependency: "direct main" + description: + name: pull_to_refresh + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.8" quiver: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d64c6971c..bfdb15d52 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -48,6 +48,7 @@ dependencies: logging: ^0.11.4 flutter_image_compress: ^0.6.5+1 flutter_typeahead: ^1.8.1 + pull_to_refresh: ^1.5.7 dev_dependencies: flutter_test: