You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
245 lines
7.7 KiB
245 lines
7.7 KiB
import 'package:flutter/material.dart';
|
|
import 'package:timemanage/screen/projects_screen.dart';
|
|
import 'package:timemanage/screen/reports_screen.dart';
|
|
import 'package:timemanage/screen/export_screen.dart';
|
|
import 'package:timemanage/screen/settings_screen.dart';
|
|
import 'package:timemanage/screen/about_screen.dart';
|
|
import 'package:timemanage/screen/course_screen.dart';
|
|
|
|
class DashBoardScreen extends StatefulWidget {
|
|
const DashBoardScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_DashBoardScreenState createState() => _DashBoardScreenState();
|
|
}
|
|
|
|
class _DashBoardScreenState extends State<DashBoardScreen> {
|
|
List<TimerModel> timers = [];
|
|
|
|
void _addTimer() {
|
|
final controller = TextEditingController();
|
|
showDialog<String>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: const Text('新计时器'),
|
|
content: TextField(
|
|
controller: controller,
|
|
decoration: const InputDecoration(hintText: '计时器名称'),
|
|
),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, 'Cancel'),
|
|
child: const Text('取消'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
final name = controller.text;
|
|
if (name.isNotEmpty) {
|
|
setState(() {
|
|
timers.add(TimerModel(name: name));
|
|
});
|
|
}
|
|
Navigator.pop(context, 'OK');
|
|
},
|
|
child: const Text('OK'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.blueAccent, // 背景色
|
|
// 最前面的菜单按钮
|
|
leading: MenuBar(
|
|
children: <Widget>[
|
|
SubmenuButton(
|
|
menuChildren: <Widget>[
|
|
MenuItemButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => SyllabusPage()),
|
|
);
|
|
},
|
|
child: const Text('课程表'),
|
|
),
|
|
MenuItemButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const ProjectsScreen()),
|
|
);
|
|
},
|
|
child: const Text('项目'),
|
|
),
|
|
MenuItemButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const ReportsScreen()),
|
|
);
|
|
},
|
|
child: const Text('统计报告'),
|
|
),
|
|
MenuItemButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const ExportScreen()),
|
|
);
|
|
},
|
|
child: const Text('导入和导出'),
|
|
),
|
|
MenuItemButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const SettingsScreen()),
|
|
);
|
|
},
|
|
child: const Text('设置'),
|
|
),
|
|
MenuItemButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const AboutScreen()),
|
|
);
|
|
},
|
|
child: const Text('关于'),
|
|
),
|
|
],
|
|
child: const Icon(Icons.menu),
|
|
),
|
|
],
|
|
),
|
|
// 标题
|
|
title: const Text('时间管理'),
|
|
actions: [
|
|
// 搜索按钮
|
|
IconButton(
|
|
icon: const Icon(Icons.search),
|
|
onPressed: () {},
|
|
),
|
|
// 筛选按钮
|
|
IconButton(
|
|
icon: const Icon(Icons.add),
|
|
onPressed: _addTimer,
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.filter_alt),
|
|
onPressed: () {},
|
|
)
|
|
],
|
|
),
|
|
body: ListView.builder(
|
|
itemCount: timers.length,
|
|
itemBuilder: (context, index) {
|
|
return Column(
|
|
children: [
|
|
ListTile(
|
|
leading: CircleAvatar(
|
|
child: Text((index + 1).toString()),
|
|
),
|
|
title: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
timers[index].name,
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
StreamBuilder<int>(
|
|
stream: Stream.periodic(const Duration(milliseconds: 100),
|
|
(_) => timers[index].stopwatch.elapsed.inSeconds),
|
|
builder: (context, snapshot) {
|
|
final seconds = snapshot.data ?? 0;
|
|
final hours = seconds ~/ 3600;
|
|
final minutes = (seconds % 3600) ~/ 60;
|
|
final remainingSeconds = seconds % 60;
|
|
return Text(
|
|
'${hours.toString().padLeft(2, '0')}:${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}',
|
|
style: const TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(
|
|
icon: timers[index].isActive
|
|
? const Icon(Icons.pause)
|
|
: const Icon(Icons.play_arrow),
|
|
onPressed: () {
|
|
setState(() {
|
|
if (timers[index].isActive) {
|
|
timers[index].stop();
|
|
} else {
|
|
timers[index].start();
|
|
}
|
|
});
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.delete),
|
|
onPressed: () {
|
|
setState(() {
|
|
timers[index].stopwatch.stop(); // 确保计时器停止以防止内存泄漏
|
|
timers.removeAt(index);
|
|
});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 10), // 添加间隔
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class TimerModel {
|
|
String name;
|
|
Stopwatch stopwatch;
|
|
bool isActive;
|
|
|
|
TimerModel({required this.name})
|
|
: stopwatch = Stopwatch(),
|
|
isActive = false;
|
|
|
|
void start() {
|
|
stopwatch.start();
|
|
isActive = true;
|
|
}
|
|
|
|
void stop() {
|
|
stopwatch.stop();
|
|
isActive = false;
|
|
}
|
|
|
|
void reset() {
|
|
stopwatch.reset();
|
|
}
|
|
}
|