时间表可点按,可长按

zhangrenshu
LRC 2 years ago
parent b7f39dab8d
commit 6d2ad8182b

@ -125,8 +125,8 @@ class CourseController {
return await CourseDao().deleteAllCourses();
}
Future<int> deleteCourse(int id) async {
return await CourseDao().deleteCourseById(id);
Future<int> deleteCourse(int courseId) async {
return await CourseDao().deleteCourseByCourseId(courseId);
}
}

@ -64,9 +64,8 @@ class MyDatabase {
workId INTEGER NOT NULL,
teamId INTEGER NOT NULL,
name TEXT NOT NULL,
status TEXT NOT NULL,
status TEXT,
workContent TEXT NOT NULL,
functionaryId INTEGER NOT NULL,
endTime TEXT NOT NULL,
startTime TEXT NOT NULL
);
@ -81,9 +80,9 @@ class MyDatabase {
id INTEGER PRIMARY KEY,
clockId INTEGER NOT NULL,
userId INTEGER NOT NULL,
text TEXT NOT NULL,
img TEXT NOT NULL,
music TEXT NOT NULL
text TEXT,
img TEXT,
music TEXT
);
''');
}
@ -95,7 +94,7 @@ class MyDatabase {
id INTEGER PRIMARY KEY,
taskId INTEGER NOT NULL,
userId INTEGER NOT NULL,
content TEXT NOT NULL,
content TEXT,
name TEXT NOT NULL,
startTime TEXT NOT NULL,
endTime TEXT NOT NULL
@ -111,10 +110,10 @@ class MyDatabase {
userId INTEGER,
courseId INTEGER NOT NULL,
name TEXT NOT NULL,
credit REAL NOT NULL,
teacher TEXT NOT NULL,
location TEXT NOT NULL,
remark TEXT NOT NULL,
credit REAL,
teacher TEXT,
location TEXT,
remark TEXT,
start TEXT NOT NULL,
end TEXT NOT NULL
);
@ -128,7 +127,7 @@ class MyDatabase {
id INTEGER PRIMARY KEY,
leaderId INTEGER NOT NULL,
teamName TEXT NOT NULL,
maxNumber INTEGER NOT NULL,
maxNumber INTEGER,
introduce TEXT
);
''');

