完成值绑定

This commit is contained in:
bluesea 2024-05-11 14:16:32 +08:00
parent d4b7e2446b
commit 23c509d556
2 changed files with 12 additions and 14 deletions

View File

@ -1,15 +1,11 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
class TabbarPageController extends GetxController { class TabbarPageController extends GetxController {
// TabbarPageController var currentIdenx = 0.obs;
@override
void onInit(){
super.onInit();
}
void onItemTapped(int index) { void onItemTapped(int index) {
currentIdenx.value = index;
} }
} }

View File

@ -6,25 +6,27 @@ import 'package:wallpaper/pages/homePage/homePage_view.dart';
import 'package:wallpaper/pages/downloadpage/downloadpage_view.dart'; import 'package:wallpaper/pages/downloadpage/downloadpage_view.dart';
import 'package:wallpaper/pages/collectionpage/collectionpage_view.dart'; import 'package:wallpaper/pages/collectionpage/collectionpage_view.dart';
import 'package:wallpaper/pages/mypage/mypage_view.dart'; import 'package:wallpaper/pages/mypage/mypage_view.dart';
class TabbarPageView extends GetView {
const TabbarPageView({super.key}); import 'tabarpage_controller.dart';
class TabbarPageView extends GetView <TabbarPageController>{
const TabbarPageView({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<Widget> childPageList = getPages(); final List<Widget> childPageList = getPages();
final List<BottomNavigationBarItem> listBarItems = getTabarItem(); final List<BottomNavigationBarItem> listBarItems = getTabarItem();
return Scaffold( return Scaffold(
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar:Obx(() => BottomNavigationBar(
items: listBarItems, items: listBarItems,
unselectedItemColor:Colors.grey, unselectedItemColor:Colors.grey,
selectedItemColor: Colors.orange, selectedItemColor: Colors.orange,
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
selectedFontSize: 14, selectedFontSize: 14,
unselectedFontSize: 14, unselectedFontSize: 14,
currentIndex: 0, currentIndex: controller.currentIdenx.value,
onTap: controller.onItemTapped,
), )),
body: childPageList[0], body: childPageList[0],
); );
} }
@ -48,7 +50,7 @@ class TabbarPageView extends GetView {
//tabitem对应控制器视图, //tabitem对应控制器视图,
List<Widget> getPages(){ List<Widget> getPages(){
return [HomePageView(),CollectionPageView(),DownloadPageView(),MyPageView(),]; return [const HomePageView(),const CollectionPageView(),const DownloadPageView(),const MyPageView(),];
} }