home_view.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import 'package:application/view/home/user_manage/user_manage_page.dart';
  2. import 'data_detail/data_detail.dart';
  3. import 'app_bar.dart';
  4. import 'map/map_page.dart';
  5. import 'home_controller.dart';
  6. import 'package:application/widget.dart';
  7. class HomeView extends GetView<HomeController> {
  8. const HomeView({super.key});
  9. static Bindings bindings() {
  10. return BindingsBuilder(() {
  11. Get.lazyPut<HomeController>(() => HomeController());
  12. });
  13. }
  14. @override
  15. Widget build(BuildContext context) {
  16. return DefaultTabController(
  17. initialIndex: 1,
  18. length: _tabElems.length,
  19. child: Scaffold(
  20. appBar: HomeAppBar(
  21. tab:
  22. TabBar(
  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. physics: const NeverScrollableScrollPhysics(),
  36. children: _tabElems.map((e) => e.child).toList(),
  37. )
  38. ) ,
  39. ));
  40. }
  41. }
  42. final _tabElems = [
  43. _TabElem(title: '设置', child: const SizedBox()),
  44. _TabElem(title: '地图', child: const MapPage()),
  45. _TabElem(title: '用户管理', child: const UserManagePage()),
  46. _TabElem(title: '个人排名', child: const SizedBox()),
  47. _TabElem(title: '分组排名', child: const SizedBox()),
  48. _TabElem(title: '数据详情', child: const DataDetailPage()),
  49. ];
  50. class _TabElem {
  51. _TabElem({required this.title, required this.child});
  52. final String title;
  53. final Widget child;
  54. }
  55. class CustomTabIndicator extends Decoration {
  56. @override
  57. BoxPainter createBoxPainter([VoidCallback? onChanged]) {
  58. return _CustomPainter(this, onChanged!);
  59. }
  60. }
  61. class _CustomPainter extends BoxPainter {
  62. final CustomTabIndicator decoration;
  63. _CustomPainter(this.decoration, VoidCallback onChanged)
  64. : super(onChanged);
  65. @override
  66. void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
  67. final size = configuration.size;
  68. assert(size != null);
  69. final Paint paint = Paint();
  70. paint.color = const Color(0xff003656);
  71. paint.style = PaintingStyle.fill;
  72. final path = Path();
  73. final rect = offset & size!;
  74. path.moveTo(rect.center.dx - 12 , rect.bottom);
  75. path .lineTo(rect.center.dx + 12, rect.bottom);
  76. path.lineTo(rect.center.dx, rect.height - 12);
  77. path.close();
  78. canvas.drawPath(path, paint);
  79. }
  80. }