home_component.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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: FlatButton(
  56. highlightColor: const Color(0x11FFFFFF),
  57. splashColor: const Color(0x22FFFFFF),
  58. onPressed: () {
  59. if (_deepLinkOpacity == 1.0) {
  60. Timer(Duration(milliseconds: 2000), () {
  61. setState(() {
  62. _deepLinkOpacity = 1.0;
  63. });
  64. });
  65. setState(() {
  66. _deepLinkOpacity = 0.0;
  67. });
  68. final clipboardData = ClipboardData(text: _deepLinkURL);
  69. Clipboard.setData(clipboardData);
  70. }
  71. },
  72. child: Padding(
  73. padding: EdgeInsets.all(8.0),
  74. child: Text(
  75. "Click here to copy a deep link url to the clipboard",
  76. textAlign: TextAlign.center,
  77. style: TextStyle(
  78. fontSize: 12.0,
  79. color: const Color(0xCCFFFFFF),
  80. ),
  81. ),
  82. ),
  83. ),
  84. ),
  85. ),
  86. ],
  87. );
  88. }
  89. @override
  90. Widget build(BuildContext context) {
  91. var menuWidgets = <Widget>[
  92. menuButton(context, 'assets/images/ic_transform_native_hz.png',
  93. "Native Animation", "native"),
  94. menuButton(context, 'assets/images/ic_transform_fade_in_hz.png',
  95. "Preset (Fade In)", "preset-fade"),
  96. menuButton(context, 'assets/images/ic_transform_global_hz.png',
  97. "Preset (Global transition)", "fixed-trans"),
  98. menuButton(context, 'assets/images/ic_transform_custom_hz.png',
  99. "Custom Transition", "custom"),
  100. menuButton(context, 'assets/images/ic_result_hz.png', "Navigator Result",
  101. "pop-result"),
  102. menuButton(context, 'assets/images/ic_function_hz.png', "Function Call",
  103. "function-call"),
  104. ];
  105. final size = MediaQuery.of(context).size;
  106. final childRatio = (size.width / size.height) * 2.5;
  107. return Material(
  108. color: const Color(0xFF00D6F7),
  109. child: SafeArea(
  110. top: true,
  111. child: Column(
  112. mainAxisSize: MainAxisSize.max,
  113. mainAxisAlignment: MainAxisAlignment.center,
  114. crossAxisAlignment: CrossAxisAlignment.start,
  115. children: <Widget>[
  116. Padding(
  117. padding: EdgeInsets.only(top: 25, bottom: 35, left: 25),
  118. child: Image(
  119. image: AssetImage("assets/images/logo_fluro.png"),
  120. width: 100.0,
  121. ),
  122. ),
  123. Expanded(
  124. child: Padding(
  125. padding: const EdgeInsets.symmetric(horizontal: 25),
  126. child: GridView.count(
  127. childAspectRatio: childRatio,
  128. crossAxisCount: 2,
  129. mainAxisSpacing: 5,
  130. children: menuWidgets,
  131. ),
  132. ),
  133. ),
  134. // Padding(
  135. // padding: EdgeInsets.only(top: 35.0, bottom: 25),
  136. // child: Center(
  137. // child: ConstrainedBox(
  138. // constraints: BoxConstraints.tightFor(height: 60.0),
  139. // child: deepLinkWidget(context),
  140. // ),
  141. // ),
  142. // ),
  143. ],
  144. ),
  145. ),
  146. );
  147. }
  148. // helpers
  149. Widget menuButton(
  150. BuildContext context, String assetSrc, String title, String key) {
  151. return Padding(
  152. padding: EdgeInsets.all(4.0),
  153. child: Container(
  154. height: 42.0,
  155. child: FlatButton(
  156. color: const Color(0x22FFFFFF),
  157. highlightColor: const Color(0x11FFFFFF),
  158. splashColor: const Color(0x22FFFFFF),
  159. child: Column(
  160. mainAxisSize: MainAxisSize.min,
  161. mainAxisAlignment: MainAxisAlignment.center,
  162. crossAxisAlignment: CrossAxisAlignment.center,
  163. children: <Widget>[
  164. Padding(
  165. padding: const EdgeInsets.only(bottom: 10),
  166. child: Container(
  167. height: 36,
  168. child: Image.asset(
  169. assetSrc,
  170. fit: BoxFit.contain,
  171. ),
  172. ),
  173. ),
  174. Text(
  175. title,
  176. textAlign: TextAlign.center,
  177. style: TextStyle(
  178. color: const Color(0xAA001133),
  179. ),
  180. )
  181. ],
  182. ),
  183. onPressed: () {
  184. tappedMenuButton(context, key);
  185. },
  186. ),
  187. ),
  188. );
  189. }
  190. // actions
  191. void tappedMenuButton(BuildContext context, String key) {
  192. String message = "";
  193. String hexCode = "#FFFFFF";
  194. String result;
  195. TransitionType transitionType = TransitionType.native;
  196. if (key != "custom" && key != "function-call" && key != "fixed-trans") {
  197. if (key == "native") {
  198. hexCode = "#F76F00";
  199. message =
  200. "This screen should have appeared using the default flutter animation for the current OS";
  201. } else if (key == "preset-from-left") {
  202. hexCode = "#5BF700";
  203. message =
  204. "This screen should have appeared with a slide in from left transition";
  205. transitionType = TransitionType.inFromLeft;
  206. } else if (key == "preset-fade") {
  207. hexCode = "#F700D2";
  208. message = "This screen should have appeared with a fade in transition";
  209. transitionType = TransitionType.fadeIn;
  210. } else if (key == "pop-result") {
  211. transitionType = TransitionType.native;
  212. hexCode = "#7d41f4";
  213. message =
  214. "When you close this screen you should see the current day of the week";
  215. result = "Today is ${_daysOfWeek[DateTime.now().weekday - 1]}!";
  216. }
  217. String route = "/demo?message=$message&color_hex=$hexCode";
  218. if (result != null) {
  219. route = "$route&result=$result";
  220. }
  221. Application.router
  222. .navigateTo(context, route, transition: transitionType)
  223. .then((result) {
  224. if (key == "pop-result") {
  225. Application.router.navigateTo(context, "/demo/func?message=$result");
  226. }
  227. });
  228. } else if (key == "custom") {
  229. hexCode = "#DFF700";
  230. message =
  231. "This screen should have appeared with a crazy custom transition";
  232. var transition = (BuildContext context, Animation<double> animation,
  233. Animation<double> secondaryAnimation, Widget child) {
  234. return ScaleTransition(
  235. scale: animation,
  236. child: RotationTransition(
  237. turns: animation,
  238. child: child,
  239. ),
  240. );
  241. };
  242. Application.router.navigateTo(
  243. context,
  244. "/demo?message=$message&color_hex=$hexCode",
  245. transition: TransitionType.custom,
  246. transitionBuilder: transition,
  247. transitionDuration: const Duration(milliseconds: 600),
  248. );
  249. } else if (key == "fixed-trans") {
  250. Application.router.navigateTo(
  251. context, "/demo/fixedtrans?message=Hello!&color_hex=#f4424b");
  252. } else {
  253. message = "You tapped the function button!";
  254. Application.router.navigateTo(context, "/demo/func?message=$message");
  255. }
  256. }
  257. }