增加若干基础页面
This commit is contained in:
6
lib/pages/tab/index.dart
Normal file
6
lib/pages/tab/index.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
library tab;
|
||||
|
||||
export './tab_logic.dart';
|
||||
export './tab_state.dart';
|
||||
export './tab_view.dart';
|
||||
export './tab_binding.dart';
|
||||
14
lib/pages/tab/tab_binding.dart
Normal file
14
lib/pages/tab/tab_binding.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter_jdt_store/pages/layout/home/index.dart';
|
||||
import 'package:flutter_jdt_store/pages/layout/user/index.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'tab_logic.dart';
|
||||
|
||||
class TabBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => TabLogic());
|
||||
Get.lazyPut(() => HomeLogic());
|
||||
Get.lazyPut(() => UserLogic());
|
||||
}
|
||||
}
|
||||
48
lib/pages/tab/tab_logic.dart
Normal file
48
lib/pages/tab/tab_logic.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../global.dart';
|
||||
import 'tab_state.dart';
|
||||
|
||||
class TabLogic extends GetxController {
|
||||
final TabState state = TabState();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
state.pageController = PageController(initialPage: state.currentPage);
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
state.pageController!.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
handlePageChanged(int page) {
|
||||
state.currentPage = page;
|
||||
update();
|
||||
}
|
||||
|
||||
handleNavBarTap(int index) {
|
||||
if (index == state.currentPage) return;
|
||||
if (Global.isOfflineLogin && index != 0) {
|
||||
Get.toNamed('/tab');
|
||||
return;
|
||||
}
|
||||
state.pageController!.jumpToPage(index);
|
||||
}
|
||||
}
|
||||
10
lib/pages/tab/tab_state.dart
Normal file
10
lib/pages/tab/tab_state.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class TabState {
|
||||
late int currentPage;
|
||||
PageController? pageController;
|
||||
TabState() {
|
||||
///Initialize variables
|
||||
currentPage = 0;
|
||||
}
|
||||
}
|
||||
89
lib/pages/tab/tab_view.dart
Normal file
89
lib/pages/tab/tab_view.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../layout/home/index.dart';
|
||||
import '../layout/user/index.dart';
|
||||
import 'tab_logic.dart';
|
||||
|
||||
class TabPage extends StatelessWidget {
|
||||
const TabPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final logic = Get.find<TabLogic>();
|
||||
final state = Get.find<TabLogic>().state;
|
||||
|
||||
/// 内容页
|
||||
Widget buildPageView() {
|
||||
return GetBuilder<TabLogic>(builder: (_) {
|
||||
return PageView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: state.pageController,
|
||||
onPageChanged: logic.handlePageChanged,
|
||||
children: const <Widget>[
|
||||
HomePage(),
|
||||
UserPage(),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
List<BottomNavigationBarItem> createBottomItems() {
|
||||
return <BottomNavigationBarItem>[
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(
|
||||
TDIcons.dashboard,
|
||||
color: Colors.grey,
|
||||
),
|
||||
activeIcon: Icon(
|
||||
TDIcons.dashboard,
|
||||
color: Color.fromRGBO(0, 82, 217, 1),
|
||||
),
|
||||
label: "工作台",
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(
|
||||
TDIcons.desktop,
|
||||
color: Colors.grey,
|
||||
),
|
||||
activeIcon: Icon(
|
||||
TDIcons.desktop,
|
||||
color: Color.fromRGBO(0, 82, 217, 1),
|
||||
),
|
||||
label: "商家中心",
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// 底部导航
|
||||
Widget buildBottomNavigationBar() {
|
||||
List<BottomNavigationBarItem> bottomItems = createBottomItems();
|
||||
return GetBuilder<TabLogic>(builder: (_) {
|
||||
return BottomNavigationBar(
|
||||
items: bottomItems,
|
||||
currentIndex: state.currentPage,
|
||||
backgroundColor: Colors.white,
|
||||
unselectedItemColor: Colors.grey,
|
||||
selectedItemColor: const Color.fromRGBO(0, 82, 217, 1),
|
||||
type: BottomNavigationBarType.fixed,
|
||||
onTap: logic.handleNavBarTap,
|
||||
selectedFontSize: 10.sp,
|
||||
unselectedFontSize: 10.sp,
|
||||
iconSize: 32.w,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (_) {
|
||||
ToolFn().isExit();
|
||||
},
|
||||
child: Scaffold(
|
||||
body: buildPageView(),
|
||||
bottomNavigationBar: buildBottomNavigationBar(),
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user