home_view.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 DefaultTabController(
  19. initialIndex: 1,
  20. length: _tabElems.length,
  21. child: Scaffold(
  22. appBar: HomeAppBar(
  23. tab:
  24. TabBar(
  25. tabs: _tabElems.map((e) => Tab(text: e.title)).toList(),
  26. labelColor: Colors.white,
  27. unselectedLabelColor: Colors.white,
  28. indicatorSize: TabBarIndicatorSize.tab,
  29. indicatorPadding: const EdgeInsets.only(bottom: 0),
  30. indicator: CustomTabIndicator(),
  31. dividerColor: Colors.transparent
  32. ),
  33. ),
  34. body: Container(
  35. decoration: const BoxDecoration(image: DecorationImage(image: AssetImage(Assets.imagesBkCommonPage), fit: BoxFit.fill)),
  36. child: TabBarView(
  37. physics: const NeverScrollableScrollPhysics(),
  38. children: _tabElems.map((e) => e.child).toList(),
  39. )
  40. ) ,
  41. ));
  42. }
  43. }
  44. final _tabElems = [
  45. _TabElem(title: '设置', child: const SizedBox()),
  46. _TabElem(title: '地图', child: const MapPage()),
  47. _TabElem(title: '场控', child: const FieldControlPage()),
  48. _TabElem(title: '用户管理', child: const UserManagePage()),
  49. _TabElem(title: '个人排名', child: const PersonalRankPage()),
  50. _TabElem(title: '分组排名', child: const SizedBox()),
  51. _TabElem(title: '数据详情', child: const DataDetailPage()),
  52. ];
  53. class _TabElem {
  54. _TabElem({required this.title, required this.child});
  55. final String title;
  56. final Widget child;
  57. }
  58. class CustomTabIndicator extends Decoration {
  59. @override
  60. BoxPainter createBoxPainter([VoidCallback? onChanged]) {
  61. return _CustomPainter(this, onChanged!);
  62. }
  63. }
  64. class _CustomPainter extends BoxPainter {
  65. final CustomTabIndicator decoration;
  66. _CustomPainter(this.decoration, VoidCallback onChanged)
  67. : super(onChanged);
  68. @override
  69. void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
  70. final size = configuration.size;
  71. assert(size != null);
  72. final Paint paint = Paint();
  73. paint.color = const Color(0xff003656);
  74. paint.style = PaintingStyle.fill;
  75. final path = Path();
  76. final rect = offset & size!;
  77. path.moveTo(rect.center.dx - 12 , rect.bottom);
  78. path .lineTo(rect.center.dx + 12, rect.bottom);
  79. path.lineTo(rect.center.dx, rect.height - 12);
  80. path.close();
  81. canvas.drawPath(path, paint);
  82. }
  83. }