main_page.dart 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import 'package:abroad_location/base/base_page.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/src/widgets/framework.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:get/get.dart';
  7. import 'package:get/get_core/src/get_main.dart';
  8. import '../../resource/colors.gen.dart';
  9. import '../../router/app_pages.dart';
  10. import 'main_controller.dart';
  11. class MainPage extends BasePage<MainController> {
  12. const MainPage({super.key});
  13. static start() {
  14. Get.offAllNamed(RoutePath.mainTab);
  15. }
  16. @override
  17. bool immersive() {
  18. return true;
  19. }
  20. @override
  21. Widget buildBody(BuildContext context) {
  22. return DefaultTabController(
  23. initialIndex: controller.currentIndex,
  24. length: controller.tabData.length,
  25. child: Scaffold(
  26. body: buildTabBarView(), bottomNavigationBar: buildBottomBar()),
  27. );
  28. }
  29. Widget buildBottomBar() {
  30. return Container(
  31. decoration: BoxDecoration(
  32. color: ColorName.white,
  33. boxShadow: [
  34. BoxShadow(
  35. color: ColorName.black5.withOpacity(0.03), // 阴影颜色
  36. blurRadius: 16, // 阴影模糊半径
  37. spreadRadius: 2, // 阴影扩展半径
  38. offset: const Offset(0, 0), // 阴影位置,向上偏移
  39. ),
  40. ],
  41. ),
  42. child: Row(children: [
  43. for (int i = 0; i < controller.tabData.length; i++)
  44. tabItem(controller.tabData[i], i)
  45. ]),
  46. );
  47. }
  48. Widget tabItem(TabData tabData, int index) {
  49. return Expanded(
  50. child: Container(
  51. padding: EdgeInsets.only(top: 9.w, bottom: 15.w),
  52. child: Builder(builder: (context) {
  53. return GestureDetector(
  54. onTap: () {
  55. DefaultTabController.of(context).animateTo(index);
  56. controller.onTabClick(index);
  57. },
  58. child: Obx(() {
  59. return Image(
  60. image: controller.currentIndex == index
  61. ? tabData.selectIcon
  62. : tabData.unSelectIcon,
  63. width: 32.w,
  64. height: 32.w);
  65. }),
  66. );
  67. }),
  68. ));
  69. }
  70. Widget buildTabBarView() {
  71. return TabBarView(children: [
  72. for (int i = 0; i < controller.tabData.length; i++)
  73. controller.tabData[i].page
  74. ]);
  75. }
  76. }