Refactoring : extracted many widgets from downloader
This commit is contained in:
parent
08c2152145
commit
2c00135a59
|
|
@ -7,6 +7,9 @@ import 'package:quickgui/src/globals.dart';
|
||||||
import 'package:quickgui/src/model/operating_system.dart';
|
import 'package:quickgui/src/model/operating_system.dart';
|
||||||
import 'package:quickgui/src/model/option.dart';
|
import 'package:quickgui/src/model/option.dart';
|
||||||
import 'package:quickgui/src/model/version.dart';
|
import 'package:quickgui/src/model/version.dart';
|
||||||
|
import 'package:quickgui/src/widgets/cancel_dismiss_button.dart';
|
||||||
|
import 'package:quickgui/src/widgets/download_label.dart';
|
||||||
|
import 'package:quickgui/src/widgets/download_progress_bar.dart';
|
||||||
|
|
||||||
class Downloader extends StatefulWidget {
|
class Downloader extends StatefulWidget {
|
||||||
const Downloader({
|
const Downloader({
|
||||||
|
|
@ -89,7 +92,8 @@ class _DownloaderState extends State<Downloader> {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(
|
title: Text(
|
||||||
'Downloading ${widget.operatingSystem.name} ${widget.version.version}' + (widget.option!.option.isNotEmpty ? ' (${widget.option!.option})' : '')),
|
'Downloading ${widget.operatingSystem.name} ${widget.version.version}' + (widget.option!.option.isNotEmpty ? ' (${widget.option!.option})' : ''),
|
||||||
|
),
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
|
|
@ -102,30 +106,14 @@ class _DownloaderState extends State<Downloader> {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
DownloadLabel(
|
||||||
padding: const EdgeInsets.all(8.0),
|
downloadFinished: _downloadFinished,
|
||||||
child: _downloadFinished
|
data: snapshot.hasData ? snapshot.data : null,
|
||||||
? const Text('Download finished.')
|
downloader: widget.option!.downloader,
|
||||||
: snapshot.hasData
|
|
||||||
? widget.option!.downloader != 'zsync'
|
|
||||||
? widget.option!.downloader == 'wget'
|
|
||||||
? Text('Downloading...${(snapshot.data! * 100).toInt()}%')
|
|
||||||
: Text('${snapshot.data} Mbs downloaded')
|
|
||||||
: const Text("Downloading (no progress available)...")
|
|
||||||
: const Text('Waiting for download to start'),
|
|
||||||
),
|
),
|
||||||
Padding(
|
DownloadProgressBar(
|
||||||
padding: const EdgeInsets.all(8.0),
|
downloadFinished: _downloadFinished,
|
||||||
child: SizedBox(
|
data: snapshot.hasData ? data : null,
|
||||||
width: 200,
|
|
||||||
child: LinearProgressIndicator(
|
|
||||||
value: _downloadFinished
|
|
||||||
? 1
|
|
||||||
: snapshot.hasData
|
|
||||||
? data
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 32),
|
padding: const EdgeInsets.only(top: 32),
|
||||||
|
|
@ -136,20 +124,8 @@ class _DownloaderState extends State<Downloader> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
CancelDismissButton(
|
||||||
padding: const EdgeInsets.all(8.0),
|
downloadFinished: _downloadFinished,
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: _downloadFinished
|
|
||||||
? () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: _downloadFinished ? const Text('Dimiss') : const Text('Cancel'))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class CancelDismissButton extends StatelessWidget {
|
||||||
|
const CancelDismissButton({
|
||||||
|
Key? key,
|
||||||
|
required this.downloadFinished,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final bool downloadFinished;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: !downloadFinished
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: downloadFinished ? const Text('Dimiss') : const Text('Cancel'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class DownloadLabel extends StatelessWidget {
|
||||||
|
const DownloadLabel({Key? key, required this.downloadFinished, required this.data, required this.downloader}) : super(key: key);
|
||||||
|
|
||||||
|
final bool downloadFinished;
|
||||||
|
final double? data;
|
||||||
|
final String downloader;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: downloadFinished
|
||||||
|
? const Text('Download finished.')
|
||||||
|
: data != null
|
||||||
|
? downloader != 'zsync'
|
||||||
|
? downloader == 'wget'
|
||||||
|
? Text('Downloading...${(data! * 100).toInt()}%')
|
||||||
|
: Text('$data Mbs downloaded')
|
||||||
|
: const Text("Downloading (no progress available)...")
|
||||||
|
: const Text('Waiting for download to start'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class DownloadProgressBar extends StatelessWidget {
|
||||||
|
const DownloadProgressBar({
|
||||||
|
Key? key,
|
||||||
|
required this.downloadFinished,
|
||||||
|
required this.data,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final bool downloadFinished;
|
||||||
|
final double? data;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 200,
|
||||||
|
child: LinearProgressIndicator(
|
||||||
|
value: downloadFinished ? 1 : data,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue