tab_button.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'package:fis_theme/theme.dart';
  2. import 'package:fis_ui/index.dart';
  3. import 'package:fis_ui/interface/active_widget.dart';
  4. import 'package:fis_ui/interface/interactive_container.dart';
  5. import 'package:flutter/material.dart';
  6. class FTabButton extends FStatefulWidget implements FActiveWidget {
  7. FTabButton({
  8. Key? key,
  9. required this.businessParent,
  10. this.name,
  11. this.tabTitle,
  12. this.index,
  13. this.activeIndex,
  14. this.onCallbackTap,
  15. this.width = 100,
  16. this.disableShadow = false,
  17. this.padding = const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
  18. this.margin = const EdgeInsets.only(right: 8),
  19. }) : super(key: key);
  20. final String? tabTitle;
  21. final int? index;
  22. late final int? activeIndex;
  23. final VoidCallback? onCallbackTap;
  24. final double width;
  25. final EdgeInsetsGeometry? padding;
  26. final EdgeInsetsGeometry? margin;
  27. final bool disableShadow;
  28. @override
  29. FState<FTabButton> createState() => _FTabButtonState();
  30. @override
  31. final FInteractiveContainer businessParent;
  32. @override
  33. final String? name;
  34. }
  35. class _FTabButtonState extends FState<FTabButton> {
  36. get isActive => widget.activeIndex == widget.index;
  37. @override
  38. FWidget build(BuildContext context) {
  39. final borderRadius = const Radius.circular(10);
  40. final textColorActive = Colors.white;
  41. return FContainer(
  42. height: 36,
  43. alignment: Alignment.center,
  44. margin: widget.margin,
  45. decoration: widget.disableShadow
  46. ? null
  47. : BoxDecoration(
  48. boxShadow: isActive
  49. ? [
  50. BoxShadow(
  51. color: Colors.black.withOpacity(0.2),
  52. blurRadius: 10,
  53. spreadRadius: 1,
  54. offset: const Offset(5, 5),
  55. )
  56. ]
  57. : []),
  58. child: FGestureDetector(
  59. businessParent: widget.businessParent,
  60. name: widget.name ?? widget.tabTitle ?? '',
  61. onTap: widget.onCallbackTap,
  62. child: FContainer(
  63. child: FCenter(
  64. child: FText(
  65. widget.tabTitle ?? '',
  66. style: isActive
  67. ? TextStyle(color: textColorActive)
  68. : TextStyle(color: Colors.black87),
  69. ),
  70. ),
  71. width: widget.width,
  72. padding: widget.padding,
  73. decoration: BoxDecoration(
  74. color: isActive ? FTheme.ins.colorScheme.primary : Colors.white,
  75. borderRadius: BorderRadius.only(
  76. topLeft: borderRadius,
  77. topRight: borderRadius,
  78. ),
  79. ),
  80. ),
  81. ),
  82. );
  83. }
  84. }