button_group.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import 'package:fis_measure/interfaces/process/standard_line/calibration.dart';
  2. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  3. import 'package:fis_measure/process/workspace/measure_handler.dart';
  4. import 'package:fis_ui/index.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:get/get.dart';
  7. class ButtonGroup extends StatefulWidget {
  8. final VoidCallback capturePng;
  9. const ButtonGroup({
  10. Key? key,
  11. required this.capturePng,
  12. }) : super(key: key);
  13. @override
  14. State<ButtonGroup> createState() => _ButtonGroupState();
  15. }
  16. class _ButtonGroupState extends State<ButtonGroup> {
  17. double _width = 0;
  18. bool _isExpanded = false;
  19. final _key = GlobalKey();
  20. final application = Get.find<IApplication>();
  21. late final measureHandler = Get.find<MeasureHandler>();
  22. Future<bool> _showList() async {
  23. await Future.delayed(const Duration(milliseconds: 300));
  24. return true;
  25. }
  26. /// TODO 翻译
  27. @override
  28. Widget build(BuildContext context) {
  29. return Row(
  30. mainAxisAlignment: MainAxisAlignment.end,
  31. children: [
  32. InkWell(
  33. onTap: () {},
  34. onHover: (isHover) {
  35. if (!isHover) {
  36. setState(() {
  37. _width = 0;
  38. _isExpanded = isHover;
  39. });
  40. } else {
  41. setState(() {
  42. application.isThirdPart ? _width = 270 : _width = 220;
  43. _isExpanded = isHover;
  44. });
  45. }
  46. },
  47. child: AnimatedContainer(
  48. duration: const Duration(milliseconds: 300),
  49. padding: const EdgeInsets.only(
  50. top: 5,
  51. bottom: 5,
  52. left: 15,
  53. ),
  54. decoration: BoxDecoration(
  55. borderRadius: const BorderRadius.only(
  56. topLeft: Radius.circular(4),
  57. bottomLeft: Radius.circular(4),
  58. ),
  59. color: Colors.grey.withOpacity(0.6),
  60. ),
  61. width: _width,
  62. height: 60,
  63. child: _isExpanded
  64. ? FutureBuilder(
  65. future: _showList(),
  66. builder: (context, snapshot) {
  67. if (!snapshot.hasData) {
  68. return const SizedBox();
  69. }
  70. return Row(
  71. children: [
  72. _buildTitleButton(FIcons.fis_quash, '撤销',
  73. () => application.undoRecord()),
  74. _buildTitleButton(FIcons.fis_purge, '清除',
  75. () => application.clearRecords()),
  76. _buildTitleButton(FIcons.fis_full_screen, '全屏', () {
  77. measureHandler.fullScreenState =
  78. !measureHandler.fullScreenState;
  79. }),
  80. _buildTitleButton(
  81. FIcons.fis_save, '保存', widget.capturePng),
  82. _buildTitleButton(
  83. FIcons.fis_share,
  84. '分享',
  85. () {
  86. print('分享');
  87. },
  88. ),
  89. application.isThirdPart
  90. ? _buildTitleButton(
  91. FIcons.device,
  92. '校准线',
  93. () {
  94. Get.find<
  95. IStandardLineCalibrationController>()
  96. .enterEditMode();
  97. },
  98. )
  99. : const SizedBox(),
  100. ],
  101. );
  102. })
  103. : const SizedBox(),
  104. ),
  105. ),
  106. InkWell(
  107. onTap: () {},
  108. onHover: (isHover) {
  109. if (isHover) {
  110. setState(() {
  111. application.isThirdPart ? _width = 270 : _width = 220;
  112. _isExpanded = isHover;
  113. });
  114. } else {
  115. setState(() {
  116. _width = 0;
  117. _isExpanded = isHover;
  118. });
  119. }
  120. },
  121. child: Container(
  122. height: 60,
  123. color: Colors.white,
  124. child: !_isExpanded
  125. ? const Icon(Icons.chevron_left_rounded)
  126. : const Icon(Icons.chevron_right_rounded),
  127. ),
  128. ),
  129. ],
  130. );
  131. }
  132. Widget _buildTitleButton(IconData icon, String title, Function onClick) {
  133. return Container(
  134. margin: const EdgeInsets.only(
  135. right: 10,
  136. ),
  137. child: InkWell(
  138. onTap: () => onClick.call(),
  139. child: Column(
  140. children: [
  141. Icon(
  142. icon,
  143. color: Colors.white,
  144. ),
  145. Text(
  146. title,
  147. style: const TextStyle(
  148. color: Colors.white,
  149. fontSize: 14,
  150. ),
  151. )
  152. ],
  153. ),
  154. ),
  155. );
  156. }
  157. }