view.dart 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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: SizedBox(
  72. key: controller.aiGuideKey,
  73. width: 52.w,
  74. child: AspectRatio(
  75. aspectRatio: 1 / 1,
  76. child: Assets.images.mainTabSecretary.image()),
  77. ));
  78. }
  79. Widget buildBottomAppBar() {
  80. return Container(
  81. decoration: BoxDecoration(
  82. boxShadow: [
  83. BoxShadow(
  84. color: ColorName.black5.withOpacity(0.05), // 阴影颜色
  85. blurRadius: 23, // 阴影模糊半径
  86. spreadRadius: 2, // 阴影扩展半径
  87. offset: const Offset(0, 0), // 阴影位置,向上偏移
  88. ),
  89. ],
  90. ),
  91. child: BottomAppBar(
  92. color: Colors.white,
  93. height: Constants.bottomBarHeight,
  94. padding: EdgeInsets.zero,
  95. shape: const CusCircularNotchedRectangle(),
  96. child: Flex(
  97. mainAxisAlignment: MainAxisAlignment.spaceAround,
  98. direction: Axis.horizontal,
  99. children: <Widget>[
  100. Expanded(
  101. flex: 1,
  102. child: bottomAppBarItem(0),
  103. ),
  104. SizedBox(
  105. width: 62.w,
  106. height: double.infinity,
  107. child: Align(
  108. alignment: const Alignment(0.0, 0.6),
  109. child: Text(StringName.mainTabAi.tr,
  110. style: TextStyle(
  111. fontSize: 10.sp, color: ColorName.tabUnCheckColor))),
  112. ),
  113. Expanded(
  114. flex: 1,
  115. child: bottomAppBarItem(1),
  116. ),
  117. ],
  118. ),
  119. ),
  120. );
  121. }
  122. Widget bottomAppBarItem(int index) {
  123. return Obx(() {
  124. TextStyle style;
  125. TabBean tabBean = controller.tabBeans[index];
  126. String imagePath;
  127. if (controller.currentIndex == index) {
  128. //选中的话
  129. style = TextStyle(fontSize: 10.sp, color: tabBean.txtSelectedColor);
  130. imagePath = tabBean.selectedIcon;
  131. } else {
  132. style = TextStyle(fontSize: 10.sp, color: tabBean.txtNormalColor);
  133. imagePath = tabBean.normalIcon;
  134. }
  135. return GestureDetector(
  136. behavior: HitTestBehavior.opaque,
  137. child: SizedBox(
  138. height: 56.h,
  139. child: Center(
  140. child: Column(
  141. mainAxisSize: MainAxisSize.min,
  142. children: <Widget>[
  143. Image.asset(imagePath, width: 24.w, height: 24.w),
  144. Text(
  145. tabBean.title.tr,
  146. style: style,
  147. )
  148. ],
  149. ),
  150. ),
  151. ),
  152. onTap: () {
  153. if (controller.currentIndex != index) {
  154. controller.updateIndex(index);
  155. }
  156. },
  157. );
  158. });
  159. }
  160. }
  161. class CusCircularNotchedRectangle extends NotchedShape {
  162. /// Creates a [CusCircularNotchedRectangle].
  163. ///
  164. /// The same object can be used to create multiple shapes.
  165. const CusCircularNotchedRectangle();
  166. /// Creates a [Path] that describes a rectangle with a smooth circular notch.
  167. ///
  168. /// `host` is the bounding box for the returned shape. Conceptually this is
  169. /// the rectangle to which the notch will be applied.
  170. ///
  171. /// `guest` is the bounding box of a circle that the notch accommodates. All
  172. /// points in the circle bounded by `guest` will be outside of the returned
  173. /// path.
  174. ///
  175. /// The notch is curve that smoothly connects the host's top edge and
  176. /// the guest circle.
  177. // TODO(amirh): add an example diagram here.
  178. @override
  179. Path getOuterPath(Rect host, Rect? guest) {
  180. if (guest == null || !host.overlaps(guest)) {
  181. return Path()..addRect(host);
  182. }
  183. // The guest's shape is a circle bounded by the guest rectangle.
  184. // So the guest's radius is half the guest width.
  185. final double notchRadius = guest.width / 2.0;
  186. // We build a path for the notch from 3 segments:
  187. // Segment A - a Bezier curve from the host's top edge to segment B.
  188. // Segment B - an arc with radius notchRadius.
  189. // Segment C - a Bezier curve from segment B back to the host's top edge.
  190. //
  191. // A detailed explanation and the derivation of the formulas below is
  192. // available at: https://goo.gl/Ufzrqn
  193. const double s1 = 20.0;
  194. const double s2 = 6;
  195. final double r = notchRadius;
  196. final double a = -1.0 * r - s2;
  197. final double b = host.top - guest.center.dy;
  198. final double n2 = math.sqrt(b * b * r * r * (a * a + b * b - r * r));
  199. final double p2xA = ((a * r * r) - n2) / (a * a + b * b);
  200. final double p2xB = ((a * r * r) + n2) / (a * a + b * b);
  201. final double p2yA = math.sqrt(r * r - p2xA * p2xA);
  202. final double p2yB = math.sqrt(r * r - p2xB * p2xB);
  203. final List<Offset?> p = List<Offset?>.filled(6, null);
  204. // p0, p1, and p2 are the control points for segment A.
  205. p[0] = Offset(a - s1, b);
  206. p[1] = Offset(a, b);
  207. final double cmp = b < 0 ? -1.0 : 1.0;
  208. p[2] = cmp * p2yA > cmp * p2yB ? Offset(p2xA, p2yA) : Offset(p2xB, p2yB);
  209. // p3, p4, and p5 are the control points for segment B, which is a mirror
  210. // of segment A around the y axis.
  211. p[3] = Offset(-1.0 * p[2]!.dx, p[2]!.dy);
  212. p[4] = Offset(-1.0 * p[1]!.dx, p[1]!.dy);
  213. p[5] = Offset(-1.0 * p[0]!.dx, p[0]!.dy);
  214. // translate all points back to the absolute coordinate system.
  215. for (int i = 0; i < p.length; i += 1) {
  216. p[i] = p[i]! + guest.center;
  217. }
  218. return Path()
  219. ..moveTo(host.left, host.top)
  220. ..lineTo(p[0]!.dx, p[0]!.dy)
  221. ..quadraticBezierTo(p[1]!.dx, p[1]!.dy, p[2]!.dx, p[2]!.dy)
  222. ..arcToPoint(
  223. p[3]!,
  224. radius: Radius.circular(notchRadius),
  225. clockwise: false,
  226. )
  227. ..quadraticBezierTo(p[4]!.dx, p[4]!.dy, p[5]!.dx, p[5]!.dy)
  228. ..lineTo(host.right, host.top)
  229. ..lineTo(host.right, host.bottom)
  230. ..lineTo(host.left, host.bottom)
  231. ..close();
  232. }
  233. }