home_view.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'package:track_common/widget/prelude.dart';
  2. import 'app_bar.dart';
  3. import 'home_controller.dart';
  4. class HomeView extends GetView<HomeController> {
  5. const HomeView({super.key});
  6. static const name = '/HomeView';
  7. @override
  8. Widget build(BuildContext context) {
  9. return Scaffold(
  10. appBar: HomeAppBar(
  11. tab: TabBar(
  12. controller: controller.tabController,
  13. tabs: controller.tabs.map((e) => Tab(text: e.title)).toList(),
  14. labelColor: Colors.white,
  15. unselectedLabelColor: Colors.white,
  16. indicatorSize: TabBarIndicatorSize.tab,
  17. indicatorPadding: const EdgeInsets.only(bottom: 0),
  18. indicator: CustomTabIndicator(),
  19. dividerColor: Colors.transparent),
  20. ),
  21. body: Container(
  22. decoration: const BoxDecoration(
  23. image: DecorationImage(
  24. image:
  25. AssetImage(Assets.imagesBkCommonPage, package: package),
  26. fit: BoxFit.fill)),
  27. child: TabBarView(
  28. controller: controller.tabController,
  29. physics: const NeverScrollableScrollPhysics(),
  30. children: controller.tabs.map((e) => e.builder()).toList(),
  31. )),
  32. );
  33. }
  34. }
  35. class CustomTabIndicator extends Decoration {
  36. @override
  37. BoxPainter createBoxPainter([VoidCallback? onChanged]) {
  38. return _CustomPainter(this, onChanged!);
  39. }
  40. }
  41. class _CustomPainter extends BoxPainter {
  42. final CustomTabIndicator decoration;
  43. _CustomPainter(this.decoration, VoidCallback onChanged) : super(onChanged);
  44. @override
  45. void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
  46. final size = configuration.size;
  47. assert(size != null);
  48. final Paint paint = Paint();
  49. paint.color = const Color(0xff003656);
  50. paint.style = PaintingStyle.fill;
  51. final path = Path();
  52. final rect = offset & size!;
  53. path.moveTo(rect.center.dx - 12, rect.bottom);
  54. path.lineTo(rect.center.dx + 12, rect.bottom);
  55. path.lineTo(rect.center.dx, rect.height - 12);
  56. path.close();
  57. canvas.drawPath(path, paint);
  58. }
  59. }