@ -30,7 +30,9 @@ import 'package:timemanagerapp/database/MyDatebase.dart';
import '../controller/TaskController.dart';
import '../controller/WorkController.dart';
import '../entity/Task.dart';
import '../setting/Setting.dart';
import '../util/dataUtil.dart';
class TestWidget extends StatefulWidget {
@ -106,6 +108,16 @@ class _TestWidgetState extends State<TestWidget> {
endTime: DateTime.now().add(Duration(hours: 2)))),
child: Text('插入一个测试课程'),
),
ElevatedButton(
onPressed: () async => taskController.insertTask(Task(
userId: 1,
taskId: await IdGenerator().generateId(),
name: "测试个人计划",
startTime: DateTime.now(),
endTime: DateTime.now().add(Duration(hours: 2)),
content: '测试个人计划内容')),
child: Text('插入一个测试个人计划'),
),
ElevatedButton(
onPressed: () {
courseController.getCourses().then((courses) {

@ -25,14 +25,15 @@ class TimetableWidgetState extends State<TimetableWidget> {
int firstInit = 0;
//
late TimetableWidgetController timetableWidgetController = TimetableWidgetController();
late TimetableWidgetController timetableWidgetController =
TimetableWidgetController();
late CourseController courseController = CourseController.getInstance();
late TaskController taskController = TaskController();
late List timeBlockList = [];
List taskList = [];
Map<int, List> timeBlockWeekMap = {};
//
var weekList = ['', '', '', '', '', '', ''];
//
@ -73,9 +74,7 @@ class TimetableWidgetState extends State<TimetableWidget> {
TimetableWidgetState({required this.deviceWidth});
updateDateByWeekCount() {
}
updateDateByWeekCount() {}
Future<void> futureDo() async {
print('开始futureDo');
@ -83,7 +82,6 @@ class TimetableWidgetState extends State<TimetableWidget> {
//
courseList = await courseController.getCourses();
taskList = await taskController.getTasks();
}
//
@ -92,7 +90,7 @@ class TimetableWidgetState extends State<TimetableWidget> {
super.initState();
}
dataInitAfterFutherDo(){
dataInitAfterFutherDo() {
//
timeBlockWeekMap = {};
timeBlockList = [];
@ -102,7 +100,8 @@ class TimetableWidgetState extends State<TimetableWidget> {
timeBlockList.addAll(courseList);
timeBlockList.addAll(taskList);
timeBlockWeekMap = timetableWidgetController.transformCourseMap(timeBlockList);
timeBlockWeekMap =
timetableWidgetController.transformCourseMap(timeBlockList);
//
var mondayTime = timetableWidgetController.getmondayTime();
@ -115,18 +114,19 @@ class TimetableWidgetState extends State<TimetableWidget> {
}
//
positions = timetableWidgetController.convertTimeList(timePoints, deviceWidth);
positions =
timetableWidgetController.convertTimeList(timePoints, deviceWidth);
}
updateAfterFutherDo(){
updateAfterFutherDo() {
timeBlockWeekMap = {};
timeBlockList = [];
timeBlockList.addAll(courseList);
timeBlockList.addAll(taskList);
timeBlockWeekMap = timetableWidgetController.transformCourseMap(timeBlockList);//
timeBlockWeekMap =
timetableWidgetController.transformCourseMap(timeBlockList); //
var mondayTime = timetableWidgetController.getmondayTime();
//
@ -141,238 +141,256 @@ class TimetableWidgetState extends State<TimetableWidget> {
@override
Widget build(BuildContext contexvoidt) {
return Consumer<TimeProvider>(
builder: (ctx, timePro, child) {
print('Rebuild timePro');
return FutureBuilder<void>(
future: futureDo(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
//
if (snapshot.connectionState == ConnectionState.done) {
if(firstInit == 0){ //
dataInitAfterFutherDo();
firstInit = 1;
}else{ //
updateAfterFutherDo();
}
return RefreshIndicator(
onRefresh: () {
print('下拉refresh');
return futureDo().then((value) => setState(() {}));
},
child: GestureDetector(
onHorizontalDragEnd: (details) {
if (details.primaryVelocity! > 0) {
//
setState(() {
weekCount--;
updateDateByWeekCount();
});
} else if (details.primaryVelocity! < 0) {
//
setState(() {
weekCount++;
updateDateByWeekCount();
});
}
},
child: Column(
mainAxisAlignment: MainAxisAlignment.start, //
children: [
SizedBox(
//
//
child: GridView.builder(
shrinkWrap: true,
//
physics: NeverScrollableScrollPhysics(),
//
itemCount: 8,
gridDelegate:
return Consumer<TimeProvider>(builder: (ctx, timePro, child) {
print('Rebuild timePro');
return FutureBuilder<void>(
future: futureDo(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
//
if (snapshot.connectionState == ConnectionState.done) {
if (firstInit == 0) {
//
dataInitAfterFutherDo();
firstInit = 1;
} else {
//
updateAfterFutherDo();
}
return RefreshIndicator(
onRefresh: () {
print('下拉refresh');
return futureDo().then((value) => setState(() {}));
},
child: GestureDetector(
onHorizontalDragEnd: (details) {
if (details.primaryVelocity! > 0) {
//
setState(() {
weekCount--;
updateDateByWeekCount();
});
} else if (details.primaryVelocity! < 0) {
//
setState(() {
weekCount++;
updateDateByWeekCount();
});
}
},
child: Column(
mainAxisAlignment: MainAxisAlignment.start, //
children: [
SizedBox(
//
//
child: GridView.builder(
shrinkWrap: true,
//
physics: NeverScrollableScrollPhysics(),
//
itemCount: 8,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 8, childAspectRatio: 1 / 1),
//
itemBuilder: (BuildContext context, int index) {
//item
return Container(
color: index == this.currentWeekDayIndex
? Color(0xf7f7f7) //
: Colors.white,
child: Center(
child: index == 0
? Column(
//
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
// height: 10,
// width: 6,
child: Text(
'' +
weekCount.toString() +
'', //
//
itemBuilder: (BuildContext context, int index) {
//item
return Container(
color: index == this.currentWeekDayIndex
? Color(0xf7f7f7) //
: Colors.white,
child: Center(
child: index == 0
? Column(
//
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
// height: 10,
// width: 6,
child: Text(
'' +
weekCount.toString() +
'', //
style: TextStyle(
fontSize: 12,
color: currentWeek ==
weekCount //
? Colors.amber
: Colors.black87)),
),
],
)
: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(weekList[index - 1], //
style: TextStyle(
fontSize: 14,
color: index ==
currentWeekDayIndex //
? Colors.lightBlue
: Colors.black87)),
SizedBox(
height: 5,
),
Text(dateListstr[index - 1], //
style: TextStyle(
fontSize: 12,
color: currentWeek ==
weekCount //
? Colors.amber
color: index ==
currentWeekDayIndex //
? Colors.lightBlue
: Colors.black87)),
],
),
),
);
}),
),
//stack
Expanded(
child: SingleChildScrollView(
child: Row(
children: [
//stack
Container(
width: deviceWidth,
height: 2000,
child: Stack(
alignment: Alignment.center,
children: [
// Stack
Positioned(
top: 0,
left: 0,
child: Container(
width: deviceWidth,
height: 2000,
child: Stack(
children: List.generate(
//
positions.length,
(index) => Positioned(
top: positions[index].dy,
left: positions[index].dx,
child: Row(
children: [
Text(
timePoints[index]
.hour
.toString()
.padLeft(2, '0') +
':' +
timePoints[index]
.minute
.toString()
.padLeft(2, '0'),
),
Container(
width: deviceWidth * 0.04,
height: 10,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.amber,
width: 2,
),
),
),
Container(
width: deviceWidth * 0.84,
height: 2,
color: const Color.fromARGB(
255, 136, 61, 61),
),
],
),
),
),
],
)
: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(weekList[index - 1], //
style: TextStyle(
fontSize: 14,
color: index ==
currentWeekDayIndex //
? Colors.lightBlue
: Colors.black87)),
SizedBox(
height: 5,
),
Text(dateListstr[index - 1], //
style: TextStyle(
fontSize: 12,
color: index ==
currentWeekDayIndex //
? Colors.lightBlue
: Colors.black87)),
],
),
),
);
}),
),
//stack
Expanded(
child: SingleChildScrollView(
child: Row(
children: [
//stack
Container(
width: deviceWidth,
height: 2000,
),
)),
//Stack
Container(
constraints: BoxConstraints
.expand(), // 使constraints
// width: 390,
// height: 2000,
child: Stack(
alignment: Alignment.center,
children: [
// Stack
Positioned(
top: 0,
left: 0,
child: Container(
width: deviceWidth,
height: 2000,
child: Stack(
children: List.generate(
//
positions.length,
(index) => Positioned(
top: positions[index].dy,
left: positions[index].dx,
child: Row(
children: [
Text(
timePoints[index]
.hour
.toString()
.padLeft(2, '0') +
':' +
timePoints[index]
.minute
.toString()
.padLeft(2, '0'),
),
Container(
width: deviceWidth * 0.04,
height: 10,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.amber,
width: 2,
),
),
),
Container(
width: deviceWidth * 0.84,
height: 2,
color: const Color.fromARGB(
255, 136, 61, 61),
),
],
),
children: List.generate(
timeBlockWeekMap
.containsKey(weekCount)
? timeBlockWeekMap[weekCount]!
.length
: 0,
(index) {
var currentItem = timeBlockWeekMap[
weekCount]![index];
return Positioned(
top: timetableWidgetController
.getdy(currentItem) +
10,
left: timetableWidgetController
.getdx(currentItem) +
deviceWidth * 0.15,
child: SingleChildScrollView(
child: Container(
width: deviceWidth * 0.115,
height:
timetableWidgetController
.getHeight(
currentItem),
decoration: BoxDecoration(
color: getItemColor(
currentItem),
borderRadius:
BorderRadius.all(
Radius.circular(10.0),
),
),
child: SingleChildScrollView(
child: Column(
children: [
if (currentItem
is Course)
CouresBlockContenWidget(
currentItem:
currentItem),
if (currentItem is Task)
TaskBlockContentWidget(
currentItem:
currentItem),
if (currentItem is Work)
WorkBlockContentWidget(
currentItem:
currentItem),
],
),
),
),
)),
//Stack
Container(
constraints: BoxConstraints
.expand(), // 使constraints
// width: 390,
// height: 2000,
child: Stack(
children: List.generate(
timeBlockWeekMap.containsKey(weekCount)
? timeBlockWeekMap[weekCount]!.length
: 0,
(index) {
var currentItem = timeBlockWeekMap[weekCount]![index];
return Positioned(
top: timetableWidgetController.getdy(currentItem) + 10,
left: timetableWidgetController.getdx(currentItem) + deviceWidth * 0.15,
child: SingleChildScrollView(
child: Container(
width: deviceWidth * 0.115,
height: timetableWidgetController.getHeight(currentItem),
decoration: BoxDecoration(
color: getItemColor(currentItem),
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
),
child: SingleChildScrollView(
child: Column(
children: [
if (currentItem is Course)
CouresBlockContenWidget(currentItem: currentItem),
if (currentItem is Task)
TaskBlockContentWidget(currentItem: currentItem),
if (currentItem is Work)
WorkBlockContentWidget(currentItem: currentItem),
],
),
),
),
),
);
},
),
))
],
),
),
],
),
))
],
),
),
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
});
}
);
),
);
},
),
))
],
),
),
],
),
))
],
),
),
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
});
});
}
//
@ -386,7 +404,106 @@ class TimetableWidgetState extends State<TimetableWidget> {
}
return Colors.tealAccent; //
}
}
class BlockGestureWidget extends StatelessWidget {
const BlockGestureWidget({
super.key,
required this.currentItem,
required this.blockGestureWidgetChilld,
});
final currentItem;
final blockGestureWidgetChilld;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
//
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
// currentItem
title: Text(currentItem.name),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
if (currentItem is Course) ...{
Text('老师: ${(currentItem as Course).teacher ?? ""}'),
Text('地点: ${(currentItem as Course).location ?? ""}'),
Text('开始时间: ${(currentItem as Course).startTime.toString()}'),
Text('结束时间: ${(currentItem as Course).endTime.toString()}'),
Text('备注: ${(currentItem as Course).remark ?? ""}'),
} else if (currentItem is Task) ...{
Text('内容: ${(currentItem as Task).content ?? ""}'),
Text('开始时间: ${(currentItem as Task).startTime.toString()}'),
Text('结束时间: ${(currentItem as Task).endTime.toString()}'),
} else if (currentItem is Work) ...{
Text('工作内容: ${(currentItem as Work).workContent ?? ""}'),
Text('开始时间: ${(currentItem as Work).startTime.toString()}'),
Text('结束时间: ${(currentItem as Work).endTime.toString()}'),
}
],
),
),
actions: <Widget>[
TextButton(
child: Text('关闭'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
},
onLongPress: () {
//
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('选择操作'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: () {
// TODO:
if (currentItem is Course) {
} else if (currentItem is Task) {
} else {}
Navigator.of(context).pop();
},
child: Text('编辑'),
),
ElevatedButton(
onPressed: () {
// TODO:
if (currentItem is Course) {
CourseController()
.deleteCourse((currentItem as Course).getCourseId);
} else if (currentItem is Task) {
TaskController().deleteTaskByTaskid(
(currentItem as Task).getTaskId);
} else {}
Navigator.of(context).pop();
},
child: Text('删除'),
),
SizedBox(height: 10),
],
),
);
},
);
},
child: blockGestureWidgetChilld,
);
}
}
class CouresBlockContenWidget extends StatelessWidget {
@ -399,56 +516,59 @@ class CouresBlockContenWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
(currentItem as Course).name,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
return BlockGestureWidget(
currentItem: currentItem,
blockGestureWidgetChilld: Column(
children: [
Text(
(currentItem as Course).name,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Course).teacher,
style: TextStyle(
fontSize: 8,
Text(
(currentItem as Course).teacher,
style: TextStyle(
fontSize: 8,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Course).location,
style: TextStyle(
fontSize: 10,
Text(
(currentItem as Course).location,
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Course).startTime.hour.toString() +
':' +
(currentItem as Course).startTime.minute.toString(),
style: TextStyle(
fontSize: 10,
Text(
(currentItem as Course).startTime.hour.toString() +
':' +
(currentItem as Course).startTime.minute.toString(),
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Course).endTime.hour.toString() +
':' +
(currentItem as Course).endTime.minute.toString(),
style: TextStyle(
fontSize: 10,
Text(
(currentItem as Course).endTime.hour.toString() +
':' +
(currentItem as Course).endTime.minute.toString(),
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Course).remark,
style: TextStyle(
fontSize: 10,
Text(
(currentItem as Course).remark,
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
],
],
),
);
}
}
@ -463,38 +583,41 @@ class TaskBlockContentWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
(currentItem as Task).name,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
return BlockGestureWidget(
currentItem: currentItem,
blockGestureWidgetChilld: Column(
children: [
Text(
(currentItem as Task).name,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Task).content,
style: TextStyle(
fontSize: 8,
Text(
(currentItem as Task).content,
style: TextStyle(
fontSize: 8,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Task).startTime.toString(),
style: TextStyle(
fontSize: 10,
Text(
(currentItem as Task).startTime.toString(),
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
(currentItem as Task).endTime.toString(),
style: TextStyle(
fontSize: 10,
Text(
(currentItem as Task).endTime.toString(),
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
],
],
),
);
}
}
@ -509,38 +632,41 @@ class WorkBlockContentWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(
currentItem.name,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
return BlockGestureWidget(
currentItem: currentItem,
blockGestureWidgetChilld: Column(
children: [
Text(
currentItem.name,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
currentItem.workContent,
style: TextStyle(
fontSize: 8,
Text(
currentItem.workContent,
style: TextStyle(
fontSize: 8,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
currentItem.startTime.toString(),
style: TextStyle(
fontSize: 10,
Text(
currentItem.startTime.toString(),
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
Text(
currentItem.endTime.toString(),
style: TextStyle(
fontSize: 10,
Text(
currentItem.endTime.toString(),
style: TextStyle(
fontSize: 10,
),
overflow: TextOverflow.clip,
),
overflow: TextOverflow.clip,
),
],
],
),
);
}
}
}

Loading…
Cancel
Save