tab_button.dart 2.5 KB

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