Guest User

Untitled

a guest
Apr 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class Activity extends StatefulWidget {
  4. @override
  5. _ActivityState createState() => new _ActivityState();
  6. }
  7.  
  8. class _ActivityState extends State<Activity> {
  9. int hours = 8;
  10. Map<int, bool> hourData = {};
  11. List<Map<String, String>> projects = [
  12. {"id": "proma", "name": "PROMA"},
  13. {"id": "mcm", "name": "MCM"},
  14. {"id": "emr", "name": "EMR"},
  15. {"id": "adar", "name": "ADAR"},
  16. {"id": "masterchild", "name": "Master-Child"},
  17. {"id": "p2l", "name": "Pick to Light"},
  18. {"id": "aaps", "name": "AAPS"},
  19. {"id": "vaswani", "name": "Vaswani"},
  20. {"id": "self", "name": "Self Study"},
  21. {"id": "leave", "name": "Leave"},
  22. ];
  23. Map<int, String> data = {};
  24.  
  25. initState() {
  26. // initialize hourData
  27. reset();
  28. super.initState();
  29. }
  30.  
  31. // actions
  32. selectProject(int hour, String id) {
  33. setState(() {
  34. if (hourData[hour] != null && data[hour] == id) {
  35. hourData[hour] = !hourData[hour];
  36. } else {
  37. hourData[hour] = true;
  38. }
  39. if (hourData[hour]) {
  40. data[hour] = id;
  41. } else {
  42. data[hour] = null;
  43. }
  44. });
  45. print("selected project");
  46. print(hour);
  47. print(data[hour]);
  48. print(hourData[hour]);
  49. }
  50.  
  51. // projects row
  52. Widget projectsRow(int hour) {
  53. return new Container(
  54. height: 50.0,
  55. child: new ListView(
  56. scrollDirection: Axis.horizontal,
  57. children: projects.map((item) {
  58. return new RaisedButton(
  59. color: hourData[hour] == true && data[hour] == item['id']
  60. ? Colors.teal
  61. : Theme.of(context).buttonColor,
  62. onPressed: () {
  63. selectProject(hour, item['id']);
  64. },
  65. child: new Text(
  66. item["name"],
  67. style: new TextStyle(
  68. color: hourData[hour] == true && data[hour] == item['id']
  69. ? Colors.white
  70. : Colors.black,
  71. ),
  72. ),
  73. );
  74. }).toList()),
  75. );
  76. }
  77.  
  78. Widget hourCell(int hour) {
  79. return new Container(
  80. height: 50.0,
  81. margin: const EdgeInsets.only(bottom: 0.5, right: 1.0),
  82. padding: const EdgeInsets.all(16.0),
  83. decoration: hourData[hour] == true
  84. ? new BoxDecoration(color: Colors.teal)
  85. : new BoxDecoration(color: Colors.grey),
  86. child: new Text(
  87. hour.toString(),
  88. style: const TextStyle(fontSize: 18.0, color: Colors.white),
  89. ),
  90. );
  91. }
  92.  
  93. // remarks row
  94. Widget showRemarks() {
  95. return new Row(
  96. children: [
  97. new TextFormField(
  98. decoration: new InputDecoration(hintText: "Enter remarks"),
  99. maxLines: 3,
  100. ),
  101. new RaisedButton(child: new Text("Submit"))
  102. ],
  103. );
  104. }
  105.  
  106. // build form
  107. Widget buildForm() {
  108. return new Column(
  109. children: <Widget>[
  110. new Container(
  111. padding: const EdgeInsets.symmetric(vertical: 5.0),
  112. child: new Text("Please select your activities by the hour."),
  113. ),
  114. new Expanded(
  115. child: new ListView.builder(
  116. itemCount: hours,
  117. itemBuilder: (context, i) {
  118. return new Row(children: <Widget>[
  119. hourCell(i + 1),
  120. new Expanded(child: projectsRow(i + 1)),
  121. ]);
  122. },
  123. ),
  124. ),
  125. // showRemarks()
  126. ],
  127. );
  128. }
  129.  
  130. // action buttons
  131. List<Widget> actionButtons() {
  132. List<Widget> buttons = [];
  133.  
  134. // date-picker
  135. IconButton btnDatePicker = new IconButton(icon: new Icon(Icons.date_range));
  136. buttons.add(btnDatePicker);
  137.  
  138. // reset button
  139. IconButton btnReset = new IconButton(
  140. icon: new Icon(Icons.restore),
  141. onPressed: reset,
  142. );
  143. buttons.add(btnReset);
  144.  
  145. // submit button
  146. IconButton btnSave = new IconButton(
  147. icon: new Icon(Icons.send),
  148. onPressed: submit,
  149. );
  150. buttons.add(btnSave);
  151.  
  152. return (buttons);
  153. }
  154.  
  155. // submit form
  156. submit() {}
  157.  
  158. // reset form
  159. reset() {
  160. for (int i = 1; i <= hours; i++) {
  161. setState(() {
  162. hourData[i] = false;
  163. data[i] = null;
  164. });
  165. }
  166. }
  167.  
  168. @override
  169. Widget build(BuildContext context) {
  170. return new Scaffold(
  171. appBar:
  172. new AppBar(title: new Text("Activities"), actions: actionButtons()),
  173. body: buildForm());
  174. }
  175. }
Add Comment
Please, Sign In to add comment