lvxinquan
LRC 2 years ago
parent bb7f3afd97
commit bf8753c22e

52
.gitignore vendored

@ -0,0 +1,52 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
**/.history
**/.svn/
**/migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
**/.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
**/vscode/
# Flutter/Dart/Pub related
**/src/timemanagerapp/.*
**/doc/api/
**/build/
**/ios/
**/linux/
**/macos/
**/web/
**/windows/
**/android/
**/.dart_tool/
**/.flutter-plugins
**/.flutter-plugins-dependencies
**/.packages
**/.pub-cache/
**/.pub/
# Symbolication related
app.*.symbols
# Obfuscation related
app.*.map.json
# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

@ -1,3 +1,4 @@
import 'package:timemanagerapp/controller/NetWorkController.dart';
import 'package:timemanagerapp/database/dao/CourseDao.dart';
import 'package:timemanagerapp/entity/Course.dart';
import 'package:timemanagerapp/entity/CourseForm.dart';
@ -11,7 +12,10 @@ class CourseController {
return new CourseController();
}
GetCourseByLogin getCourseByLogin = GetCourseByLogin();
IdGenerator idGenerator = IdGenerator();
List<Course> courseList = []; //courseList
NetWorkController netWorkController = NetWorkController();
DateTime termstartdate = Setting.startdate; //Setting.getStartDate();
@ -50,10 +54,11 @@ class CourseController {
hours: int.parse(raspiyane[courseForm.getEndTime() - 1][1].split(':')[0]),
minutes: int.parse(raspiyane[courseForm.getEndTime() - 1][1].split(':')[1]),
));
int courseId = await idGenerator.generateId();
Course course = Course(
name: courseForm.getCourse(),
userId: Setting.user!.getId!,
courseId: generateId(),
courseId: courseId,
teacher: courseForm.getTeacher(),
location: courseForm.getLocation(),
start: startDate,
@ -103,8 +108,9 @@ class CourseController {
return result;
}
Future<int> autoImportCours(String jsonstr) async {
List<Course> courseList = await GetCourseByLogin().dealRawString(jsonstr);
Future<int> autoImportCours(int stuid,String passwd,int year, int term) async {
String jsonstr = await netWorkController.getUserCoursejson(stuid, passwd, year, term);
List<Course> courseList = await getCourseByLogin.dealRawString(jsonstr);
return await insertCourseList(courseList);
}

@ -15,12 +15,12 @@ class NetWorkController{
"appsecret":"mN3u09pY",
});
Future<bool> login(User user) async {
return true;
Future<int> login(User user) async {
return Future(() => 1);
}
Future<bool> register(User user) async {
return true;
Future<int> register(User user) async {
return Future(() => 1);
}
Future<List<Work>> getSameFreeWork(int teamid){
@ -62,6 +62,10 @@ class NetWorkController{
Future<bool> deleteTeamUser(int teamid,int userid) async {
return true;
}
//todo
// Future<bool> deleteTeamUser(int teamid,int userid) async {
// return true;
// }
//app,
@ -73,4 +77,9 @@ class NetWorkController{
return true;
}
Future<String> getUserCoursejson(int stuid,String passwd,int year, int term){
String res = "";
return Future(() => res);
}
}

@ -11,6 +11,7 @@ class TeamController {
Map<int, List<Work>> Wordmaplist = {};
NetWorkController netWorkController = NetWorkController();
TeamController(int leaderid) {
this.leaderid = leaderid;
//TODO: leaderidteamList
@ -21,12 +22,12 @@ class TeamController {
}
}
Future<List<Map<String, dynamic>>> getTeams(int userid) async {
return TeamDao().getTeams();
Future<List<Team>> getTeams(int userid) async {
return await netWorkController.getTeamList(userid);
}
Future<void> insertTeam(Team team) async {
await TeamDao().insertTeam(team);
Future<bool> createTeam(Team team) async {
return await netWorkController.insertTeam(team);
}
Future<void> insertTeamList(List<Team> teamList) async {
@ -39,16 +40,16 @@ class TeamController {
await TeamDao().deleteAllTeams();
}
Future<void> deleteTeam(int id) async {
await TeamDao().deleteTeamById(id);
Future<bool> deleteTeam(int teamid) async {
return await netWorkController.deleteTeam(teamid);
}
Future<void> updateTeam(Team team) async {
await TeamDao().updateTeam(team);
Future<bool> updateTeam(Team team) async {
return await netWorkController.updateTeam(team);
}
Future<void> insertWork(Work work) async {
await WorkDao().insertWork(work);
// return await netWorkController.insertWork(work);
}
Future<void> insertWorkList(List<Work> workList) async {

@ -2,10 +2,15 @@ import 'package:timemanagerapp/database/dao/UserDao.dart';
import 'package:timemanagerapp/database/MyDatebase.dart';
import 'package:timemanagerapp/entity/User.dart';
import '../setting/Setting.dart';
import 'NetWorkController.dart';
/**
*
*/
class UserController {
NetWorkController netWorkController = NetWorkController();
//
static UserController getInstance() {
return new UserController();
@ -15,17 +20,32 @@ class UserController {
return await UserDao.getInstance().getUsers();
}
Future<void> insertUser(User user) async {
await UserDao.getInstance().insertUser(user);
Future<bool> login(User user) async {
int userid = await netWorkController.login(user);
user.id = userid;
await Setting.saveUser(user);
return true;
}
Future<void> deleteAllUsers() async {
await UserDao.getInstance().deleteAllUsers();
Future<bool> register(User user) async {
int userid = await netWorkController.register(user);
user.id = userid;
await Setting.saveUser(user);
return true;
}
Future<void> deleteUser(int id) async {
await UserDao.getInstance().deleteUser(id);
Future<void> insertUser(User user) async {
await UserDao.getInstance().insertUser(user);
}
Future<void> insertUserList(List<User> userList) async {
for (User user in userList) {
await UserDao.getInstance().insertUser(user);
}
}
//deleteAllUsers
Future<void> deleteAllUsers() async {
await UserDao.getInstance().deleteAllUsers();
}
}

@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:timemanagerapp/setting/Setting.dart';
import 'package:timemanagerapp/util/GetCourseByLogin.dart';
import 'package:timemanagerapp/wighets/AddCourseFormWidget.dart';
import 'package:timemanagerapp/wighets/HomeWighet.dart';
import 'package:timemanagerapp/wighets/LoginWidget.dart';
import 'package:timemanagerapp/wighets/TestWidget.dart';
import 'package:timemanagerapp/wighets/TimetableWighet.dart';

@ -12,6 +12,7 @@ class GetCourseByLogin {
String term = "1"; //
DateTime termstartdate = Setting.startdate;
List<Course> courses = []; //
IdGenerator idGenerator = IdGenerator();
// GetCourseByLogin({this.id = "", this.passwd = "", this.year = "2021", this.term = "1"});
@ -79,7 +80,7 @@ class GetCourseByLogin {
return Future(() => res);
}
dealRawString(String rawStr) {
dealRawString(String rawStr) async {
rawStr = rawStr.replaceAll("'", "\"");
// JSON
@ -140,7 +141,7 @@ class GetCourseByLogin {
final course = Course(
id: int.parse(courseId),
userId: Setting.user != null ? Setting.user!.id : null,
courseId: generateId(),
courseId: await idGenerator.generateId(),
name: courseTitle,
credit: courseData['credit'],
teacher: courseData['teacher'],

@ -1,3 +1,115 @@
int generateId() {
return DateTime.now().millisecondsSinceEpoch;
}
import 'dart:io';
import 'dart:math';
import 'package:device_info/device_info.dart';
import 'package:flutter/services.dart';
//id
class IdGenerator {
static const int EPOCH = 1609459200000; // 2021-01-01 00:00:00
static const int WORKER_ID_BITS = 5;
static const int DATACENTER_ID_BITS = 5;
static const int SEQUENCE_BITS = 12;
late int workerId;
late int datacenterId;
late var sequenceFuther ;
late int sequence = 0;
late int lastTimestamp = -1;
IdGenerator() {
//workerId = Random().nextInt(pow(2, WORKER_ID_BITS)) % 4096;
var wordidrang = pow(2, WORKER_ID_BITS).toInt();
workerId = Random().nextInt(wordidrang);
datacenterId = Random().nextInt(pow(2, DATACENTER_ID_BITS).toInt());
sequenceFuther = generateSequenceFromMacAddress();
if (workerId < 0 || workerId >= pow(2, WORKER_ID_BITS)) {
throw ArgumentError('Worker ID must be between 0 and ${pow(2, WORKER_ID_BITS) - 1}');
}
if (datacenterId < 0 || datacenterId >= pow(2, DATACENTER_ID_BITS)) {
throw ArgumentError('Datacenter ID must be between 0 and ${pow(2, DATACENTER_ID_BITS) - 1}');
}
}
Future<int> generateId() async{
sequence = await sequenceFuther;
int timestamp = DateTime.now().millisecondsSinceEpoch - EPOCH;
if (timestamp < lastTimestamp) {
throw Exception('Invalid system clock');
}
if (timestamp == lastTimestamp) {
sequence = (sequence + 1) & ((1 << SEQUENCE_BITS) - 1);
if (sequence == 0) {
timestamp = tilNextMillis(lastTimestamp);
}
} else {
sequence = 0;
}
lastTimestamp = timestamp;
int id = (timestamp << (WORKER_ID_BITS + DATACENTER_ID_BITS + SEQUENCE_BITS)) |
(datacenterId << (WORKER_ID_BITS + SEQUENCE_BITS)) |
(workerId << SEQUENCE_BITS) |
sequence;
return id;
}
int tilNextMillis(int lastTimestamp) {
int timestamp = DateTime.now().millisecondsSinceEpoch - EPOCH;
while (timestamp <= lastTimestamp) {
timestamp = DateTime.now().millisecondsSinceEpoch - EPOCH;
}
return timestamp;
}
Future<int> generateSequenceFromMacAddress() async{
String macAddress = await getMacAddress();;
// MAC
String sanitizedMacAddress = macAddress.replaceAll(':', '').toUpperCase();
// MAC6
int sum = int.parse(sanitizedMacAddress.substring(0, 12), radix: 16);
// sequence
return sum % (1 << 12);
}
Future<String> getMacAddress() async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
return _getMacAddress(androidInfo);
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
return iosInfo.identifierForVendor;
}
return '';
}
Future<String> _getMacAddress(AndroidDeviceInfo androidInfo) async {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
String macAddress = androidInfo.androidId;
print("get MAC address:" + macAddress);
return macAddress;
// 使WifiManagerMAC
MethodChannel channel = MethodChannel('plugins.flutter.io/device_info');
try {
macAddress = await channel.invokeMethod('getWifiMacAddress');
} catch (e) {
print('Failed to get MAC address: $e');
}
return macAddress;
}
}

@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:timemanagerapp/setting/Setting.dart';
import 'package:timemanagerapp/util/GetCourseByLogin.dart';
import 'package:timemanagerapp/wighets/AddCourseFormWidget.dart';
import 'package:timemanagerapp/wighets/LoginWidget.dart';
import 'package:timemanagerapp/wighets/TestWidget.dart';
import 'package:timemanagerapp/wighets/TimetableWighet.dart';
class HomeWighet extends StatefulWidget {
const HomeWighet({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomeWighet> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return TimetableWidget();
}
}

@ -82,9 +82,9 @@ class _HomePageState extends State<TestWidget> {
mainAxisSize: MainAxisSize.min,
children: users
.map((user) => ListTile(
title: Text(user['username']),
subtitle: Text(user.toString()),
))
title: Text(user['username']),
subtitle: Text(user.toString()),
))
.toList(),
),
),
@ -143,9 +143,9 @@ class _HomePageState extends State<TestWidget> {
mainAxisSize: MainAxisSize.min,
children: courses
.map((course) => ListTile(
title: Text(course.getName),
subtitle: Text(course.toString()),
))
title: Text(course.getName),
subtitle: Text(course.toString()),
))
.toList(),
),
),
@ -171,10 +171,10 @@ class _HomePageState extends State<TestWidget> {
child: Text('查看时间表'),
),
AddCourseButton(
onCourseAdded: (jsonstr) {
// addCourse()
courseController.autoImportCours(jsonstr);
}
onCourseAdded: (jsonstr) {
// addCourse()
// courseController.autoImportCours(jsonstr);
}
)
],
),

@ -147,45 +147,45 @@ class PageState extends State<TimetableWidget> {
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)),
),
],
)
//
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: index ==
currentWeekDayIndex //
? Colors.lightBlue
: Colors.black87)),
],
),
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)),
],
),
),
);
}),
@ -193,92 +193,92 @@ class PageState extends State<TimetableWidget> {
//stack
Expanded(
child: SingleChildScrollView(
child: Row(
children: [
//stack
Container(
width: 390,
height: 2000,
child: Stack(
alignment: Alignment.center,
children: [
// Stack
Positioned(
top: 0,
left: 0,
child: Container(
width: 390,
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]
child: Row(
children: [
//stack
Container(
width: 390,
height: 2000,
child: Stack(
alignment: Alignment.center,
children: [
// Stack
Positioned(
top: 0,
left: 0,
child: Container(
width: 390,
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'),
),
SizedBox(width: 5),
Container(
width: 10,
height: 10,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.amber,
width: 2,
':' +
timePoints[index]
.minute
.toString()
.padLeft(2, '0'),
),
),
),
Container(
width: 315,
height: 2,
color: const Color.fromARGB(
255, 136, 61, 61),
SizedBox(width: 5),
Container(
width: 10,
height: 10,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.amber,
width: 2,
),
),
),
Container(
width: 315,
height: 2,
color: const Color.fromARGB(
255, 136, 61, 61),
),
],
),
],
),
),
),
),
),
)),
//Stack
Container(
constraints:
)),
//Stack
Container(
constraints:
BoxConstraints.expand(), // 使constraints
// width: 390,
// height: 2000,
child: Stack(
children: List.generate(
//
courseWeekMap.containsKey(weekCount)
? courseWeekMap[weekCount]!.length
: 0,
((index) => Positioned(
// width: 390,
// height: 2000,
child: Stack(
children: List.generate(
//
courseWeekMap.containsKey(weekCount)
? courseWeekMap[weekCount]!.length
: 0,
((index) => Positioned(
top: courseWeekMap[weekCount]![index]
.getdy() +
.getdy() +
10,
left: courseWeekMap[weekCount]![index]
.getdx() +
.getdx() +
50,
child: SingleChildScrollView(
child: Container(
//
width: 40,
height:
courseWeekMap[weekCount]![index]
.getHeight(),
courseWeekMap[weekCount]![index]
.getHeight(),
decoration: BoxDecoration(
color: Colors.tealAccent,
//
@ -292,71 +292,71 @@ class PageState extends State<TimetableWidget> {
children: [
Text(
courseWeekMap[weekCount]![
index]
index]
.name,
style: TextStyle(
fontSize: 10,
fontWeight:
FontWeight.bold),
FontWeight.bold),
overflow: TextOverflow
.clip, //name
),
Text(
courseWeekMap[weekCount]![
index]
index]
.teacher,
style:
TextStyle(fontSize: 8),
TextStyle(fontSize: 8),
overflow: TextOverflow.clip,
),
Text(
courseWeekMap[weekCount]![
index]
index]
.location,
style:
TextStyle(fontSize: 10),
TextStyle(fontSize: 10),
overflow: TextOverflow.clip,
),
Text(
courseWeekMap[weekCount]![
index]
.start
.hour
.toString() +
index]
.start
.hour
.toString() +
':' +
courseWeekMap[
weekCount]![
index]
weekCount]![
index]
.start
.minute
.toString(),
style:
TextStyle(fontSize: 10),
TextStyle(fontSize: 10),
overflow: TextOverflow.clip,
),
Text(
courseWeekMap[weekCount]![
index]
.end
.hour
.toString() +
index]
.end
.hour
.toString() +
':' +
courseWeekMap[
weekCount]![
index]
weekCount]![
index]
.end
.minute
.toString(),
style:
TextStyle(fontSize: 10),
TextStyle(fontSize: 10),
overflow: TextOverflow.clip,
),
Text(
courseWeekMap[weekCount]![
index]
index]
.remark,
style:
TextStyle(fontSize: 10),
TextStyle(fontSize: 10),
overflow: TextOverflow.clip,
),
],
@ -365,13 +365,13 @@ class PageState extends State<TimetableWidget> {
),
),
))),
))
],
),
))
],
),
),
],
),
],
),
))
))
],
),
);

@ -49,6 +49,22 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.6"
device_info:
dependency: "direct main"
description:
name: device_info
sha256: f4a8156cb7b7480d969cb734907d18b333c8f0bc0b1ad0b342cdcecf30d62c48
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.3"
device_info_platform_interface:
dependency: transitive
description:
name: device_info_platform_interface
sha256: b148e0bf9640145d09a4f8dea96614076f889e7f7f8b5ecab1c7e5c2dbc73c1b
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.1"
fake_async:
dependency: transitive
description:

@ -41,6 +41,7 @@ dependencies:
path_provider: ^2.1.1
multi_select_flutter: 4.1.3
http: ^1.1.0
device_info:
dev_dependencies:

Loading…
Cancel
Save