mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 12:57:24 +00:00
improve login and logout
This commit is contained in:
@@ -63,13 +63,16 @@ class _Appdata {
|
|||||||
Future<void> readData() async {
|
Future<void> readData() async {
|
||||||
final file = File("${App.dataPath}/account.json");
|
final file = File("${App.dataPath}/account.json");
|
||||||
if (file.existsSync()) {
|
if (file.existsSync()) {
|
||||||
account = Account.fromJson(jsonDecode(await file.readAsString()));
|
var json = jsonDecode(await file.readAsString());
|
||||||
|
if(json != null) {
|
||||||
|
account = Account.fromJson(json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final settingsFile = File("${App.dataPath}/settings.json");
|
final settingsFile = File("${App.dataPath}/settings.json");
|
||||||
if (settingsFile.existsSync()) {
|
if (settingsFile.existsSync()) {
|
||||||
var json = jsonDecode(await settingsFile.readAsString());
|
var json = jsonDecode(await settingsFile.readAsString());
|
||||||
for (var key in json.keys) {
|
for (var key in json.keys) {
|
||||||
if(json[key] != null) {
|
if (json[key] != null) {
|
||||||
settings[key] = json[key];
|
settings[key] = json[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
96
lib/components/button.dart
Normal file
96
lib/components/button.dart
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
|
import 'package:pixes/foundation/app.dart';
|
||||||
|
|
||||||
|
abstract class BaseButton extends StatelessWidget {
|
||||||
|
const BaseButton({this.enabled = true, this.isLoading = false, super.key});
|
||||||
|
|
||||||
|
final bool enabled;
|
||||||
|
|
||||||
|
final bool isLoading;
|
||||||
|
|
||||||
|
Widget buildNormal(BuildContext context);
|
||||||
|
|
||||||
|
Widget buildLoading(BuildContext context);
|
||||||
|
|
||||||
|
Widget buildDisabled(BuildContext context);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (isLoading) {
|
||||||
|
return buildLoading(context);
|
||||||
|
} else if (enabled) {
|
||||||
|
return buildNormal(context);
|
||||||
|
} else {
|
||||||
|
return buildDisabled(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FluentButton extends BaseButton {
|
||||||
|
const FluentButton({
|
||||||
|
required this.onPressed,
|
||||||
|
required this.child,
|
||||||
|
this.width,
|
||||||
|
super.enabled,
|
||||||
|
super.isLoading,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final void Function() onPressed;
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
final double? width;
|
||||||
|
|
||||||
|
static const _kFluentButtonPadding = 24;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget buildNormal(BuildContext context) {
|
||||||
|
Widget child = this.child;
|
||||||
|
if (width != null) {
|
||||||
|
child = child.fixWidth(width! - _kFluentButtonPadding);
|
||||||
|
}
|
||||||
|
return FilledButton(
|
||||||
|
onPressed: onPressed,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget buildLoading(BuildContext context) {
|
||||||
|
Widget child = Center(
|
||||||
|
child: const ProgressRing(
|
||||||
|
strokeWidth: 1.6,
|
||||||
|
).fixWidth(14).fixHeight(14),
|
||||||
|
);
|
||||||
|
if (width != null) {
|
||||||
|
child = child.fixWidth(width!);
|
||||||
|
}
|
||||||
|
return Container(
|
||||||
|
height: 26,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: FluentTheme.of(context).inactiveBackgroundColor,
|
||||||
|
borderRadius: BorderRadius.circular(4)),
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget buildDisabled(BuildContext context) {
|
||||||
|
Widget child = Center(
|
||||||
|
child: this.child,
|
||||||
|
);
|
||||||
|
if (width != null) {
|
||||||
|
child = child.fixWidth(width!);
|
||||||
|
}
|
||||||
|
return Center(
|
||||||
|
child: Container(
|
||||||
|
height: 26,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: FluentTheme.of(context).inactiveBackgroundColor,
|
||||||
|
borderRadius: BorderRadius.circular(4)),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
|
import 'package:pixes/components/button.dart';
|
||||||
import 'package:pixes/foundation/app.dart';
|
import 'package:pixes/foundation/app.dart';
|
||||||
import 'package:pixes/network/network.dart';
|
import 'package:pixes/network/network.dart';
|
||||||
import 'package:pixes/pages/webview_page.dart';
|
import 'package:pixes/pages/webview_page.dart';
|
||||||
@@ -56,22 +57,11 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
if (checked)
|
FluentButton(
|
||||||
FilledButton(
|
onPressed: onContinue,
|
||||||
onPressed: onContinue,
|
enabled: checked,
|
||||||
child: Text("Continue".tl),
|
width: 96,
|
||||||
)
|
child: Text("Continue".tl),
|
||||||
else
|
|
||||||
Container(
|
|
||||||
height: 28,
|
|
||||||
width: 78,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: FluentTheme.of(context)
|
|
||||||
.inactiveBackgroundColor,
|
|
||||||
borderRadius: BorderRadius.circular(4)),
|
|
||||||
child: Center(
|
|
||||||
child: Text("Continue".tl),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 16,
|
height: 16,
|
||||||
|
@@ -88,6 +88,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
child: Text('Continue'.tl),
|
child: Text('Continue'.tl),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
appdata.account = null;
|
appdata.account = null;
|
||||||
|
appdata.writeData();
|
||||||
App.rootNavigatorKey.currentState!.pushAndRemoveUntil(
|
App.rootNavigatorKey.currentState!.pushAndRemoveUntil(
|
||||||
AppPageRoute(
|
AppPageRoute(
|
||||||
builder: (context) => const MainPage()),
|
builder: (context) => const MainPage()),
|
||||||
|
Reference in New Issue
Block a user