mod: 用户信息渲染、退出登录
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/pages/home/view.dart';
|
||||
import 'package:pilipala/pages/hot/view.dart';
|
||||
import 'package:pilipala/pages/mine/view.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
class MainController extends GetxController {
|
||||
List<Widget> pages = <Widget>[
|
||||
@ -11,7 +14,7 @@ class MainController extends GetxController {
|
||||
const HotPage(),
|
||||
const MinePage(),
|
||||
];
|
||||
List navigationBars = [
|
||||
RxList navigationBars = [
|
||||
{
|
||||
// 'icon': const Icon(Icons.home_outlined),
|
||||
// 'selectedIcon': const Icon(Icons.home),
|
||||
@ -51,5 +54,33 @@ class MainController extends GetxController {
|
||||
),
|
||||
'label': "我的",
|
||||
}
|
||||
];
|
||||
].obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
readuUserFace();
|
||||
}
|
||||
|
||||
// 设置头像
|
||||
readuUserFace() async {
|
||||
Box user = GStrorage.user;
|
||||
if (user.get(UserBoxKey.userFace) != null) {
|
||||
navigationBars.last['icon'] =
|
||||
navigationBars.last['selectedIcon'] = NetworkImgLayer(
|
||||
width: 25,
|
||||
height: 25,
|
||||
type: 'avatar',
|
||||
src: user.get(UserBoxKey.userFace),
|
||||
);
|
||||
navigationBars.last['label'] = '我';
|
||||
}
|
||||
}
|
||||
|
||||
// 重置
|
||||
resetLast() {
|
||||
navigationBars.last['icon'] = const Icon(Icons.person_outline);
|
||||
navigationBars.last['selectedIcon'] = const Icon(Icons.person);
|
||||
navigationBars.last['label'] = '我的';
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
late AnimationController? _animationController;
|
||||
late Animation<double>? _fadeAnimation;
|
||||
late Animation<double>? _slideAnimation;
|
||||
int selectedIndex = 0;
|
||||
int selectedIndex = 2;
|
||||
int? _lastSelectTime; //上次点击时间
|
||||
|
||||
@override
|
||||
@ -111,17 +111,19 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: NavigationBar(
|
||||
elevation: 1,
|
||||
destinations: _mainController.navigationBars.map((e) {
|
||||
return NavigationDestination(
|
||||
icon: e['icon'],
|
||||
selectedIcon: e['selectedIcon'],
|
||||
label: e['label'],
|
||||
);
|
||||
}).toList(),
|
||||
selectedIndex: selectedIndex,
|
||||
onDestinationSelected: (value) => setIndex(value),
|
||||
bottomNavigationBar: Obx(
|
||||
() => NavigationBar(
|
||||
elevation: 1,
|
||||
destinations: _mainController.navigationBars.map((e) {
|
||||
return NavigationDestination(
|
||||
icon: e['icon'],
|
||||
selectedIcon: e['selectedIcon'],
|
||||
label: e['label'],
|
||||
);
|
||||
}).toList(),
|
||||
selectedIndex: selectedIndex,
|
||||
onDestinationSelected: (value) => setIndex(value),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user