Skip to content

Commit

Permalink
add spinner when uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
qcasey committed Dec 2, 2020
1 parent b03b2ff commit e995b3e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 46 deletions.
113 changes: 67 additions & 46 deletions lib/share.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:dio/dio.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';
import 'model/auth.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class SharePage extends StatefulWidget {
@override
Expand All @@ -15,6 +16,7 @@ class SharePage extends StatefulWidget {
class _SharePageState extends State<SharePage> {
StreamSubscription _intentDataStreamSubscription;
List<SharedMediaFile> _sharedFiles;
bool _isActivelySharing = false;
final AuthModel _auth = AuthModel();

@override
Expand All @@ -26,7 +28,8 @@ class _SharePageState extends State<SharePage> {
.listen((List<SharedMediaFile> value) {
setState(() {
_sharedFiles = value;
if (_sharedFiles != null && _sharedFiles.isNotEmpty) {
_isActivelySharing = _sharedFiles != null && _sharedFiles.isNotEmpty;
if (_isActivelySharing) {
for (var f in _sharedFiles) {
uploadFileToPaperless(f.path);
}
Expand All @@ -40,7 +43,8 @@ class _SharePageState extends State<SharePage> {
ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
setState(() {
_sharedFiles = value;
if (_sharedFiles != null && _sharedFiles.isNotEmpty) {
_isActivelySharing = _sharedFiles != null && _sharedFiles.isNotEmpty;
if (_isActivelySharing) {
for (var f in _sharedFiles) {
uploadFileToPaperless(f.path);
}
Expand Down Expand Up @@ -93,55 +97,72 @@ class _SharePageState extends State<SharePage> {

@override
Widget build(BuildContext context) {
final _auth = Provider.of<AuthModel>(context, listen: true);

return Scaffold(
appBar: AppBar(
title: Text("Paperless Share"),
actions: [
// action button
IconButton(
icon: Icon(Icons.logout),
tooltip: "Logout",
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text("Logout?"),
actions: [
new FlatButton(
child: new Text("Yes"),
onPressed: () {
_auth.logout();
Navigator.pushReplacementNamed(context, "/login");
},
),
new FlatButton(
child: new Text("No"),
onPressed: () {
Navigator.of(context).pop();
}),
],
);
});
},
),
],
actions: [_actionButton()],
),
body: Center(
child: Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
padding: EdgeInsets.symmetric(vertical: 0),
child: FractionallySizedBox(
child: Column(
children: <Widget>[
_shareScreenExample(),
_welcomeText(),
],
)),
))));
child: FractionallySizedBox(child: _bodyContent()),
));
}

Widget _bodyContent() {
if (_isActivelySharing) {
return new Column(mainAxisAlignment: MainAxisAlignment.center, children: [
SpinKitRing(
color: Color(0xFF17541f),
size: 100.0,
)
]);
}

return new Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
_shareScreenExample(),
_welcomeText(),
],
)));
}

Widget _actionButton() {
final _auth = Provider.of<AuthModel>(context, listen: true);

if (_isActivelySharing) {
return new Container();
}

return // action button
IconButton(
icon: Icon(Icons.logout),
tooltip: "Logout",
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text("Logout?"),
actions: [
new FlatButton(
child: new Text("Yes"),
onPressed: () {
_auth.logout();
Navigator.pushReplacementNamed(context, "/login");
},
),
new FlatButton(
child: new Text("No"),
onPressed: () {
Navigator.of(context).pop();
}),
],
);
});
},
);
}

Widget _welcomeText() {
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ packages:
url: "https://github.com/knyghtryda/flutter_launcher_icons"
source: git
version: "0.7.5"
flutter_spinkit:
dependency: "direct main"
description:
name: flutter_spinkit
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.2+1"
flutter_string_encryption:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
receive_sharing_intent: ^1.4.2
dio: ^3.0.10
fluttertoast: ^7.1.5
flutter_spinkit: "^4.1.2"

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down

0 comments on commit e995b3e

Please sign in to comment.