home_view.dart 2.2 KB

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