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.
TimeManager/src/timemanagerapp/lib/widgets/UserSettingWidget.dart

99 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:timemanagerapp/setting/Setting.dart';
import '../provider/TimeProvider.dart';
class UserSettingWidget extends StatefulWidget {
@override
_UserSettingWightState createState() => _UserSettingWightState();
}
class _UserSettingWightState extends State<UserSettingWidget> {
TextEditingController _controller = TextEditingController();
TextEditingController _startDateController = TextEditingController();
Future<void> savepixelToMinuteRatio_ratio(double value) async {
// 实现savepixelToMinuteRatio_ratio功能
await Setting.savepixelToMinuteRatio_ratio(value);
print('savepixelToMinuteRatio_ratio触发$value');
}
Future<void> saveStartDate(DateTime date) async {
// 实现saveStartDate功能
await Setting.saveStartDate(date);
print('saveStartDate触发$date');
}
Future<void> handleSave() async {
double number = double.tryParse(_controller.text) ?? 0;
// 限制number的取值范围
if(number < 0.1) number = 0.1;
if(number > 2) number = 2;
await savepixelToMinuteRatio_ratio(number);
DateTime date = DateTime.tryParse(_startDateController.text) ?? DateTime.now();
await saveStartDate(date);
// Provider.of<TimeProvider>(context, listen: false).updateTimetable(); // 更新时间表页面操作
setState(() {
});
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
_controller.text = Setting.pixelToMinuteRatio_ratio.toString();
_startDateController.text = Setting.startdate.toString().substring(0, 10);
return Scaffold(
appBar: AppBar(
title: Text('设置'),
actions: [
IconButton(
icon: Icon(Icons.save),
onPressed: handleSave,
),
],
),
body: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
Row(
children: [
Text('时间轴比例: ', style: TextStyle(fontSize: 20.0)),
Expanded(
child: TextField(
controller: _controller,
style: TextStyle(fontSize: 20.0), // 设置字体大小为20
keyboardType: TextInputType.number,
decoration: InputDecoration(),
),
),
],
),
Row(
children: [
Text('本学期第一周周一日期: ', style: TextStyle(fontSize: 20.0)),
Expanded(
child: TextField(
controller: _startDateController,
keyboardType: TextInputType.datetime,
style: TextStyle(fontSize: 20.0), // 设置字体大小为20
decoration: InputDecoration(),
),
),
],
),
],
),
),
);
}
}