初始化提交
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_home/controllers/kr_home_controller.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_invite/controllers/kr_invite_controller.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_login/controllers/kr_login_controller.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_statistics/controllers/kr_statistics_controller.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_user_info/controllers/kr_user_info_controller.dart';
|
||||
|
||||
import '../controllers/kr_main_controller.dart';
|
||||
|
||||
class KRMainBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<KRMainController>(
|
||||
() => KRMainController(),
|
||||
);
|
||||
|
||||
Get.lazyPut(() => KRHomeController());
|
||||
Get.lazyPut(() => KRLoginController());
|
||||
|
||||
Get.lazyPut(() => KRInviteController());
|
||||
Get.lazyPut(() => KRUserInfoController());
|
||||
Get.lazyPut(() => KRStatisticsController());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_home/views/kr_home_view.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_invite/views/kr_invite_view.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_statistics/views/kr_statistics_view.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_user_info/views/kr_user_info_view.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_user_info/controllers/kr_user_info_controller.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/kr_keep_alive_wrapper.dart';
|
||||
|
||||
import '../../../widgets/kr_language_switch_dialog.dart';
|
||||
|
||||
enum MainRoutes {
|
||||
INDEX(0, '首页'),
|
||||
DYNAMICS(1, '看看'),
|
||||
TOTALLETTER(2, '邮筒'),
|
||||
MESSAGELIST(3, '消息'),
|
||||
USER_CENTER(4, '我的');
|
||||
|
||||
final int i;
|
||||
final String title;
|
||||
|
||||
const MainRoutes(this.i, this.title);
|
||||
}
|
||||
|
||||
class KRMainController extends GetxController {
|
||||
static KRMainController get to => Get.find();
|
||||
DateTime? lastPopTime;
|
||||
var kr_currentIndex = 0.obs;
|
||||
final List<Widget> widgets = [
|
||||
KRKeepAliveWrapper(KRHomeView()),
|
||||
KRKeepAliveWrapper(KRInviteView()),
|
||||
KRKeepAliveWrapper(KRStatisticsView()),
|
||||
KRKeepAliveWrapper(KRUserInfoView()),
|
||||
];
|
||||
|
||||
/// 分页控制器
|
||||
PageController pageController = PageController(keepPage: true);
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
/// 到哪个页面,具体传值查看MainRoutes的枚举类
|
||||
kr_setPage(int index) {
|
||||
kr_currentIndex.value = index;
|
||||
pageController.jumpToPage(index);
|
||||
|
||||
// 监控页面进入
|
||||
if (index == MainRoutes.USER_CENTER.i) {
|
||||
final userInfoController = Get.find<KRUserInfoController>();
|
||||
userInfoController.kr_onPageEnter();
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_login/views/kr_login_view.dart';
|
||||
import 'package:kaer_with_panels/app/modules/kr_main/views/kr_tabbar_view.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/kr_local_image.dart';
|
||||
|
||||
import '../controllers/kr_main_controller.dart';
|
||||
|
||||
class KRMainView extends GetView<KRMainController> {
|
||||
const KRMainView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context); // 获取当前主题
|
||||
return Scaffold(
|
||||
// 根据下标显示哪个页面
|
||||
body: GetBuilder<KRMainController>(builder: (mc) {
|
||||
return PageView(
|
||||
children: mc.widgets,
|
||||
controller: controller.pageController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
);
|
||||
}),
|
||||
|
||||
bottomNavigationBar: Obx(
|
||||
() => KRCustomBottomNavBar(
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
currentIndex: controller.kr_currentIndex.value,
|
||||
onTap: (i) => controller.kr_setPage(i),
|
||||
items: [
|
||||
KRCustomBottomNavBarItem(
|
||||
imageName: "tab_home_n",
|
||||
activeImageName: "tab_home_s",
|
||||
),
|
||||
KRCustomBottomNavBarItem(
|
||||
imageName: "tab_invite_n",
|
||||
activeImageName: "tab_invite_s",
|
||||
),
|
||||
KRCustomBottomNavBarItem(
|
||||
imageName: "tab_statistics_n",
|
||||
activeImageName: "tab_statistics_s",
|
||||
),
|
||||
KRCustomBottomNavBarItem(
|
||||
imageName: "tab_my_n",
|
||||
activeImageName: "tab_my_s",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/kr_local_image.dart';
|
||||
|
||||
/// 用来描述底部导航栏的每一项
|
||||
class KRCustomBottomNavBarItem {
|
||||
/// 未选中时的图片名称
|
||||
final String imageName;
|
||||
|
||||
/// 选中时的图片名称(可选,不传则用同一张 imageName)
|
||||
final String? activeImageName;
|
||||
|
||||
/// 标签(可选)
|
||||
final String? label;
|
||||
|
||||
KRCustomBottomNavBarItem({
|
||||
required this.imageName,
|
||||
this.activeImageName,
|
||||
this.label,
|
||||
});
|
||||
}
|
||||
|
||||
class KRCustomBottomNavBar extends StatelessWidget {
|
||||
/// 传入当前选中的索引
|
||||
final int currentIndex;
|
||||
|
||||
/// 导航栏的各个条目信息
|
||||
final List<KRCustomBottomNavBarItem> items;
|
||||
|
||||
/// 点击某项时的回调
|
||||
final ValueChanged<int> onTap;
|
||||
|
||||
/// 背景色
|
||||
final Color backgroundColor;
|
||||
|
||||
/// 选中时 图标/文字 颜色
|
||||
final Color selectedColor;
|
||||
|
||||
/// 未选中时 图标/文字 颜色
|
||||
final Color unselectedColor;
|
||||
|
||||
/// 导航栏高度(不含安全区额外高度)
|
||||
final double height;
|
||||
|
||||
/// 是否在内部自动使用 SafeArea
|
||||
final bool useSafeArea;
|
||||
|
||||
const KRCustomBottomNavBar({
|
||||
Key? key,
|
||||
required this.currentIndex,
|
||||
required this.items,
|
||||
required this.onTap,
|
||||
this.backgroundColor = Colors.white,
|
||||
this.selectedColor = Colors.blue,
|
||||
this.unselectedColor = Colors.grey,
|
||||
this.height = 56.0,
|
||||
this.useSafeArea = true,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(items.isNotEmpty, 'The items list cannot be empty.');
|
||||
assert(currentIndex >= 0 && currentIndex < items.length,
|
||||
'The currentIndex must be within the bounds of the items list.');
|
||||
|
||||
Widget child = Container(
|
||||
color: backgroundColor,
|
||||
height: height,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: List.generate(items.length, (index) {
|
||||
final item = items[index];
|
||||
final bool isSelected = (index == currentIndex);
|
||||
|
||||
final iconName = isSelected
|
||||
? (item.activeImageName ?? item.imageName)
|
||||
: item.imageName;
|
||||
|
||||
final textColor = isSelected ? selectedColor : unselectedColor;
|
||||
|
||||
return Expanded(
|
||||
child: InkWell(
|
||||
onTap: () => onTap(index),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
KrLocalImage(
|
||||
imageName: iconName,
|
||||
height: 24,
|
||||
width: 24,
|
||||
),
|
||||
if (item.label != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
item.label!,
|
||||
style: TextStyle(color: textColor, fontSize: 12),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
// 使用 SafeArea 包裹,避免底部被手势栏遮挡
|
||||
return useSafeArea ? SafeArea(child: child) : child;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user