mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Add user managemant page
This commit is contained in:
@@ -13,6 +13,8 @@ class DownloadZipPage extends StatefulWidget {
|
||||
const DownloadZipPage(this.gid, {super.key});
|
||||
final int gid;
|
||||
|
||||
static const routeName = '/dialog/download/zip/:gid';
|
||||
|
||||
@override
|
||||
State<DownloadZipPage> createState() => _DownloadZipPage();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ class GalleryDetailsPage extends StatefulWidget {
|
||||
final int gid;
|
||||
final GMeta? meta;
|
||||
|
||||
static const routeName = '/dialog/gallery/details/:gid';
|
||||
|
||||
@override
|
||||
State<GalleryDetailsPage> createState() => _GalleryDetailsPage();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ class NewDownloadTaskPage extends StatefulWidget {
|
||||
final int? gid;
|
||||
final String? token;
|
||||
|
||||
static const routeName = "/dialog/new_download_task";
|
||||
|
||||
@override
|
||||
State<NewDownloadTaskPage> createState() => _NewDownloadTaskPage();
|
||||
}
|
||||
|
||||
124
lib/dialog/new_user_page.dart
Normal file
124
lib/dialog/new_user_page.dart
Normal file
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../components/labeled_checkbox.dart';
|
||||
import '../globals.dart';
|
||||
|
||||
class NewUserPage extends StatefulWidget {
|
||||
const NewUserPage({super.key});
|
||||
|
||||
static const routeName = "/dialog/user/new";
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _NewUserPage();
|
||||
}
|
||||
|
||||
class _NewUserPage extends State<NewUserPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
String _username = "";
|
||||
String _password = "";
|
||||
bool _isAdmin = false;
|
||||
bool _passwordVisible = false;
|
||||
|
||||
Widget _buildWithVecticalPadding(Widget child) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!tryInitApi(context)) {
|
||||
return Container();
|
||||
}
|
||||
if (auth.isAdmin == false) {
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
context.go("/");
|
||||
});
|
||||
return Container();
|
||||
}
|
||||
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: [
|
||||
Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Text(
|
||||
i18n.createNewUser,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: IconButton(
|
||||
onPressed: () => context.canPop()
|
||||
? context.pop()
|
||||
: context.go("/users"),
|
||||
icon: const Icon(Icons.close),
|
||||
)),
|
||||
],
|
||||
),
|
||||
_buildWithVecticalPadding(TextFormField(
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: i18n.username,
|
||||
),
|
||||
initialValue: _username,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_username = value;
|
||||
});
|
||||
},
|
||||
)),
|
||||
_buildWithVecticalPadding(TextFormField(
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText: i18n.password,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_passwordVisible
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
color: Theme.of(context).primaryColorDark,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_passwordVisible = !_passwordVisible;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
initialValue: _password,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_password = value;
|
||||
});
|
||||
},
|
||||
obscureText: !_passwordVisible,
|
||||
)),
|
||||
_buildWithVecticalPadding(LabeledCheckbox(
|
||||
value: _isAdmin,
|
||||
onChanged: (b) {
|
||||
if (b != null) {
|
||||
setState(() {
|
||||
_isAdmin = b;
|
||||
});
|
||||
}
|
||||
},
|
||||
label: Text(i18n.admin))),
|
||||
],
|
||||
))),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,8 @@ class TaskPage extends StatefulWidget {
|
||||
const TaskPage(this.id, {super.key});
|
||||
final int id;
|
||||
|
||||
static const routeName = "/dialog/task/:id";
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _TaskPage();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user