Skip to content

Commit

Permalink
[+*]Add account dialog & fix home
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 20, 2023
1 parent 64484e5 commit 3308905
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 30 deletions.
22 changes: 12 additions & 10 deletions lib/io/userInfoStorage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@ import 'package:nyalcf/model/User.dart';
import 'package:nyalcf/util/FileIO.dart';

class UserInfoStorage {
static final path = FileIO.support_path;
static final _path = FileIO.support_path;

/**
* 保存数据
*/
/// 保存数据
static Future<void> save(User data) async {
final String write_data = jsonEncode(data);
await File('${await path}/session.json')
await File('${await _path}/session.json')
.writeAsString(write_data, encoding: utf8);
}

/**
* 读取数据
*/
/// 读取数据
static Future<User?> read() async {
try {
final String result =
await File('${await path}/session.json').readAsString(encoding: utf8);
final String result = await File('${await _path}/session.json')
.readAsString(encoding: utf8);
return User.fromJson(jsonDecode(result));
} catch (e) {
return null;
}
}

/// 退出登录
/// 只是删除session.json
static sigo() async {
await File('${await _path}/session.json').delete();
}
}
2 changes: 1 addition & 1 deletion lib/ui/auth/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class _LoginState extends State<Login> {
} else {
Get.snackbar(
'登陆失败',
res,
res.toString(),
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
Expand Down
8 changes: 7 additions & 1 deletion lib/ui/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ class Home extends StatelessWidget {
Text('$title - 首页', style: const TextStyle(color: Colors.white)),
backgroundColor: Colors.pink[100],
actions: AppbarActionsX(context: context).actions(),
automaticallyImplyLeading: false,
),
body: Center(
child: Container(
margin: const EdgeInsets.all(40.0),
child: Column(children: hc.w),
child: Obx(
() => ListView(
shrinkWrap: true,
children: hc.w,
),
),
),
),
floatingActionButton: FloatingActionButtonX().button());
Expand Down
50 changes: 50 additions & 0 deletions lib/ui/model/AccountDialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/io/userInfoStorage.dart';
import 'package:url_launcher/url_launcher.dart';

class AccountDialogX {
const AccountDialogX({required this.context});

final context;

Widget build() {
return SimpleDialog(
title: const Text('小可爱,喵呜?'),
children: <Widget>[
SimpleDialogOption(
child: const ListTile(
leading: Icon(Icons.transit_enterexit),
title: Text('退出登录'),
),
onPressed: () async {
try {
await UserInfoStorage.sigo();
} catch (e) {
Get.snackbar(
'发生错误',
e.toString(),
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
}
Get.toNamed('/');
}),
SimpleDialogOption(
child: const ListTile(
leading: Icon(Icons.headset),
title: Text('编辑头像'),
),
onPressed: () async {
const url = 'https://cravatar.cn';
if (!await launchUrl(Uri.parse(url))) {
const snackBar = SnackBar(
content: Text('无法打开网页,请检查设备是否存在WebView'),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
}),
],
);
}
}
22 changes: 16 additions & 6 deletions lib/ui/panel/console.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/user.dart';
import 'package:nyalcf/ui/model/AccountDialog.dart';
import 'package:nyalcf/ui/model/AppbarActions.dart';
import 'package:nyalcf/ui/model/Drawer.dart';
import 'package:nyalcf/ui/model/FloatingActionButton.dart';
Expand All @@ -21,12 +22,21 @@ class PanelConsole extends StatelessWidget {
backgroundColor: Colors.pink[100],
//automaticallyImplyLeading: false,
actions: AppbarActionsX(append: <Widget>[
Obx(() => ClipRRect(
borderRadius: BorderRadius.circular(500),
child: Image.network(
'${c.avatar}',
width: 35,
)))
Obx(() => IconButton(
onPressed: () {
showDialog(
context: context,
builder: (x) {
return AccountDialogX(context: context).build();
});
},
icon: ClipRRect(
borderRadius: BorderRadius.circular(500),
child: Image.network(
'${c.avatar}',
width: 35,
),
))),
], context: context)
.actions(),
),
Expand Down
22 changes: 16 additions & 6 deletions lib/ui/panel/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/dpanel.dart';
import 'package:nyalcf/controller/user.dart';
import 'package:nyalcf/ui/model/AccountDialog.dart';
import 'package:nyalcf/ui/model/Drawer.dart';
import 'package:nyalcf/ui/model/FloatingActionButton.dart';
import 'package:url_launcher/url_launcher.dart';
Expand All @@ -29,12 +30,21 @@ class PanelHome extends StatelessWidget {
backgroundColor: Colors.pink[100],
//automaticallyImplyLeading: false,
actions: AppbarActionsX(append: <Widget>[
Obx(() => ClipRRect(
borderRadius: BorderRadius.circular(500),
child: Image.network(
'${c.avatar}',
width: 35,
)))
Obx(() => IconButton(
onPressed: () {
showDialog(
context: context,
builder: (x) {
return AccountDialogX(context: context).build();
});
},
icon: ClipRRect(
borderRadius: BorderRadius.circular(500),
child: Image.network(
'${c.avatar}',
width: 35,
),
))),
], context: context)
.actions(),
),
Expand Down
22 changes: 16 additions & 6 deletions lib/ui/panel/proxies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/proxies.dart';
import 'package:nyalcf/controller/user.dart';
import 'package:nyalcf/ui/model/AccountDialog.dart';
import 'package:nyalcf/ui/model/AppbarActions.dart';
import 'package:nyalcf/ui/model/Drawer.dart';
import 'package:nyalcf/ui/model/FloatingActionButton.dart';
Expand All @@ -24,12 +25,21 @@ class PanelProxies extends StatelessWidget {
backgroundColor: Colors.pink[100],
//automaticallyImplyLeading: false,
actions: AppbarActionsX(append: <Widget>[
Obx(() => ClipRRect(
borderRadius: BorderRadius.circular(500),
child: Image.network(
'${c.avatar}',
width: 35,
)))
Obx(() => IconButton(
onPressed: () {
showDialog(
context: context,
builder: (x) {
return AccountDialogX(context: context).build();
});
},
icon: ClipRRect(
borderRadius: BorderRadius.circular(500),
child: Image.network(
'${c.avatar}',
width: 35,
),
))),
], context: context)
.actions(),
),
Expand Down

0 comments on commit 3308905

Please sign in to comment.