完成值绑定

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';
class TabbarPageController extends GetxController {
// TabbarPageController
@override
void onInit(){
super.onInit();
}
var currentIdenx = 0.obs;
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/collectionpage/collectionpage_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
Widget build(BuildContext context) {
final List<Widget> childPageList = getPages();
final List<BottomNavigationBarItem> listBarItems = getTabarItem();
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
bottomNavigationBar:Obx(() => BottomNavigationBar(
items: listBarItems,
unselectedItemColor:Colors.grey,
selectedItemColor: Colors.orange,
type: BottomNavigationBarType.fixed,
selectedFontSize: 14,
unselectedFontSize: 14,
currentIndex: 0,
),
currentIndex: controller.currentIdenx.value,
onTap: controller.onItemTapped,
)),
body: childPageList[0],
);
}
@ -48,7 +50,7 @@ class TabbarPageView extends GetView {
//tabitem对应控制器视图,
List<Widget> getPages(){
return [HomePageView(),CollectionPageView(),DownloadPageView(),MyPageView(),];
return [const HomePageView(),const CollectionPageView(),const DownloadPageView(),const MyPageView(),];
}