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/option.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 {
|
||||
const Downloader({
|
||||
|
|
@ -89,7 +92,8 @@ class _DownloaderState extends State<Downloader> {
|
|||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
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,
|
||||
),
|
||||
body: Column(
|
||||
|
|
@ -102,30 +106,14 @@ class _DownloaderState extends State<Downloader> {
|
|||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: _downloadFinished
|
||||
? const Text('Download finished.')
|
||||
: 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'),
|
||||
DownloadLabel(
|
||||
downloadFinished: _downloadFinished,
|
||||
data: snapshot.hasData ? snapshot.data : null,
|
||||
downloader: widget.option!.downloader,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
child: LinearProgressIndicator(
|
||||
value: _downloadFinished
|
||||
? 1
|
||||
: snapshot.hasData
|
||||
? data
|
||||
: null,
|
||||
),
|
||||
),
|
||||
DownloadProgressBar(
|
||||
downloadFinished: _downloadFinished,
|
||||
data: snapshot.hasData ? data : null,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 32),
|
||||
|
|
@ -136,20 +124,8 @@ class _DownloaderState extends State<Downloader> {
|
|||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: _downloadFinished
|
||||
? () {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
: null,
|
||||
child: _downloadFinished ? const Text('Dimiss') : const Text('Cancel'))
|
||||
],
|
||||
),
|
||||
CancelDismissButton(
|
||||
downloadFinished: _downloadFinished,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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