|
|
|
|
@ -1,3 +1,25 @@
|
|
|
|
|
/*
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:timemanagerapp/wighets/AddCourseFormWidget.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
runApp(MyApp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
home: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: Text('添加课程'),
|
|
|
|
|
),
|
|
|
|
|
body: AddCourseFormWidget(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:sqflite/sqflite.dart';
|
|
|
|
|
import 'package:timemanagerapp/controller/CourseController.dart';
|
|
|
|
|
@ -14,20 +36,16 @@ import '../tests/database_test.dart';
|
|
|
|
|
import 'AddCourseFormWidget.dart';
|
|
|
|
|
|
|
|
|
|
class TestWidget extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TestWidget({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_TestPageState createState() => _TestPageState();
|
|
|
|
|
_HomePageState createState() => _HomePageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _TestPageState extends State<TestWidget> {
|
|
|
|
|
|
|
|
|
|
class _HomePageState extends State<TestWidget> {
|
|
|
|
|
late UserController userController;
|
|
|
|
|
late CourseController courseController;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
@ -36,165 +54,57 @@ class _TestPageState extends State<TestWidget> {
|
|
|
|
|
courseController = CourseController.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleAddCourse() {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AddCourseRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleAddTask() {
|
|
|
|
|
// Implement the functionality for adding a task here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleAddTeam() {
|
|
|
|
|
// Implement the functionality for adding a team here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleMenu() {
|
|
|
|
|
// Implement the functionality for the menu here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: Colors.blue,
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
|
return Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: userController.deleteAllUsers,
|
|
|
|
|
child: Text('删除所有用户'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () => userController.insertUser(User(
|
|
|
|
|
teamId: 3231, username: "测试用户", password: "23243", role: 1)),
|
|
|
|
|
child: Text('插入一个测试用户'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: const Text('+功能'),
|
|
|
|
|
content: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// 导航到AddCourseFormWidget页面
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AddCourseRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text('添加课程'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// 导航到AddCourseFormWidget页面
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AddCourseRoute(); //改成任务
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text('添加任务'),
|
|
|
|
|
userController.getUsers().then((users) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('用户列表'),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: users
|
|
|
|
|
.map((user) => ListTile(
|
|
|
|
|
title: Text(user['username']),
|
|
|
|
|
subtitle: Text(user.toString()),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Text('显示用户列表'),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.more),
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.group_add),
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
),
|
|
|
|
|
Builder(
|
|
|
|
|
builder: (context) => IconButton(
|
|
|
|
|
icon: const Icon(Icons.more_horiz),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Scaffold.of(context).openEndDrawer(); // Open the right drawer
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: courseController.deleteAllCourses,
|
|
|
|
|
child: Text('删除所有课程'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
endDrawer: Drawer(
|
|
|
|
|
// Use endDrawer to place the drawer on the right side
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
UserAccountsDrawerHeader(
|
|
|
|
|
accountName: Text('Username'),
|
|
|
|
|
accountEmail: Text('user@example.com'),
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('删除用户'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.pop(context); // Close the drawer
|
|
|
|
|
userController.deleteAllUsers();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('插入用户'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.pop(context); // Close the drawer
|
|
|
|
|
userController.insertUser(User(
|
|
|
|
|
teamId: 3231,
|
|
|
|
|
username: "嘉豪急啊急啊",
|
|
|
|
|
password: "23243",
|
|
|
|
|
role: 2341,
|
|
|
|
|
));
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('获取用户列表'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.pop(context); // Close the drawer
|
|
|
|
|
userController.getUsers().then((users) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('用户列表'),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: users
|
|
|
|
|
.map((user) => ListTile(
|
|
|
|
|
title: Text(user['username']),
|
|
|
|
|
subtitle: Text(user.toString()),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('删除课程'),
|
|
|
|
|
onTap: courseController.deleteAllCourses,
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('导入课程(待开发)'),
|
|
|
|
|
onTap: () => courseController.autoImportCours(1, "1", 1, 1),
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('插入课程'),
|
|
|
|
|
onTap: () => courseController.insertCourse(Course(
|
|
|
|
|
// ElevatedButton(
|
|
|
|
|
// onPressed: () => courseController.autoImportCours(jsonstr),
|
|
|
|
|
// child: Text('导入课程(待开发)'),
|
|
|
|
|
// ),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () => courseController.insertCourse(Course(
|
|
|
|
|
userId: 1,
|
|
|
|
|
courseId: 2,
|
|
|
|
|
name: "测试课",
|
|
|
|
|
@ -203,75 +113,135 @@ class _TestPageState extends State<TestWidget> {
|
|
|
|
|
location: "638",
|
|
|
|
|
remark: "happy",
|
|
|
|
|
start: DateTime.now(),
|
|
|
|
|
end: DateTime.now().add(Duration(hours: 2)),
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('获取课程列表'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
courseController.getCourses().then((courses) {
|
|
|
|
|
print(courses.length);
|
|
|
|
|
});
|
|
|
|
|
courseController.getCourses().then((courses) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('课程列表'),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: courses
|
|
|
|
|
.map((course) => ListTile(
|
|
|
|
|
title: Text(course.getName),
|
|
|
|
|
subtitle: Text(course.toString()),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
end: DateTime.now().add(Duration(hours: 2)))),
|
|
|
|
|
child: Text('插入一个测试课程'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// 导航到AddCourseFormWidget页面
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AddCourseRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text('添加自定义课程'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
courseController.getCourses().then((courses) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('课程列表'),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: courses
|
|
|
|
|
.map((course) => ListTile(
|
|
|
|
|
title: Text(course.getName),
|
|
|
|
|
subtitle: Text(course.toString()),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: Text('查看时间表'),
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return TimetableRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Text('显示课程列表'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// 导航到AddCourseFormWidget页面
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return TimetableRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text('查看时间表'),
|
|
|
|
|
),
|
|
|
|
|
AddCourseButton(
|
|
|
|
|
onCourseAdded: (jsonstr) {
|
|
|
|
|
// 在这里执行添加课程的逻辑,可以将课程名传递给你的 addCourse() 函数
|
|
|
|
|
// courseController.autoImportCours(jsonstr);
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//string导入测试
|
|
|
|
|
|
|
|
|
|
class AddCourseButton extends StatefulWidget {
|
|
|
|
|
final Function(String jsonstr) onCourseAdded;
|
|
|
|
|
|
|
|
|
|
AddCourseButton({required this.onCourseAdded});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_AddCourseButtonState createState() => _AddCourseButtonState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AddCourseButtonState extends State<AddCourseButton> {
|
|
|
|
|
TextEditingController _jsonstrController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
void _showAddCourseDialog(BuildContext context) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('json导入课程'),
|
|
|
|
|
content: TextField(
|
|
|
|
|
controller: _jsonstrController,
|
|
|
|
|
decoration: InputDecoration(labelText: '请输入json字符串'),
|
|
|
|
|
),
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text('取消'),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text('确定'),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
// 使用 pushReplacement 代替 push
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return TimetableRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
final jsonstr = _jsonstrController.text;
|
|
|
|
|
if (jsonstr.isNotEmpty) {
|
|
|
|
|
widget.onCourseAdded(jsonstr);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Text('直接显示 TimetableRoute()'), // 可以将按钮文本改成适当的描述
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_showAddCourseDialog(context);
|
|
|
|
|
},
|
|
|
|
|
child: Text('json导入课程'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_jsonstrController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|