home_component.dart 7.2 KB

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