完成值绑定
This commit is contained in:
parent
d4b7e2446b
commit
23c509d556
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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(),];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user