123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- import 'package:flutter/material.dart';
- import 'package:flutter_habit/common/I18N.dart';
- import 'package:flutter_habit/provider/DataProvider.dart';
- import 'package:flutter_habit/database/entity/StudyInfo.dart';
- import 'package:flutter_habit/database/mapper/StudyInfoMapper.dart';
- import 'package:provider/provider.dart';
- class StudyInfoDetailsPage extends StatelessWidget {
- final StudyInfo studyInfo;
- StudyInfoDetailsPage(this.studyInfo);
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(I18N.of("课程学习详情")),
- ),
- body: Padding(
- padding: EdgeInsets.all(16),
- child: ListView(
- children: <Widget>[
- Text(
- studyInfo.getCourseName()!,
- style: Theme.of(context).textTheme.titleLarge,
- ),
- Divider(),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(I18N.of("是否迟到")),
- Row(
- children: [I18N.of("是"), 1, I18N.of("否"), 0].map((i) {
- if (i is int) {
- return Radio<int>(
- value: i,
- groupValue: studyInfo.getIsLate(),
- onChanged: null,
- );
- } else if (i is String) {
- return Text(i);
- }
- return Container();
- }).toList(),
- )
- ],
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(I18N.of("是否缺席")),
- Row(
- children: [I18N.of("是"), 1, I18N.of("否"), 0].map((i) {
- if (i is int) {
- return Radio<int>(
- value: i,
- groupValue: studyInfo.getIsAbsent(),
- onChanged: null,
- );
- } else if (i is String) {
- return Text(i);
- }
- return Container();
- }).toList(),
- )
- ],
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(I18N.of("作业是否完成")),
- Row(
- children: [I18N.of("是"), 1, I18N.of("否"), 0].map((i) {
- if (i is int) {
- return Radio<int>(
- value: i,
- groupValue: studyInfo.getIsHomeWorkDone(),
- onChanged: null,
- );
- } else if (i is String) {
- return Text(i);
- }
- return Container();
- }).toList(),
- )
- ],
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(I18N.of("课程难度")),
- Row(
- children: [
- I18N.of("简单"),
- 0,
- I18N.of("一般"),
- 1,
- I18N.of("困难"),
- 2
- ].map((i) {
- if (i is int) {
- return Radio<int>(
- value: i,
- groupValue: studyInfo.getDifficulty(),
- onChanged: null,
- );
- } else if (i is String) {
- return Text(i);
- }
- return Container();
- }).toList(),
- )
- ],
- ),
- studyInfo.getIsHomeWorkDone() == 1
- ? Container()
- : Column(
- children: <Widget>[
- Divider(),
- TextField(
- maxLines: 5,
- readOnly: true,
- controller: TextEditingController(
- text: studyInfo.getHomeworks()),
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- labelText: I18N.of("未完成的作业"),
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- ElevatedButton(
- style: ButtonStyle(
- backgroundColor: MaterialStateProperty.all(
- Theme.of(context).colorScheme.secondary),
- foregroundColor: MaterialStateProperty.all(
- Theme.of(context).cardColor)),
- child: Text(I18N.of("已解决")),
- onPressed: () => solveHomeWork(context),
- ),
- ],
- ),
- ],
- ),
- studyInfo.getIsTroublesSolved() == 1
- ? Container()
- : Column(
- children: <Widget>[
- Divider(),
- TextFormField(
- maxLines: 5,
- readOnly: true,
- controller: TextEditingController(
- text: studyInfo.getTroubles()),
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- labelText: I18N.of("遇到的问题"),
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- ElevatedButton(
- style: ButtonStyle(
- backgroundColor: MaterialStateProperty.all(
- Theme.of(context).colorScheme.secondary),
- foregroundColor: MaterialStateProperty.all(
- Theme.of(context).cardColor)),
- child: Text(I18N.of("已解决")),
- onPressed: () => solveTroubles(context),
- ),
- ],
- ),
- ],
- ),
- Divider(),
- Center(
- child: Text(
- DateTime.fromMillisecondsSinceEpoch(studyInfo.getDate()!)
- .toString()
- .substring(0, 16),
- style: Theme.of(context).textTheme.bodySmall,
- ),
- ),
- ],
- ),
- ),
- );
- }
- Future<void> solveTroubles(BuildContext context) async {
- StudyInfo s = StudyInfo();
- s.setId(studyInfo.getId());
- s.setIsTroublesSolved(1);
- await StudyInfoMapper().updateByFirstKeySelective(s);
- await Provider.of<DataProvider>(context, listen: false).loadStudyInfoData();
- Navigator.of(context).pop();
- }
- Future<void> solveHomeWork(BuildContext context) async {
- StudyInfo s = StudyInfo();
- s.setId(studyInfo.getId());
- s.setIsHomeWorkDone(1);
- await StudyInfoMapper().updateByFirstKeySelective(s);
- await Provider.of<DataProvider>(context, listen: false).loadStudyInfoData();
- Navigator.of(context).pop();
- }
- }
|