Advertisement
Guest User

Untitled

a guest
Jun 24th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.30 KB | None | 0 0
  1.  
  2. //Contiene l'indice del click che ha effettuato il tap
  3. int indiceClick = 0;
  4.  
  5. //Funzione che viene eseguita al click sul button centrale
  6. void eseguiOperazione(BuildContext context) {
  7.  
  8. //Verifico l'indice e in base a quello visualizzo la finestra desiderata
  9. print( " -- Ti trovi sull'indice: " + indiceClick.toString() + " con il button");
  10. //Eseguo la finestra che si occupa di creare il nuovo cantiere
  11. if (indiceClick == 2) {
  12.  
  13. }
  14. //Eseguo la finestra che si occupa di creare il nuovo rapportino
  15. if (indiceClick == 1) {
  16.  
  17. Navigator.push(
  18. context,
  19. MaterialPageRoute(builder: (context) => new NuovoRapportino()),
  20. );
  21. }
  22. }
  23.  
  24. class BottomBarView extends StatefulWidget {
  25. const BottomBarView(
  26. {Key key, this.tabIconsList, this.changeIndex, this.addClick})
  27. : super(key: key);
  28.  
  29. final Function addClick;
  30. final List<TabIconData> tabIconsList;
  31. @override
  32. _BottomBarViewState createState() => _BottomBarViewState();
  33.  
  34. final Function(int index) changeIndex;
  35. }
  36.  
  37. class _BottomBarViewState extends State<BottomBarView>
  38. with TickerProviderStateMixin {
  39. AnimationController animationController;
  40.  
  41. @override
  42. void dispose() {
  43. //Codice che esegue il rilascio delle risorse
  44. print("Eseguo il rilascio delle risorse");
  45. animationController.dispose();
  46. super.dispose();
  47. }
  48. @override
  49. void initState() {
  50. animationController = AnimationController(
  51. vsync: this,
  52. duration: const Duration(milliseconds: 1000),
  53. );
  54. animationController.forward();
  55. super.initState();
  56. }
  57.  
  58. //Funzuione che rimuove tutti i valori selzionati dalla lista dei tab
  59. void setRemoveAllSelection(TabIconData tabIconData) {
  60. if (mounted) {
  61. setState(() {
  62. widget.tabIconsList.forEach((TabIconData tab) {
  63. tab.isSelected = false;
  64. if (tabIconData.index == tab.index) {
  65. tab.isSelected = true;
  66. }
  67.  
  68. });
  69. });}
  70. }
  71.  
  72. @override
  73. Widget build(BuildContext context) {
  74. return Stack(
  75. alignment: AlignmentDirectional.bottomCenter,
  76. children: <Widget>[
  77. AnimatedBuilder(
  78. animation: animationController,
  79. builder: (BuildContext context, Widget child) {
  80. return Transform(
  81. transform: Matrix4.translationValues(0.0, 0.0, 0.0),
  82. child: PhysicalShape(
  83. color: TemaApp.white,
  84. elevation: 16.0,
  85. clipper: TabClipper(
  86. radius: Tween<double>(begin: 0.0, end: 1.0)
  87. .animate(CurvedAnimation(
  88. parent: animationController,
  89. curve: Curves.fastOutSlowIn))
  90. .value *
  91. 38.0),
  92. child: Column(
  93. children: <Widget>[
  94. SizedBox(
  95. height: 62,
  96. child: Padding(
  97. padding:
  98. const EdgeInsets.only(left: 8, right: 8, top: 4),
  99. child: Row(
  100. children: <Widget>[
  101. Expanded(
  102. child: TabIcons(
  103. tabIconData: widget.tabIconsList[0],
  104. removeAllSelect: () {
  105. setRemoveAllSelection(
  106. widget.tabIconsList[0]);
  107. widget.changeIndex(0);
  108. }),
  109. ),
  110. Expanded(
  111. child: TabIcons(
  112. tabIconData: widget.tabIconsList[1],
  113. removeAllSelect: () {
  114. setRemoveAllSelection(
  115. widget.tabIconsList[1]);
  116. widget.changeIndex(1);
  117. }
  118. ),
  119. ),
  120. SizedBox(
  121. width: Tween<double>(begin: 0.0, end: 1.0)
  122. .animate(CurvedAnimation(
  123. parent: animationController,
  124. curve: Curves.fastOutSlowIn))
  125. .value *
  126. 64.0,
  127. ),
  128. Expanded(
  129. child: TabIcons(
  130. tabIconData: widget.tabIconsList[2],
  131. removeAllSelect: () {
  132. setRemoveAllSelection(
  133. widget.tabIconsList[2]);
  134. widget.changeIndex(2);
  135. }),
  136. ),
  137. Expanded(
  138. child: TabIcons(
  139. tabIconData: widget.tabIconsList[3],
  140. removeAllSelect: () {
  141. setRemoveAllSelection(
  142. widget.tabIconsList[3]);
  143. widget.changeIndex(3);
  144. }),
  145. ),
  146. ],
  147. ),
  148. ),
  149. ),
  150. SizedBox(
  151. height: MediaQuery.of(context).padding.bottom,
  152. )
  153. ],
  154. ),
  155. ),
  156. );
  157. },
  158. ),
  159. Padding(
  160. padding:
  161. EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
  162. child: SizedBox(
  163. width: 38 * 2.0,
  164. height: 38 + 62.0,
  165. child: Container(
  166. alignment: Alignment.topCenter,
  167. color: Colors.transparent,
  168. child: SizedBox(
  169. width: 38 * 2.0,
  170. height: 38 * 2.0,
  171. child: Padding(
  172. padding: const EdgeInsets.all(8.0),
  173. child: ScaleTransition(
  174. alignment: Alignment.center,
  175. scale: Tween<double>(begin: 0.0, end: 1.0).animate(
  176. CurvedAnimation(
  177. parent: animationController,
  178. curve: Curves.fastOutSlowIn)),
  179. child: Container(
  180. // alignment: Alignment.center,s
  181. decoration: BoxDecoration(
  182. color: TemaApp.nearlyDarkBlue,
  183. gradient: LinearGradient(
  184. colors: [
  185. TemaApp.nearlyDarkBlue,
  186. HexColor('#6A88E5'),
  187. ],
  188. begin: Alignment.topLeft,
  189. end: Alignment.bottomRight),
  190. shape: BoxShape.circle,
  191. boxShadow: <BoxShadow>[
  192. BoxShadow(
  193. color: TemaApp.nearlyDarkBlue.withOpacity(0.4),
  194. offset: const Offset(8.0, 16.0),
  195. blurRadius: 16.0),
  196. ],
  197. ),
  198. child: Material(
  199. color: Colors.transparent,
  200. child: InkWell(
  201. splashColor: Colors.white.withOpacity(0.1),
  202. highlightColor: Colors.transparent,
  203. focusColor: Colors.transparent,
  204. onTap: () {
  205. widget.addClick();
  206.  
  207. eseguiOperazione(context);
  208. },
  209. child: Icon(
  210. Icons.add,
  211. color: TemaApp.white,
  212. size: 32,
  213. ),
  214. ),
  215. ),
  216. ),
  217. ),
  218. ),
  219. ),
  220. ),
  221. ),
  222. ),
  223. ],
  224. );
  225. }
  226. }
  227.  
  228. class TabIcons extends StatefulWidget {
  229. const TabIcons({Key key, this.tabIconData, this.removeAllSelect})
  230. : super(key: key);
  231.  
  232. final Function removeAllSelect;
  233. final TabIconData tabIconData;
  234.  
  235. @override
  236. _TabIconsState createState() => _TabIconsState();
  237. }
  238.  
  239. class _TabIconsState extends State<TabIcons> with TickerProviderStateMixin {
  240. @override
  241. void initState() {
  242. widget.tabIconData.animationController = AnimationController(
  243. vsync: this,
  244. duration: const Duration(milliseconds: 400),
  245. )..addStatusListener((AnimationStatus status) {
  246. if (status == AnimationStatus.completed) {
  247. if (!mounted) return;
  248. widget.removeAllSelect();
  249. widget.tabIconData.animationController.reverse();
  250. }
  251. });
  252. super.initState();
  253. }
  254.  
  255. void setAnimation() {
  256. widget.tabIconData.animationController.forward();
  257. }
  258.  
  259. @override
  260. Widget build(BuildContext context) {
  261. return AspectRatio(
  262. aspectRatio: 1,
  263. child: Center(
  264. child: InkWell(
  265. splashColor: Colors.transparent,
  266. focusColor: Colors.transparent,
  267. highlightColor: Colors.transparent,
  268. hoverColor: Colors.transparent,
  269. //Click sul tabIcon
  270. onTap: () {
  271. if (!widget.tabIconData.isSelected) {
  272. setAnimation();
  273. }
  274. //Salvo l'indice dell'tabicon sul quale รจ stato effettuato
  275. indiceClick = widget.tabIconData.index;
  276. print("Cambiato tap : " + indiceClick.toString());
  277. },
  278. child: IgnorePointer(
  279. child: Stack(
  280. alignment: AlignmentDirectional.center,
  281. children: <Widget>[
  282. ScaleTransition(
  283. alignment: Alignment.center,
  284. scale: Tween<double>(begin: 0.88, end: 1.0).animate(
  285. CurvedAnimation(
  286. parent: widget.tabIconData.animationController,
  287. curve:
  288. Interval(0.1, 1.0, curve: Curves.fastOutSlowIn))),
  289. child: Image.asset(widget.tabIconData.isSelected
  290. ? widget.tabIconData.selectedImagePath
  291. : widget.tabIconData.imagePath),
  292. ),
  293. Positioned(
  294. top: 4,
  295. left: 6,
  296. right: 0,
  297. child: ScaleTransition(
  298. alignment: Alignment.center,
  299. scale: Tween<double>(begin: 0.0, end: 1.0).animate(
  300. CurvedAnimation(
  301. parent: widget.tabIconData.animationController,
  302. curve: Interval(0.2, 1.0,
  303. curve: Curves.fastOutSlowIn))),
  304. child: Container(
  305. width: 8,
  306. height: 8,
  307. decoration: BoxDecoration(
  308. color: TemaApp.nearlyDarkBlue,
  309. shape: BoxShape.circle,
  310. ),
  311. ),
  312. ),
  313. ),
  314. Positioned(
  315. top: 0,
  316. left: 6,
  317. bottom: 8,
  318. child: ScaleTransition(
  319. alignment: Alignment.center,
  320. scale: Tween<double>(begin: 0.0, end: 1.0).animate(
  321. CurvedAnimation(
  322. parent: widget.tabIconData.animationController,
  323. curve: Interval(0.5, 0.8,
  324. curve: Curves.fastOutSlowIn))),
  325. child: Container(
  326. width: 4,
  327. height: 4,
  328. decoration: BoxDecoration(
  329. color: TemaApp.nearlyDarkBlue,
  330. shape: BoxShape.circle,
  331. ),
  332. ),
  333. ),
  334. ),
  335. Positioned(
  336. top: 6,
  337. right: 8,
  338. bottom: 0,
  339. child: ScaleTransition(
  340. alignment: Alignment.center,
  341. scale: Tween<double>(begin: 0.0, end: 1.0).animate(
  342. CurvedAnimation(
  343. parent: widget.tabIconData.animationController,
  344. curve: Interval(0.5, 0.6,
  345. curve: Curves.fastOutSlowIn))),
  346. child: Container(
  347. width: 6,
  348. height: 6,
  349. decoration: BoxDecoration(
  350. color: TemaApp.nearlyDarkBlue,
  351. shape: BoxShape.circle,
  352. ),
  353. ),
  354. ),
  355. ),
  356. ],
  357. ),
  358. ),
  359. ),
  360. ),
  361. );
  362. }
  363. }
  364.  
  365. class TabClipper extends CustomClipper<Path> {
  366. TabClipper({
  367. this.radius = 38.0,
  368. });
  369.  
  370. final double radius;
  371.  
  372. @override
  373. Path getClip(Size size) {
  374. final Path path = Path();
  375.  
  376. final double v = radius * 2;
  377. path.lineTo(0, 0);
  378. path.arcTo(Rect.fromLTWH(0, 0, radius, radius), degreeToRadians(180),
  379. degreeToRadians(90), false);
  380. path.arcTo(
  381. Rect.fromLTWH(
  382. ((size.width / 2) - v / 2) - radius + v * 0.04, 0, radius, radius),
  383. degreeToRadians(270),
  384. degreeToRadians(70),
  385. false);
  386. path.arcTo(Rect.fromLTWH((size.width / 2) - v / 2, -v / 2, v, v),
  387. degreeToRadians(160), degreeToRadians(-140), false);
  388.  
  389. path.arcTo(
  390. Rect.fromLTWH((size.width - ((size.width / 2) - v / 2)) - v * 0.04, 0,
  391. radius, radius),
  392. degreeToRadians(200),
  393. degreeToRadians(70),
  394. false);
  395. path.arcTo(Rect.fromLTWH(size.width - radius, 0, radius, radius),
  396. degreeToRadians(270), degreeToRadians(90), false);
  397. path.lineTo(size.width, 0);
  398. path.lineTo(size.width, size.height);
  399. path.lineTo(0, size.height);
  400.  
  401. path.close();
  402. return path;
  403. }
  404.  
  405. @override
  406. bool shouldReclip(TabClipper oldClipper) => true;
  407.  
  408. //Conversione in radianti dei gragi
  409. double degreeToRadians(double degree) {
  410. final double redian = (math.pi / 180) * degree;
  411. return redian;
  412. }
  413. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement