Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.04 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:english_words/english_words.dart';
  3.  
  4. void main() => runApp(new MyApp());
  5.  
  6. class MyApp extends StatelessWidget {
  7. @override
  8. Widget build(BuildContext context) {
  9. return new MaterialApp(
  10. title: 'Startup Name Generator',
  11. theme: new ThemeData(
  12. primaryColor: Colors.white,
  13. ),
  14. home: new RandomWords(),
  15. );
  16. }
  17. }
  18.  
  19. class RandomWords extends StatefulWidget{
  20. @override
  21. createState() => new RandomWordsState();
  22. }
  23.  
  24. class RandomWordsState extends State<RandomWords> {
  25. final _suggestions = <WordPair>[];
  26. final _saved = new Set<WordPair>();
  27. final _biggerFont = const TextStyle(fontSize: 18.0);
  28. @override
  29. Widget build(BuildContext context) {
  30. return new Scaffold(
  31. appBar: new AppBar(
  32. title: new Text('Startup Name Generator'),
  33. actions: <Widget>[
  34. new IconButton(icon: new Icon(Icons.list),onPressed: _pushSaved),
  35. ],
  36. ),
  37. body: _buildSuggestions(),
  38. );
  39. }
  40.  
  41. Widget _buildRow(WordPair pair){
  42. final alreadySaved = _saved.contains(pair);
  43. return new ListTile(
  44. title: new Text(
  45. pair.asPascalCase,
  46. style: _biggerFont,
  47. ),
  48. trailing: new Icon(
  49. alreadySaved ? Icons.favorite : Icons.favorite_border,
  50. color: alreadySaved ? Colors.red : null,
  51. ),
  52. onTap: (){
  53. setState((){
  54. if (alreadySaved){
  55. _saved.remove(pair);
  56. } else {
  57. _saved.add(pair);
  58. }
  59. });
  60. },
  61. );
  62. }
  63.  
  64. Widget _buildSuggestions() {
  65. return new ListView.builder(
  66. padding: const EdgeInsets.all(16.0),
  67. itemBuilder: (context,i){
  68. if (i.isOdd) return new Divider();
  69. final index = i ~/2;
  70. if (index >= _suggestions.length) {
  71. _suggestions.addAll(generateWordPairs().take(16));
  72. }
  73. return _buildRow(_suggestions[index]);
  74. }
  75. );
  76. }
  77.  
  78. void _pushSaved() {
  79. Navigator.of(context).push(
  80. new MaterialPageRoute(
  81. builder: (context){
  82. final tiles = _saved.map(
  83. (pair){
  84. return new ListTile(
  85. title: new Text(
  86. pair.asPascalCase,
  87. style: _biggerFont,
  88. ),
  89. );
  90. },
  91. );
  92.  
  93. final divided = ListTile
  94. .divideTiles(
  95. context: context,
  96. tiles: tiles,
  97. )
  98. .toList();
  99.  
  100. return new Scaffold(
  101. appBar: new AppBar(
  102. title: new Text('Saved Suggestions'),
  103. actions: <Widget>[
  104. new IconButton(icon: new Icon(Icons.list),onPressed: _nextTopics),
  105. ],
  106. ),
  107. body: new ListView(children: divided),
  108. );
  109. },
  110. ),
  111. );
  112. }
  113.  
  114. void _nextTopics() {
  115. Navigator.of(context).push(
  116. new MaterialPageRoute(
  117. builder: (context){
  118.  
  119. return new Scaffold(
  120. appBar: new AppBar(
  121. title: new Text('Next Topics - Layout'),
  122. ),
  123. body: _buildLayout(),
  124. );
  125. },
  126. ),
  127. );
  128. }
  129.  
  130. Widget _buildLayout() {
  131. return new ListView(
  132. children: <Widget>[
  133. //
  134. // Account Section
  135. //
  136. new Container(
  137. padding: const EdgeInsets.all(20.0),
  138. color: const Color(0xFFEEEEEE),
  139. child: new Text(
  140. 'Account',
  141. style: new TextStyle(
  142. fontWeight: FontWeight.bold,
  143. fontSize: 20.0,
  144. ),
  145. ),
  146. ),
  147. new Divider(color: Colors.grey),
  148. new ListTile(
  149. leading: new Icon(Icons.account_circle),
  150. title: new Text('Felix'),
  151. subtitle: new Text('felixkywong@gmail.com'),
  152. ),
  153. new Divider(color: Colors.grey),
  154. new ListTile(
  155. leading: new Icon(Icons.account_box),
  156. title: new Text('Personal Info'),
  157. trailing: new Icon(Icons.chevron_right),
  158. ),
  159. new Divider(color: Colors.grey),
  160. new ListTile(
  161. leading: new Icon(Icons.tune),
  162. title: new Text('Preferences'),
  163. trailing: new Icon(Icons.chevron_right),
  164. ),
  165. new Divider(color: Colors.grey),
  166. new ListTile(
  167. leading: new Icon(Icons.payment),
  168. title: new Text('Payments'),
  169. trailing: new Icon(Icons.chevron_right),
  170. ),
  171. new Divider(color: Colors.grey),
  172. new ListTile(
  173. leading: new Icon(Icons.check_circle_outline),
  174. title: new Text('Voice Match'),
  175. trailing: new Icon(Icons.chevron_right),
  176. ),
  177. new Divider(color: Colors.grey),
  178. //
  179. // Devices Section
  180. //
  181. new Container(
  182. padding: const EdgeInsets.all(20.0),
  183. color: const Color(0xFFEEEEEE),
  184. child: new Text(
  185. 'Devices',
  186. style: new TextStyle(
  187. fontWeight: FontWeight.bold,
  188. fontSize: 20.0,
  189. ),
  190. ),
  191. ),
  192. new Divider(color: Colors.grey),
  193. new ListTile(
  194. leading: new Icon(Icons.phone_iphone),
  195. title: new Text('Phone'),
  196. ),
  197. new Divider(color: Colors.grey),
  198. new ListTile(
  199. leading: new Icon(Icons.speaker),
  200. title: new Text('Home'),
  201. trailing: new Icon(Icons.chevron_right),
  202. ),
  203. new Divider(color: Colors.grey),
  204. new ListTile(
  205. leading: new Icon(Icons.headset),
  206. title: new Text('LE-Incognito Bose QC 35II(F'),
  207. trailing: new Icon(Icons.chevron_right),
  208. ),
  209. new Divider(color: Colors.grey),
  210. //
  211. // Services Section
  212. //
  213. new Container(
  214. padding: const EdgeInsets.all(20.0),
  215. color: const Color(0xFFEEEEEE),
  216. child: new Text(
  217. 'Services',
  218. style: new TextStyle(
  219. fontWeight: FontWeight.bold,
  220. fontSize: 20.0,
  221. ),
  222. ),
  223. ),
  224. new Divider(color: Colors.grey),
  225. new ListTile(
  226. leading: new Icon(Icons.music_note),
  227. title: new Text('Music'),
  228. ),
  229. new Divider(color: Colors.grey),
  230. new ListTile(
  231. leading: new Icon(Icons.lightbulb_outline),
  232. title: new Text('Home control'),
  233. trailing: new Icon(Icons.chevron_right),
  234. ),
  235. new Divider(color: Colors.grey),
  236. new ListTile(
  237. leading: new Icon(Icons.web),
  238. title: new Text('News'),
  239. trailing: new Icon(Icons.chevron_right),
  240. ),
  241. new Divider(color: Colors.grey),
  242. new ListTile(
  243. leading: new Icon(Icons.rounded_corner),
  244. title: new Text('Routines'),
  245. trailing: new Icon(Icons.chevron_right),
  246. ),
  247. new Divider(color: Colors.grey),
  248. new ListTile(
  249. leading: new Icon(Icons.cast),
  250. title: new Text('TVs and speakers'),
  251. trailing: new Icon(Icons.chevron_right),
  252. ),
  253. new Divider(color: Colors.grey),
  254. new ListTile(
  255. leading: new Icon(Icons.format_list_bulleted),
  256. title: new Text('Shopping list'),
  257. trailing: new Icon(Icons.chevron_right),
  258. ),
  259. new Divider(color: Colors.grey),
  260. new ListTile(
  261. leading: new Icon(Icons.format_list_bulleted),
  262. title: new Text('Purchases'),
  263. trailing: new Icon(Icons.chevron_right),
  264. ),
  265. new Divider(color: Colors.grey),
  266. new ListTile(
  267. leading: new Icon(Icons.format_list_bulleted),
  268. title: new Text('Reminders'),
  269. trailing: new Icon(Icons.chevron_right),
  270. ),
  271. new Divider(color: Colors.grey),
  272. new ListTile(
  273. leading: new Icon(Icons.comment),
  274. title: new Text('Shortcuts'),
  275. trailing: new Icon(Icons.chevron_right),
  276. ),
  277. new Divider(color: Colors.grey),
  278. new ListTile(
  279. leading: new Icon(Icons.ondemand_video),
  280. title: new Text('Videos and photos'),
  281. trailing: new Icon(Icons.chevron_right),
  282. ),
  283. new Divider(color: Colors.grey),
  284. ],
  285. );
  286. }
  287. /*
  288. return new Container(
  289. padding: const EdgeInsets.all(4.0),
  290. child: new Row(
  291. children: [
  292. new Container(
  293. padding: const EdgeInsets.all(20.0),
  294. decoration: const BoxDecoration(
  295. border: const Border(
  296. bottom: const BorderSide(width:1.0, color: const Color(0xFFF007F7F)),
  297. ),
  298. ),
  299. child: new Text(
  300. 'Account',
  301. style: new TextStyle(
  302. fontWeight: FontWeight.bold,
  303. fontSize: 20.0,
  304. ),
  305. ),
  306. ),
  307. ],
  308. ),
  309. );
  310. */
  311.  
  312.  
  313.  
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement