home_component.dart 6.8 KB

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