home_component.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * fluro
  3. * Created by Yakka
  4. * https://theyakka.com
  5. *
  6. * Copyright (c) 2019 Yakka, LLC. All rights reserved.
  7. * See LICENSE for distribution and usage details.
  8. */
  9. import 'dart:async';
  10. import 'package:fluro/fluro.dart';
  11. import 'package:flutter/cupertino.dart';
  12. import 'package:flutter/material.dart';
  13. import 'package:flutter/services.dart';
  14. import '../../config/application.dart';
  15. class HomeComponent extends StatefulWidget {
  16. @override
  17. State createState() => HomeComponentState();
  18. }
  19. class HomeComponentState extends State<HomeComponent> {
  20. var _deepLinkOpacity = 1.0;
  21. final _deepLinkURL =
  22. "fluro://deeplink?path=/message&mesage=fluro%20rocks%21%21";
  23. final _daysOfWeek = const [
  24. "Monday",
  25. "Tuesday",
  26. "Wednesday",
  27. "Thursday",
  28. "Friday",
  29. "Saturday",
  30. "Sunday"
  31. ];
  32. Widget deepLinkWidget(BuildContext context) {
  33. return Stack(
  34. children: <Widget>[
  35. // copied widget
  36. AnimatedOpacity(
  37. opacity: (_deepLinkOpacity - 1.0).abs(),
  38. duration: Duration(milliseconds: 400),
  39. child: Center(
  40. child: Text(
  41. "Copied to clipboard!",
  42. style: TextStyle(
  43. fontSize: 14.0,
  44. color: const Color(0xFFFFFFFF),
  45. fontWeight: FontWeight.w500,
  46. ),
  47. ),
  48. ),
  49. ),
  50. // button widget
  51. AnimatedOpacity(
  52. opacity: _deepLinkOpacity,
  53. duration: Duration(milliseconds: 250),
  54. child: Center(
  55. child: TextButton(
  56. onPressed: () {
  57. if (_deepLinkOpacity == 1.0) {
  58. Timer(Duration(milliseconds: 2000), () {
  59. setState(() {
  60. _deepLinkOpacity = 1.0;
  61. });
  62. });
  63. setState(() {
  64. _deepLinkOpacity = 0.0;
  65. });
  66. final clipboardData = ClipboardData(text: _deepLinkURL);
  67. Clipboard.setData(clipboardData);
  68. }
  69. },
  70. child: Padding(
  71. padding: EdgeInsets.all(8.0),
  72. child: Text(
  73. "Click here to copy a deep link url to the clipboard",
  74. textAlign: TextAlign.center,
  75. style: TextStyle(
  76. fontSize: 12.0,
  77. color: const Color(0xCCFFFFFF),
  78. ),
  79. ),
  80. ),
  81. ),
  82. ),
  83. ),
  84. ],
  85. );
  86. }
  87. @override
  88. Widget build(BuildContext context) {
  89. var menuWidgets = <Widget>[
  90. menuButton(context, 'assets/images/ic_transform_native_hz.png',
  91. "Native Animation", "native"),
  92. menuButton(context, 'assets/images/ic_transform_fade_in_hz.png',
  93. "Preset (Fade In)", "preset-fade"),
  94. menuButton(context, 'assets/images/ic_transform_global_hz.png',
  95. "Preset (Global transition)", "fixed-trans"),
  96. menuButton(context, 'assets/images/ic_transform_custom_hz.png',
  97. "Custom Transition", "custom"),
  98. menuButton(context, 'assets/images/ic_result_hz.png', "Navigator Result",
  99. "pop-result"),
  100. menuButton(context, 'assets/images/ic_function_hz.png', "Function Call",
  101. "function-call"),
  102. ];
  103. final size = MediaQuery.of(context).size;
  104. final childRatio = (size.width / size.height) * 2.5;
  105. return Material(
  106. color: const Color(0xFF00D6F7),
  107. child: SafeArea(
  108. top: true,
  109. child: Column(
  110. mainAxisSize: MainAxisSize.max,
  111. mainAxisAlignment: MainAxisAlignment.center,
  112. crossAxisAlignment: CrossAxisAlignment.start,
  113. children: <Widget>[
  114. Padding(
  115. padding: EdgeInsets.only(top: 25, bottom: 35, left: 25),
  116. child: Image(
  117. image: AssetImage("assets/images/logo_fluro.png"),
  118. width: 100.0,
  119. ),
  120. ),
  121. Expanded(
  122. child: Padding(
  123. padding: const EdgeInsets.symmetric(horizontal: 25),
  124. child: GridView.count(
  125. childAspectRatio: childRatio,
  126. crossAxisCount: 2,
  127. mainAxisSpacing: 5,
  128. children: menuWidgets,
  129. ),
  130. ),
  131. ),
  132. ],
  133. ),
  134. ),
  135. );
  136. }
  137. // helpers
  138. Widget menuButton(
  139. BuildContext context, String assetSrc, String title, String key) {
  140. return Padding(
  141. padding: EdgeInsets.all(4.0),
  142. child: Container(
  143. height: 42.0,
  144. child: TextButton(
  145. child: Column(
  146. mainAxisSize: MainAxisSize.min,
  147. mainAxisAlignment: MainAxisAlignment.center,
  148. crossAxisAlignment: CrossAxisAlignment.center,
  149. children: <Widget>[
  150. Padding(
  151. padding: const EdgeInsets.only(bottom: 10),
  152. child: Container(
  153. height: 36,
  154. child: Image.asset(
  155. assetSrc,
  156. fit: BoxFit.contain,
  157. ),
  158. ),
  159. ),
  160. Text(
  161. title,
  162. textAlign: TextAlign.center,
  163. style: TextStyle(
  164. color: const Color(0xAA001133),
  165. ),
  166. )
  167. ],
  168. ),
  169. onPressed: () {
  170. tappedMenuButton(context, key);
  171. },
  172. ),
  173. ),
  174. );
  175. }
  176. // actions
  177. void tappedMenuButton(BuildContext context, String key) {
  178. String message = "";
  179. String hexCode = "#FFFFFF";
  180. String? result;
  181. TransitionType transitionType = TransitionType.native;
  182. if (key != "custom" && key != "function-call" && key != "fixed-trans") {
  183. if (key == "native") {
  184. hexCode = "#F76F00";
  185. message =
  186. "This screen should have appeared using the default flutter animation for the current OS";
  187. } else if (key == "preset-from-left") {
  188. hexCode = "#5BF700";
  189. message =
  190. "This screen should have appeared with a slide in from left transition";
  191. transitionType = TransitionType.inFromLeft;
  192. } else if (key == "preset-fade") {
  193. hexCode = "#F700D2";
  194. message = "This screen should have appeared with a fade in transition";
  195. transitionType = TransitionType.fadeIn;
  196. } else if (key == "pop-result") {
  197. transitionType = TransitionType.native;
  198. hexCode = "#7d41f4";
  199. message =
  200. "When you close this screen you should see the current day of the week";
  201. result = "Today is ${_daysOfWeek[DateTime.now().weekday - 1]}!";
  202. }
  203. String route = "/demo?message=$message&color_hex=$hexCode";
  204. if (result != null) {
  205. route = "$route&result=$result";
  206. }
  207. Application.router
  208. .navigateTo(context, route, transition: transitionType)
  209. .then((result) {
  210. if (key == "pop-result") {
  211. Application.router.navigateTo(context, "/demo/func?message=$result");
  212. }
  213. });
  214. } else if (key == "custom") {
  215. hexCode = "#DFF700";
  216. message =
  217. "This screen should have appeared with a crazy custom transition";
  218. var transition = (BuildContext context, Animation<double> animation,
  219. Animation<double> secondaryAnimation, Widget child) {
  220. return ScaleTransition(
  221. scale: animation,
  222. child: RotationTransition(
  223. turns: animation,
  224. child: child,
  225. ),
  226. );
  227. };
  228. Application.router.navigateTo(
  229. context,
  230. "/demo?message=$message&color_hex=$hexCode",
  231. transition: TransitionType.custom,
  232. transitionBuilder: transition,
  233. transitionDuration: const Duration(milliseconds: 600),
  234. );
  235. } else if (key == "fixed-trans") {
  236. Application.router.navigateTo(
  237. context, "/demo/fixedtrans?message=Hello!&color_hex=#f4424b");
  238. } else {
  239. message = "You tapped the function button!";
  240. Application.router.navigateTo(context, "/demo/func?message=$message");
  241. }
  242. }
  243. }