mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Add download zip page
This commit is contained in:
40
lib/dialog/dialog_page.dart
Normal file
40
lib/dialog/dialog_page.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DialogPage<T> extends Page<T> {
|
||||
final Offset? anchorPoint;
|
||||
final Color? barrierColor;
|
||||
final bool barrierDismissible;
|
||||
final String? barrierLabel;
|
||||
final bool useSafeArea;
|
||||
final CapturedThemes? themes;
|
||||
final WidgetBuilder builder;
|
||||
|
||||
const DialogPage({
|
||||
required this.builder,
|
||||
this.anchorPoint,
|
||||
this.barrierColor = Colors.black87,
|
||||
this.barrierDismissible = true,
|
||||
this.barrierLabel,
|
||||
this.useSafeArea = true,
|
||||
this.themes,
|
||||
super.key,
|
||||
super.name,
|
||||
super.arguments,
|
||||
super.restorationId,
|
||||
});
|
||||
|
||||
@override
|
||||
Route<T> createRoute(BuildContext context) => DialogRoute<T>(
|
||||
context: context,
|
||||
settings: this,
|
||||
builder: (context) => Dialog(
|
||||
child: builder(context),
|
||||
),
|
||||
anchorPoint: anchorPoint,
|
||||
barrierColor: barrierColor,
|
||||
barrierDismissible: barrierDismissible,
|
||||
barrierLabel: barrierLabel,
|
||||
useSafeArea: useSafeArea,
|
||||
themes: themes,
|
||||
);
|
||||
}
|
||||
117
lib/dialog/download_zip_page.dart
Normal file
117
lib/dialog/download_zip_page.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import '../globals.dart';
|
||||
import '../utils/download_zip.dart';
|
||||
|
||||
final _log = Logger("DownloadZipPage");
|
||||
|
||||
class DownloadZipPage extends StatefulWidget {
|
||||
const DownloadZipPage(this.gid, {Key? key}) : super(key: key);
|
||||
final int gid;
|
||||
|
||||
@override
|
||||
State<DownloadZipPage> createState() => _DownloadZipPage();
|
||||
}
|
||||
|
||||
class _DownloadZipPage extends State<DownloadZipPage> {
|
||||
bool useTitleJpn = false;
|
||||
bool exportAd = false;
|
||||
String maxLength = "";
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
@override
|
||||
void initState() {
|
||||
useTitleJpn = prefs.getBool("useTitleJpn") ?? false;
|
||||
exportAd = prefs.getBool("exportAd") ?? false;
|
||||
maxLength = prefs.getInt("maxZipFilenameLength")?.toString() ?? "";
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final i18n = AppLocalizations.of(context)!;
|
||||
final maxWidth = MediaQuery.of(context).size.width;
|
||||
return Container(
|
||||
padding: maxWidth < 400
|
||||
? const EdgeInsets.symmetric(vertical: 20, horizontal: 5)
|
||||
: const EdgeInsets.all(20),
|
||||
width: maxWidth < 810 ? null : 800,
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10)),
|
||||
child: SingleChildScrollView(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
i18n.downloadAsZip,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
))),
|
||||
IconButton(
|
||||
onPressed: () => context.canPop()
|
||||
? context.pop()
|
||||
: context.go("/gallery/${widget.gid}"),
|
||||
icon: const Icon(Icons.close),
|
||||
)
|
||||
],
|
||||
),
|
||||
CheckboxMenuButton(
|
||||
value: useTitleJpn,
|
||||
onChanged: (u) {
|
||||
if (u != null) {
|
||||
setState(() {
|
||||
useTitleJpn = u!;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text(i18n.useTitleJpn)),
|
||||
CheckboxMenuButton(
|
||||
value: exportAd,
|
||||
onChanged: (u) {
|
||||
if (u != null) {
|
||||
setState(() {
|
||||
exportAd = u!;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text(i18n.exportAd)),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: TextFormField(
|
||||
initialValue: maxLength,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly
|
||||
],
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
maxLength = v;
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: i18n.maxZipFilenameLength),
|
||||
)),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
downloadZip(widget.gid,
|
||||
jpnTitle: useTitleJpn,
|
||||
exportAd: exportAd,
|
||||
maxLength: int.tryParse(maxLength))
|
||||
.catchError((err) {
|
||||
_log.warning("Failed to download zip:", err);
|
||||
});
|
||||
context.canPop()
|
||||
? context.pop()
|
||||
: context.go("/gallery/${widget.gid}");
|
||||
},
|
||||
child: Text(i18n.download))
|
||||
],
|
||||
))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user