home_component.dart 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 (In from Left)", "preset-from-left"),
  99. menuButton(context, "Preset (Fade In)", "preset-fade"),
  100. menuButton(context, "Custom Transition", "custom"),
  101. menuButton(context, "Navigator Result", "pop-result"),
  102. menuButton(context, "Function Call", "function-call"),
  103. new Padding(
  104. padding: new EdgeInsets.only(top: 65.0, left: 60.0, right: 60.0),
  105. child: new Center(
  106. child: new ConstrainedBox(
  107. constraints: new BoxConstraints.tightFor(height: 60.0),
  108. child: deepLinkWidget(context),
  109. ),
  110. ),
  111. ),
  112. ];
  113. return new Material(
  114. color: const Color(0xFF00D6F7),
  115. child: new Column(
  116. mainAxisAlignment: MainAxisAlignment.center,
  117. children: menuWidgets,
  118. ),
  119. );
  120. }
  121. // helpers
  122. Widget menuButton(BuildContext context, String title, String key) {
  123. return new Padding(
  124. padding: new EdgeInsets.all(4.0),
  125. child: new ConstrainedBox(
  126. constraints: new BoxConstraints(minHeight: 42.0),
  127. child: new FlatButton(
  128. highlightColor: const Color(0x11FFFFFF),
  129. splashColor: const Color(0x22FFFFFF),
  130. child: new Text(
  131. title,
  132. style: new TextStyle(
  133. color: const Color(0xAA001133),
  134. ),
  135. ),
  136. onPressed: () {
  137. tappedMenuButton(context, key);
  138. },
  139. ),
  140. ),
  141. );
  142. }
  143. // actions
  144. void tappedMenuButton(BuildContext context, String key) {
  145. String message = "";
  146. String hexCode = "#FFFFFF";
  147. String result;
  148. TransitionType transitionType = TransitionType.native;
  149. if (key != "custom" && key != "function-call") {
  150. if (key == "native") {
  151. hexCode = "#F76F00";
  152. message =
  153. "This screen should have appeared using the default flutter animation for the current OS";
  154. } else if (key == "preset-from-left") {
  155. hexCode = "#5BF700";
  156. message =
  157. "This screen should have appeared with a slide in from left transition";
  158. transitionType = TransitionType.inFromLeft;
  159. } else if (key == "preset-fade") {
  160. hexCode = "#F700D2";
  161. message = "This screen should have appeared with a fade in transition";
  162. transitionType = TransitionType.fadeIn;
  163. } else if (key == "pop-result") {
  164. transitionType = TransitionType.native;
  165. hexCode = "#7d41f4";
  166. message =
  167. "When you close this screen you should see the current day of the week";
  168. result = "Today is ${_daysOfWeek[new DateTime.now().weekday - 1]}!";
  169. }
  170. String route = "/demo?message=$message&color_hex=$hexCode";
  171. if (result != null) {
  172. route = "$route&result=$result";
  173. }
  174. Application.router
  175. .navigateTo(context, route, transition: transitionType)
  176. .then((result) {
  177. if (key == "pop-result") {
  178. Application.router.navigateTo(context, "/demo/func?message=$result");
  179. }
  180. });
  181. } else if (key == "custom") {
  182. hexCode = "#DFF700";
  183. message =
  184. "This screen should have appeared with a crazy custom transition";
  185. var transition = (BuildContext context, Animation<double> animation,
  186. Animation<double> secondaryAnimation, Widget child) {
  187. return new ScaleTransition(
  188. scale: animation,
  189. child: new RotationTransition(
  190. turns: animation,
  191. child: child,
  192. ),
  193. );
  194. };
  195. Application.router.navigateTo(
  196. context,
  197. "/demo?message=$message&color_hex=$hexCode",
  198. transition: TransitionType.custom,
  199. transitionBuilder: transition,
  200. transitionDuration: const Duration(milliseconds: 600),
  201. );
  202. } else {
  203. message = "You tapped the function button!";
  204. Application.router.navigateTo(context, "/demo/func?message=$message");
  205. }
  206. }
  207. }