Files
TaskTracker/lib/NewProject.dart
2022-03-14 20:30:20 +05:30

483 lines
23 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:intl/intl.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'User.dart' as User;
import 'Data.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'DateTimeRangeCustom.dart';
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat durationFormat = DateFormat("HH:mm:ss");
class NewProject extends StatefulWidget {
const NewProject({Key? key}) : super(key: key);
@override
_NewProjectState createState() => _NewProjectState();
}
List<String> getCategoryNames() {
List<String> _cats = [];
User.categories.forEach((element) {
String name = element.name;
_cats.add(name);
});
return _cats;
}
bool multiLine = true;
String selectedCat = User.categories[0].name;
class _NewProjectState extends State<NewProject> {
TextEditingController nameController = TextEditingController();
bool productive = true;
Color pickerColor = Colors.blue;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('New Project')),
body: Container(
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.fromLTRB(20, 50, 20, 50),
child: Column(
children: [
Container(
padding: EdgeInsets.all(0),
child: Text('Project Name')),
Container(
padding: EdgeInsets.all(10),
child: TextField(
controller: nameController,
decoration: InputDecoration(
hintText:
'ex: Cool science project, Build a new game etc...',
border: OutlineInputBorder()),
),
),
Divider(),
Column(children: [
Container(
padding: EdgeInsets.all(0),
child: Text('Related Category')),
Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.symmetric(
horizontal: 12, vertical: 1),
decoration: BoxDecoration(
color: Colors.white10,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Colors.grey, width: 2)),
child: DropdownButton<String>(
dropdownColor: Colors.black,
iconSize: 30,
elevation: 10,
borderRadius: BorderRadius.circular(10),
value: selectedCat,
isExpanded: true,
items: getCategoryNames()
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? _value) {
setState(() {
selectedCat = _value!;
});
})),
Divider(),
Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('This project is',
style: TextStyle(fontSize: 18)),
FlutterSwitch(
width: 130,
height: 35.0,
valueFontSize: 15.0,
toggleSize: 25.0,
toggleColor: Colors.white70,
activeTextColor: Colors.white,
inactiveTextColor: Colors.white,
value: multiLine,
borderRadius: 30.0,
showOnOff: true,
activeText: 'Multi step',
inactiveText: 'Single step',
activeColor: Colors.deepOrange,
activeIcon: Icon(Icons.linear_scale,
color: Colors.orange),
inactiveIcon: Icon(Icons.check,
color: Colors.green),
inactiveColor: Colors.green,
onToggle: (val) {
setState(() {
multiLine = val;
print(
"Multi=Step : $multiLine");
});
},
)
])),
]),
],
))),
Container(
padding:
EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
flex: 5,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,
shape: StadiumBorder()),
onPressed: () {
setState(() {
Navigator.pop(context);
});
},
child: Text('Cancel',
style: TextStyle(fontSize: 20))))),
Expanded(
flex: 6,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.green,
shape: StadiumBorder()),
onPressed: () {
// add_action();
if (nameController.text.length > 3) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
NewProject2(
projectName:
nameController.text,
)));
} else {
showAlertDialog(context, 'Really?',
'Enter a valid name for this project!');
}
},
child: Text('Next',
style: TextStyle(fontSize: 20))))),
],
))
])));
}
void pickColor(BuildContext context) => showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Pick Color for Category'),
content: Column(mainAxisSize: MainAxisSize.min, children: [
MaterialPicker(
pickerColor: pickerColor,
onColorChanged: (color) {
setState(() {
pickerColor = color;
});
},
enableLabel: false,
portraitOnly: true,
),
TextButton(
child: Text('Select', style: TextStyle(fontSize: 20)),
onPressed: () => Navigator.of(context).pop(),
)
]),
));
void add_action() async {
String catName = nameController.value.text;
if (catName.length < 2) {
showAlertDialog(context, 'Category needs a name',
'Please enter a name for this category');
return;
}
var hex = '#${pickerColor.value.toRadixString(16)}';
await User.UserOperations.addCategory(catName, hex, productive);
Navigator.of(context).popUntil((route) {
return route.isFirst;
});
}
}
String _printDuration(Duration duration) {
String twoDigits(int n) => n.toString().padLeft(2, "0");
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
return "${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
}
showAlertDialog(BuildContext context, String title, String message) {
// set up the button
Widget okButton = TextButton(
child: Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Text(title),
content: Text(message),
actions: [
okButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
class NewProject2 extends StatefulWidget {
NewProject2({Key? key, this.projectName}) : super(key: key);
late String? projectName;
@override
State<NewProject2> createState() => _NewProject2State(pName: projectName);
}
class _NewProject2State extends State<NewProject2> {
bool knowEta = false;
int etaHours = 1;
List<ProjectStep> steps = [
ProjectStep('Step 1', 3),
ProjectStep('Step 2', 2),
ProjectStep('Ez Step', 1),
ProjectStep('Very hard', 10),
ProjectStep('Finishing', 5)
];
DateTime deadline = DateTime.now().add(Duration(days:7));
late String? projectName;
_NewProject2State({String? pName}) {
projectName = pName;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(projectName ?? 'Error')),
body: Container(
height: MediaQuery.of(context).size.height,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SingleChildScrollView(
child: Container(
padding: EdgeInsets.fromLTRB(20, 50, 20, 50),
child: (multiLine)
? Column(
children: [
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(10),
child: Text('List your steps down')
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white10,
),
padding: EdgeInsets.all(10),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child:Column(
children: printSteps(),
)
),
),
],
)
],
)
: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(10),
child: Text(
"Estimated Time to reach target")),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
InkWell(
onTap: () {
showDurationSelector(context,selectedHour: etaHours, onChange: (newVal){
etaHours = newVal.inHours;
knowEta=true;
setState(() {
});
print("Selected $newVal");
});
},
child: Container(
decoration: BoxDecoration(
color: (knowEta) ? Colors.green:Colors.white10,
borderRadius:
BorderRadius.circular(30),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 50, vertical: 10),
child: Text("${(knowEta)?etaHours:'?'} Hours"),
),
),
),InkWell(
onTap: (){
knowEta=false;
setState(() {
});
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: (knowEta) ? Colors.white10 :Colors.redAccent
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20,vertical: 10),
child: Text("I have no idea"),
)
),
)
],
),
SizedBox(
height: 20,
),
Container(
padding: EdgeInsets.all(8),
child: Text("Deadline")),
InkWell(
onTap: () {
DatePicker.showDatePicker(
context,
showTitleActions: true,
minTime: DateTime.now(),
theme: DatePickerTheme(backgroundColor: Colors.white),
onChanged: (date) {
// print('change $date');
}, onConfirm: (date) {
setState(() {
if(deadline.isAfter(DateTime.now())){
deadline=date;
}else{
showAlertDialog(context, 'Come on!', 'Deadline was passed?');
}
});
},
currentTime: deadline,
locale: LocaleType.en);
setState(() {
});
},
child: Container(
decoration: BoxDecoration(
color: Colors.white10,
borderRadius:
BorderRadius.circular(30),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 100, vertical: 10),
child: Text(DateFormat("MMMM dd yyyy").format(deadline)),
),
),
),
],
))),
Container(
padding:
EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded(
flex: 5,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,
shape: StadiumBorder()),
onPressed: () {
setState(() {
Navigator.pop(context);
});
},
child: Text('Back',
style: TextStyle(fontSize: 20))))),
Expanded(
flex: 6,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.green,
shape: StadiumBorder()),
onPressed: () {},
child: Text('Next',
style: TextStyle(fontSize: 20))))),
],
))
])));
}
int selectedStep = 0;
List<Widget> printSteps(){
List<Widget> _steps = [];
for(int i=0; i < steps.)
_steps.add(
InkWell(onTap:(){se},child: Container(padding:EdgeInsets.symmetric(horizontal: 10,vertical: 2),child: Row(mainAxisSize:MainAxisSize.max,mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [Text(value.stepName), Icon(Icons.timelapse), Text(value.eta.toString() + " Hours")],))));
}
return _steps;
}
}