home_view.dart 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import 'personal_rank/personal_rank.dart';
  2. import 'field_control/field_control.dart';
  3. import 'user_manage/user_manage_page.dart';
  4. import 'data_detail/data_detail.dart';
  5. import 'app_bar.dart';
  6. import 'map/map_page.dart';
  7. import 'home_controller.dart';
  8. import 'package:application/widget.dart';
  9. class HomeView extends GetView<HomeController> {
  10. const HomeView({super.key});
  11. static Bindings bindings() {
  12. return BindingsBuilder(() {
  13. Get.lazyPut<HomeController>(() => HomeController());
  14. });
  15. }
  16. @override
  17. Widget build(BuildContext context) {
  18. return Scaffold(
  19. appBar: HomeAppBar(
  20. tab:
  21. TabBar(
  22. controller: controller.tabController,
  23. tabs: _tabElems.map((e) => Tab(text: e.title)).toList(),
  24. labelColor: Colors.white,
  25. unselectedLabelColor: Colors.white,
  26. indicatorSize: TabBarIndicatorSize.tab,
  27. indicatorPadding: const EdgeInsets.only(bottom: 0),
  28. indicator: CustomTabIndicator(),
  29. dividerColor: Colors.transparent
  30. ),
  31. ),
  32. body: Container(
  33. decoration: const BoxDecoration(image: DecorationImage(image: AssetImage(Assets.imagesBkCommonPage), fit: BoxFit.fill)),
  34. child: TabBarView(
  35. controller: controller.tabController,
  36. physics: const NeverScrollableScrollPhysics(),
  37. children: _tabElems.map((e) => e.child).toList(),
  38. )
  39. ) ,
  40. );
  41. }
  42. }
  43. final _tabElems = [
  44. _TabElem(title: '设置', child: const SizedBox()),
  45. _TabElem(title: '地图', child: const MapPage()),
  46. _TabElem(title: '场控', child: const FieldControlPage()),
  47. _TabElem(title: '用户管理', child: const UserManagePage()),
  48. _TabElem(title: '个人排名', child: PersonalRankPage()),
  49. _TabElem(title: '分组排名', child: const SizedBox()),
  50. _TabElem(title: '数据详情', child: const DataDetailPage()),
  51. ];
  52. class _TabElem {
  53. _TabElem({required this.title, required this.child});
  54. final String title;
  55. final Widget child;
  56. }
  57. class CustomTabIndicator extends Decoration {
  58. @override
  59. BoxPainter createBoxPainter([VoidCallback? onChanged]) {
  60. return _CustomPainter(this, onChanged!);
  61. }
  62. }
  63. class _CustomPainter extends BoxPainter {
  64. final CustomTabIndicator decoration;
  65. _CustomPainter(this.decoration, VoidCallback onChanged)
  66. : super(onChanged);
  67. @override
  68. void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
  69. final size = configuration.size;
  70. assert(size != null);
  71. final Paint paint = Paint();
  72. paint.color = const Color(0xff003656);
  73. paint.style = PaintingStyle.fill;
  74. final path = Path();
  75. final rect = offset & size!;
  76. path.moveTo(rect.center.dx - 12 , rect.bottom);
  77. path .lineTo(rect.center.dx + 12, rect.bottom);
  78. path.lineTo(rect.center.dx, rect.height - 12);
  79. path.close();
  80. canvas.drawPath(path, paint);
  81. }
  82. }