I added time_planner into my flutter project ('package:time_planner/time_planner.dart'; ) . Yes, it is working properly in my application.
But I just wanted to know how can I create a new task for a hour/minute by long pressing or tapping on that empty cell to trigger adding a new task.
I can add a new task from pressing a separate button and entering (or picking from a time picker tool) the time (hour-minute) values.
Here is the code I used:
import 'package:flutter/material.dart';
import 'package:time_planner/time_planner.dart';
class timeselect extends StatefulWidget {
@override
_timeselectState createState() => _timeselectState();
}
class _timeselectState extends State<timeselect> {
DateTime selectedDate = DateTime.now();
Future<void> _selectDate(BuildContext context) async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2022, 8),
lastDate: DateTime(2024));
if (picked != null && picked != selectedDate) {
setState(() {
selectedDate = picked;
});
}
}
void _addTask(BuildContext context)
{
setState(() {
TimePlannerTask(
color: const Color.fromARGB(255, 188, 117, 117),
dateTime: TimePlannerDateTime(
day: 11,
hour: 18,
minutes: 35,),
minutesDuration: 45,
daysDuration: 1,
onTap: () {
},
child: Text(
'this is a demo',
style: TextStyle(color: Colors.grey[350], fontSize: 12),
),
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 11),
child: Column (
children: [
ElevatedButton(
child: const Text('Today''s Timetable...'),
onPressed: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
List<TimePlannerTask> tasks = [
TimePlannerTask(
color: Color.fromARGB(255, 144, 0, 255),
dateTime: TimePlannerDateTime(day: 0, hour: 09, minutes: 15),
minutesDuration: 50,
onTap: () {},
child: const Text(
'sample text here',
style: TextStyle(color: const Color.fromARGB(255, 255, 255, 255), fontSize: 12),
),),),];
return Container(
height: MediaQuery.of(context).size.height * 0.8,
color: const Color.fromARGB(255, 255, 255, 255),
child: Center(
child: Column(
children: <Widget>[
SizedBox(
height: 600,
child: TimePlanner(
style: TimePlannerStyle(
cellHeight: 60,
cellWidth: 291,
dividerColor: Colors.white,
showScrollBar: true,
horizontalTaskPadding: 1,
borderRadius: const BorderRadius.all(Radius.circular(5)),
),
currentTimeAnimation: true,
startHour: 8,
endHour: 20,
headers: const [
TimePlannerTitle(
date: "3/10/2023",
title: "sunday",
),
],
tasks: tasks,
),
),
],
),
),
);
},
);
},
),
]
),
)
);
}