view.dart 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/module/main/controller.dart';
  3. import 'package:electronic_assistant/module/main/drawer/view.dart';
  4. import 'package:electronic_assistant/resource/assets.gen.dart';
  5. import 'package:electronic_assistant/resource/colors.gen.dart';
  6. import 'package:electronic_assistant/resource/string.gen.dart';
  7. import 'package:electronic_assistant/utils/expand.dart';
  8. import 'package:electronic_assistant/utils/toast_util.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter_screenutil/flutter_screenutil.dart';
  11. import 'package:get/get.dart';
  12. import '../../data/consts/constants.dart';
  13. import '../files/view.dart';
  14. import '../home/view.dart';
  15. import 'dart:math' as math;
  16. class MainTabPage extends BasePage<MainController> {
  17. MainTabPage({super.key});
  18. final pages = [
  19. const HomePage(),
  20. const FilesPage(),
  21. ];
  22. @override
  23. Widget buildBody(BuildContext context) {
  24. return PopScope(
  25. canPop: false,
  26. onPopInvokedWithResult: (bool didPop, dynamic result) async {
  27. if (controller.scaffoldKey.currentState?.isDrawerOpen == true) {
  28. controller.closeDrawer();
  29. return;
  30. }
  31. if ((controller.lastPressedAt == null ||
  32. DateTime.now().difference(controller.lastPressedAt!) >
  33. const Duration(seconds: 2))) {
  34. controller.setLastPressedAt(DateTime.now());
  35. ToastUtil.showToast(StringName.exitAppTip.tr);
  36. } else {
  37. controller.exit();
  38. }
  39. },
  40. child: Scaffold(
  41. extendBody: true,
  42. backgroundColor: Colors.transparent,
  43. key: controller.scaffoldKey,
  44. body: Obx(() {
  45. return pages[controller.currentIndex];
  46. }),
  47. resizeToAvoidBottomInset: false,
  48. floatingActionButton: buildAIChatBtn(),
  49. floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  50. bottomNavigationBar: buildBottomAppBar(),
  51. drawerEdgeDragWidth: 0,
  52. drawer: Drawer(
  53. shape: const RoundedRectangleBorder(
  54. borderRadius: BorderRadius.zero,
  55. ),
  56. backgroundColor: "#F6F5F8".toColor(),
  57. child: const MainDrawerView(),
  58. ),
  59. ),
  60. );
  61. }
  62. @override
  63. bool immersive() {
  64. return true;
  65. }
  66. Widget buildAIChatBtn() {
  67. return GestureDetector(
  68. onTap: () {
  69. controller.onChatClick();
  70. },
  71. child: Assets.images.mainTabSecretary
  72. .image(key: controller.aiGuideKey, width: 52.w, height: 52.w));
  73. }
  74. Widget buildBottomAppBar() {
  75. return Container(
  76. decoration: BoxDecoration(
  77. boxShadow: [
  78. BoxShadow(
  79. color: ColorName.black5.withOpacity(0.05), // 阴影颜色
  80. blurRadius: 23, // 阴影模糊半径
  81. spreadRadius: 2, // 阴影扩展半径
  82. offset: const Offset(0, 0), // 阴影位置,向上偏移
  83. ),
  84. ],
  85. ),
  86. child: BottomAppBar(
  87. color: Colors.white,
  88. height: Constants.bottomBarHeight,
  89. padding: EdgeInsets.zero,
  90. shape: const CusCircularNotchedRectangle(),
  91. child: Flex(
  92. mainAxisAlignment: MainAxisAlignment.spaceAround,
  93. direction: Axis.horizontal,
  94. children: <Widget>[
  95. Expanded(
  96. flex: 1,
  97. child: bottomAppBarItem(0),
  98. ),
  99. SizedBox(
  100. width: 62.w,
  101. height: double.infinity,
  102. child: Align(
  103. alignment: const Alignment(0.0, 0.6),
  104. child: Text(StringName.mainTabAi.tr,
  105. style: TextStyle(
  106. fontSize: 10.sp, color: ColorName.tabUnCheckColor))),
  107. ),
  108. Expanded(
  109. flex: 1,
  110. child: bottomAppBarItem(1),
  111. ),
  112. ],
  113. ),
  114. ),
  115. );
  116. }
  117. Widget bottomAppBarItem(int index) {
  118. return Obx(() {
  119. TextStyle style;
  120. TabBean tabBean = controller.tabBeans[index];
  121. String imagePath;
  122. if (controller.currentIndex == index) {
  123. //选中的话
  124. style = TextStyle(fontSize: 10.sp, color: tabBean.txtSelectedColor);
  125. imagePath = tabBean.selectedIcon;
  126. } else {
  127. style = TextStyle(fontSize: 10.sp, color: tabBean.txtNormalColor);
  128. imagePath = tabBean.normalIcon;
  129. }
  130. return GestureDetector(
  131. behavior: HitTestBehavior.opaque,
  132. child: SizedBox(
  133. height: 56.h,
  134. child: Center(
  135. child: Column(
  136. mainAxisSize: MainAxisSize.min,
  137. children: <Widget>[
  138. Image.asset(imagePath, width: 24.w, height: 24.w),
  139. Text(
  140. tabBean.title.tr,
  141. style: style,
  142. )
  143. ],
  144. ),
  145. ),
  146. ),
  147. onTap: () {
  148. if (controller.currentIndex != index) {
  149. controller.updateIndex(index);
  150. }
  151. },
  152. );
  153. });
  154. }
  155. }
  156. class CusCircularNotchedRectangle extends NotchedShape {
  157. /// Creates a [CusCircularNotchedRectangle].
  158. ///
  159. /// The same object can be used to create multiple shapes.
  160. const CusCircularNotchedRectangle();
  161. /// Creates a [Path] that describes a rectangle with a smooth circular notch.
  162. ///
  163. /// `host` is the bounding box for the returned shape. Conceptually this is
  164. /// the rectangle to which the notch will be applied.
  165. ///
  166. /// `guest` is the bounding box of a circle that the notch accommodates. All
  167. /// points in the circle bounded by `guest` will be outside of the returned
  168. /// path.
  169. ///
  170. /// The notch is curve that smoothly connects the host's top edge and
  171. /// the guest circle.
  172. // TODO(amirh): add an example diagram here.
  173. @override
  174. Path getOuterPath(Rect host, Rect? guest) {
  175. if (guest == null || !host.overlaps(guest)) {
  176. return Path()..addRect(host);
  177. }
  178. // The guest's shape is a circle bounded by the guest rectangle.
  179. // So the guest's radius is half the guest width.
  180. final double notchRadius = guest.width / 2.0;
  181. // We build a path for the notch from 3 segments:
  182. // Segment A - a Bezier curve from the host's top edge to segment B.
  183. // Segment B - an arc with radius notchRadius.
  184. // Segment C - a Bezier curve from segment B back to the host's top edge.
  185. //
  186. // A detailed explanation and the derivation of the formulas below is
  187. // available at: https://goo.gl/Ufzrqn
  188. const double s1 = 20.0;
  189. const double s2 = 6;
  190. final double r = notchRadius;
  191. final double a = -1.0 * r - s2;
  192. final double b = host.top - guest.center.dy;
  193. final double n2 = math.sqrt(b * b * r * r * (a * a + b * b - r * r));
  194. final double p2xA = ((a * r * r) - n2) / (a * a + b * b);
  195. final double p2xB = ((a * r * r) + n2) / (a * a + b * b);
  196. final double p2yA = math.sqrt(r * r - p2xA * p2xA);
  197. final double p2yB = math.sqrt(r * r - p2xB * p2xB);
  198. final List<Offset?> p = List<Offset?>.filled(6, null);
  199. // p0, p1, and p2 are the control points for segment A.
  200. p[0] = Offset(a - s1, b);
  201. p[1] = Offset(a, b);
  202. final double cmp = b < 0 ? -1.0 : 1.0;
  203. p[2] = cmp * p2yA > cmp * p2yB ? Offset(p2xA, p2yA) : Offset(p2xB, p2yB);
  204. // p3, p4, and p5 are the control points for segment B, which is a mirror
  205. // of segment A around the y axis.
  206. p[3] = Offset(-1.0 * p[2]!.dx, p[2]!.dy);
  207. p[4] = Offset(-1.0 * p[1]!.dx, p[1]!.dy);
  208. p[5] = Offset(-1.0 * p[0]!.dx, p[0]!.dy);
  209. // translate all points back to the absolute coordinate system.
  210. for (int i = 0; i < p.length; i += 1) {
  211. p[i] = p[i]! + guest.center;
  212. }
  213. return Path()
  214. ..moveTo(host.left, host.top)
  215. ..lineTo(p[0]!.dx, p[0]!.dy)
  216. ..quadraticBezierTo(p[1]!.dx, p[1]!.dy, p[2]!.dx, p[2]!.dy)
  217. ..arcToPoint(
  218. p[3]!,
  219. radius: Radius.circular(notchRadius),
  220. clockwise: false,
  221. )
  222. ..quadraticBezierTo(p[4]!.dx, p[4]!.dy, p[5]!.dx, p[5]!.dy)
  223. ..lineTo(host.right, host.top)
  224. ..lineTo(host.right, host.bottom)
  225. ..lineTo(host.left, host.bottom)
  226. ..close();
  227. }
  228. }