home_view.dart 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import 'package:common_pub/common_pub.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import '../../generated/assets.dart';
  5. import '../../logger.dart';
  6. import 'app_bar.dart';
  7. import 'map/map_page.dart';
  8. import 'home_controller.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: 0,
  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 SizedBox()),
  48. _TabElem(title: '个人排名', child: const SizedBox()),
  49. _TabElem(title: '分组排名', child: const SizedBox()),
  50. _TabElem(title: '数据详情', child: const SizedBox()),
  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. }