Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- class Activity extends StatefulWidget {
- @override
- _ActivityState createState() => new _ActivityState();
- }
- class _ActivityState extends State<Activity> {
- int hours = 8;
- Map<int, bool> hourData = {};
- List<Map<String, String>> projects = [
- {"id": "proma", "name": "PROMA"},
- {"id": "mcm", "name": "MCM"},
- {"id": "emr", "name": "EMR"},
- {"id": "adar", "name": "ADAR"},
- {"id": "masterchild", "name": "Master-Child"},
- {"id": "p2l", "name": "Pick to Light"},
- {"id": "aaps", "name": "AAPS"},
- {"id": "vaswani", "name": "Vaswani"},
- {"id": "self", "name": "Self Study"},
- {"id": "leave", "name": "Leave"},
- ];
- Map<int, String> data = {};
- initState() {
- // initialize hourData
- reset();
- super.initState();
- }
- // actions
- selectProject(int hour, String id) {
- setState(() {
- if (hourData[hour] != null && data[hour] == id) {
- hourData[hour] = !hourData[hour];
- } else {
- hourData[hour] = true;
- }
- if (hourData[hour]) {
- data[hour] = id;
- } else {
- data[hour] = null;
- }
- });
- print("selected project");
- print(hour);
- print(data[hour]);
- print(hourData[hour]);
- }
- // projects row
- Widget projectsRow(int hour) {
- return new Container(
- height: 50.0,
- child: new ListView(
- scrollDirection: Axis.horizontal,
- children: projects.map((item) {
- return new RaisedButton(
- color: hourData[hour] == true && data[hour] == item['id']
- ? Colors.teal
- : Theme.of(context).buttonColor,
- onPressed: () {
- selectProject(hour, item['id']);
- },
- child: new Text(
- item["name"],
- style: new TextStyle(
- color: hourData[hour] == true && data[hour] == item['id']
- ? Colors.white
- : Colors.black,
- ),
- ),
- );
- }).toList()),
- );
- }
- Widget hourCell(int hour) {
- return new Container(
- height: 50.0,
- margin: const EdgeInsets.only(bottom: 0.5, right: 1.0),
- padding: const EdgeInsets.all(16.0),
- decoration: hourData[hour] == true
- ? new BoxDecoration(color: Colors.teal)
- : new BoxDecoration(color: Colors.grey),
- child: new Text(
- hour.toString(),
- style: const TextStyle(fontSize: 18.0, color: Colors.white),
- ),
- );
- }
- // remarks row
- Widget showRemarks() {
- return new Row(
- children: [
- new TextFormField(
- decoration: new InputDecoration(hintText: "Enter remarks"),
- maxLines: 3,
- ),
- new RaisedButton(child: new Text("Submit"))
- ],
- );
- }
- // build form
- Widget buildForm() {
- return new Column(
- children: <Widget>[
- new Container(
- padding: const EdgeInsets.symmetric(vertical: 5.0),
- child: new Text("Please select your activities by the hour."),
- ),
- new Expanded(
- child: new ListView.builder(
- itemCount: hours,
- itemBuilder: (context, i) {
- return new Row(children: <Widget>[
- hourCell(i + 1),
- new Expanded(child: projectsRow(i + 1)),
- ]);
- },
- ),
- ),
- // showRemarks()
- ],
- );
- }
- // action buttons
- List<Widget> actionButtons() {
- List<Widget> buttons = [];
- // date-picker
- IconButton btnDatePicker = new IconButton(icon: new Icon(Icons.date_range));
- buttons.add(btnDatePicker);
- // reset button
- IconButton btnReset = new IconButton(
- icon: new Icon(Icons.restore),
- onPressed: reset,
- );
- buttons.add(btnReset);
- // submit button
- IconButton btnSave = new IconButton(
- icon: new Icon(Icons.send),
- onPressed: submit,
- );
- buttons.add(btnSave);
- return (buttons);
- }
- // submit form
- submit() {}
- // reset form
- reset() {
- for (int i = 1; i <= hours; i++) {
- setState(() {
- hourData[i] = false;
- data[i] = null;
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar:
- new AppBar(title: new Text("Activities"), actions: actionButtons()),
- body: buildForm());
- }
- }
Add Comment
Please, Sign In to add comment