home_view.dart 2.7 KB

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