view.dart 8.1 KB

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