home_component.dart 6.7 KB

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