Skip to content

Commit

Permalink
fix:修复一系列细节bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanotsu committed Dec 30, 2023
1 parent 47700f0 commit d1b3273
Show file tree
Hide file tree
Showing 36 changed files with 731 additions and 518 deletions.
82 changes: 1 addition & 81 deletions lib/common/components/dialog_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,6 @@ buildCloseButton(
);
}

/// 弹窗中的图片展示
/// 目前在基础运动详情弹窗、动作详情弹窗、动作配置弹窗中可复用
buildImageArea(BuildContext context, Exercise exercise) {
return Container(
// 预设的图片背景色一般是白色,所以这里也设置为白色,看起来一致
// color: Colors.white,
// 2023-12-25 因为有设计深色模式,所以不能固定为白色
color: Theme.of(context).canvasColor,
child: Center(
child: Padding(
padding: EdgeInsets.only(bottom: 10.sp),
child: GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
child: Hero(
tag: 'imageTag',
child: buildExerciseImageCarouselSlider(exercise),
),
);
},
);
},
child: Hero(
tag: 'imageTag',
// child: buildExerciseImage(exercise),
child: buildExerciseImageCarouselSlider(exercise),
),
),
),
),
);
}

/// 弹窗中的标题部分
/// 主体是个ListTile,但有的地方其title只是显示文本,有的可能会是按钮,所以title部分保留传入部件
/// 目前在基础运动详情弹窗、动作详情弹窗、动作配置弹窗中可复用
Expand Down Expand Up @@ -117,50 +81,6 @@ Image buildExerciseImage(Exercise exercise) {
);
}

// 锻炼的图片轮播图(后续如果食物的图片或者其他图片有类似功能,可能再抽一次)
buildExerciseImageCarouselSlider(Exercise exercise) {
List<String> imageList = [];
// 先要排除image是个空字符串
if (exercise.images != null && exercise.images!.trim().isNotEmpty) {
imageList = exercise.images!.split(",");
}

return CarouselSlider(
options: CarouselOptions(
autoPlay: true, // 自动播放
enlargeCenterPage: true, // 居中图片放大
aspectRatio: 16 / 9, // 图片宽高比
viewportFraction: 1, // 图片占屏幕宽度的比例
// 只有一张图片时不滚动
enableInfiniteScroll: imageList.length > 1,
),
// 没有图片显示一张占位图片
items: imageList.isEmpty
? [Image.asset(placeholderImageUrl, fit: BoxFit.scaleDown)]
: imageList.map((imageUrl) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.symmetric(horizontal: 5.0),
decoration: const BoxDecoration(
color: Colors.grey,
),
child: Image.file(
File(imageUrl),
errorBuilder: (BuildContext context, Object exception,
StackTrace? stackTrace) {
return Image.asset(placeholderImageUrl,
fit: BoxFit.scaleDown);
},
),
);
},
);
}).toList(),
);
}

// 图片轮播
buildImageCarouselSlider(
List<String> imageList, {
Expand Down Expand Up @@ -271,7 +191,7 @@ _buildImageCarouselSliderType(
imageProvider: FileImage(File(imageList[index])),
);
},
enableRotation: true,
// enableRotation: true,
scrollPhysics: const BouncingScrollPhysics(),
backgroundDecoration: const BoxDecoration(
color: Colors.transparent,
Expand Down
25 changes: 22 additions & 3 deletions lib/common/utils/db_diary_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,28 @@ class DBDiaryHelper {
required String keyword,
required int pageSize, // 一次查询条数显示
required int page, // 一次查询的偏移量,用于分页
// 2023-12-30 指定创建日期升序或者降序排序
String? dateSort = "desc",
}) async {
Database db = await database;
// 根据页数和页面获得偏移量
var offset = (page - 1) * pageSize;

var sort = dateSort?.toLowerCase();
if (dateSort != null) {
// 如果有传入创建时间排序,不是传的降序一律升序
sort = dateSort.toLowerCase() == 'desc' ? 'DESC' : 'ASC';
}

try {
// 查询指定关键字当前页的数据
List<Map<String, dynamic>> maps = await db.query(
DiaryDdl.tableNameOfDiary,
where:
'(title LIKE ? OR content LIKE ?) AND user_id = ? LIMIT ? OFFSET ?',
whereArgs: ['%$keyword%', '%$keyword%', userId, pageSize, offset],
where: '(title LIKE ? OR content LIKE ?) AND user_id = ?',
whereArgs: ['%$keyword%', '%$keyword%', userId],
limit: pageSize,
offset: offset,
orderBy: sort != null ? 'gmt_create $sort' : null,
);
final list = maps.map((row) => Diary.fromMap(row)).toList();

Expand All @@ -220,6 +230,8 @@ class DBDiaryHelper {
int userId, {
String? startDate,
String? endDate,
// 2023-12-30 指定创建日期升序或者降序排序
String? dateSort = "desc",
}) async {
Database db = await database;

Expand All @@ -239,12 +251,19 @@ class DBDiaryHelper {
whereArgs.add(endDate);
}

var sort = dateSort?.toLowerCase();
if (dateSort != null) {
// 如果有传入创建时间排序,不是传的降序一律升序
sort = dateSort.toLowerCase() == 'desc' ? 'DESC' : 'ASC';
}

try {
// 查询指定关键字当前页的数据
List<Map<String, dynamic>> maps = await db.query(
DiaryDdl.tableNameOfDiary,
where: where.isNotEmpty ? where.join(' AND ') : null,
whereArgs: whereArgs.isNotEmpty ? whereArgs : null,
orderBy: sort != null ? 'gmt_create $sort' : null,
);
final list = maps.map((row) => Diary.fromMap(row)).toList();

Expand Down
16 changes: 16 additions & 0 deletions lib/common/utils/db_training_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,16 @@ class DBTrainingHelper {
whereArgs: [planId],
);

Future<List<TrainingPlan>> queryTrainingPlanById(int planId) async {
return (await (await database).query(
TrainingDdl.tableNameOfPlan,
where: "plan_id =? ",
whereArgs: [planId],
))
.map((row) => TrainingPlan.fromMap(row))
.toList();
}

/// ???查询指定计划以及其所有训练(3层嵌套,看怎么优化)
// 计划支持条件查询,估计计划的数量不会多,就暂时不分页;同时关联的训练就全部带出。
Future<List<PlanWithGroups>> searchPlanWithGroups({
Expand Down Expand Up @@ -694,6 +704,12 @@ class DBTrainingHelper {
Database db = await database;

return await db.transaction((txn) async {
// 2023-12-30 一并更新该计划的周期为列表的长度
await txn.rawUpdate(
'UPDATE ${TrainingDdl.tableNameOfPlan} SET plan_period = ? WHERE plan_id = ?',
[phgList.length, planId],
);

await txn.delete(
TrainingDdl.tableNameOfPlanHasGroup,
where: "plan_id = ? ",
Expand Down
11 changes: 9 additions & 2 deletions lib/common/utils/tool_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:math' as math;

import '../../layout/themes/cus_font_size.dart';
import '../../models/cus_app_localizations.dart';
import '../global/constants.dart';
import 'tools.dart';
Expand Down Expand Up @@ -62,16 +63,22 @@ Widget buildLoader(bool isLoading) {
// 表单使用是FormBuilderDropdown<String>但要注意类型改为匹配的,或者不指定String
List<DropdownMenuItem<Object>> genDropdownMenuItems(
List<CusLabel> options, {
double? textSize = 16,
double? textSize,
}) {
// 2023-12-30 为了英文的时候输入框显示完整,字体小点(13),中午就16
var fontSize = textSize ??
(box.read('language') == "en"
? CusFontSizes.pageSubContent
: CusFontSizes.pageSubTitle);

return options
.map(
(option) => DropdownMenuItem(
alignment: AlignmentDirectional.centerStart,
value: option.value,
child: Text(
showCusLable(option),
style: TextStyle(fontSize: textSize),
style: TextStyle(fontSize: fontSize),
),
),
)
Expand Down
5 changes: 5 additions & 0 deletions lib/common/utils/tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import 'package:intl/intl.dart';

import '../global/constants.dart';

/// 默认的日历显示范围,当前月的前后3个月
final kToday = DateTime.now();
final kFirstDay = DateTime(2023, 10, 12);
final kLastDay = DateTime(kToday.year, kToday.month + 1, 15);

// 10位的时间戳转字符串
String formatTimestampToString(int timestamp) {
if (timestamp.toString().length == 10) {
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
"richTextToolNote":" Expand Quill Toolbar",

"lastModified":"Last Modified",
"gmtCreate":"Created Time",


"confirmLabel":"Confirm",
Expand All @@ -324,7 +325,7 @@
"moreDetail": "More Detail",
"lessLabel":"less",
"enterLabel":"Enter",
"skipLabel":"Next",
"skipLabel":"Not Now",
"backLabel":"Back",
"saveLabel":"Save",
"eidtLabel":"Edit {name}",
Expand Down
9 changes: 5 additions & 4 deletions lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"groupDeleteAlert":"确认要删除该训练动作组: {workoutName} ? 删除后不可恢复!",
"groupInUse":"该训练 {workoutName} 有被计划使用,暂不支持删除",

"modifyGroupLabels": "{num, select, 0{修改训练} 1{新建训练} 2{主要肌肉} 3{次要肌肉} 4{技术要点} 5{语音提示要点} 6{动作图片} 7{用户上传} other{其他} }",
"modifyGroupLabels": "{num, select, 0{新建训练} 1{修改训练} 2{主要肌肉} 3{次要肌肉} 4{技术要点} 5{语音提示要点} 6{动作图片} 7{用户上传} other{其他} }",
"@modifyGroupLabels": {
"description": "修改或新建训练动作组的标签"
},
Expand Down Expand Up @@ -184,7 +184,7 @@
"planDeleteAlert":"确认要删除该训练计划: {planName} ? 删除后不可恢复!",
"planInUse":"该训练计划 {planName} 存在跟练记录,暂不支持删除",

"modifyPlanLabels": "{num, select, 0{修改计划} 1{新建计划} 2{名称} 3{代号} 4{分类} 5{级别} 6{训练周期} 7{概述} other{其他} }",
"modifyPlanLabels": "{num, select, 0{新建计划} 1{修改计划} 2{名称} 3{代号} 4{分类} 5{级别} 6{训练周期} 7{概述} other{其他} }",
"@modifyPlanLabels": {
"description": "修改或新建 plan 的标签"
},
Expand Down Expand Up @@ -321,6 +321,7 @@
"richTextToolNote":"展开富文本编辑工具栏",

"lastModified":"上次修改时间",
"gmtCreate":"初始创建时间",

"confirmLabel":"确定",
"cancelLabel":"取消",
Expand All @@ -329,8 +330,8 @@
"moreLabel":"更多",
"moreDetail": "更多详情",
"lessLabel":"收起",
"enterLabel":"进入",
"skipLabel":"下一步",
"enterLabel":"完成输入",
"skipLabel":"暂时忽略",
"backLabel":"返回",
"saveLabel":"保存",
"eidtLabel":"修改{name}",
Expand Down
10 changes: 5 additions & 5 deletions lib/layout/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ class _HomePageState extends State<HomePage> {
actions: [
TextButton(
onPressed: () {
Navigator.pop(context, true);
Navigator.pop(context, false);
},
child: Text(CusAL.of(context).confirmLabel),
child: Text(CusAL.of(context).cancelLabel),
),
ElevatedButton(
TextButton(
onPressed: () {
Navigator.pop(context, false);
Navigator.pop(context, true);
},
child: Text(CusAL.of(context).cancelLabel),
child: Text(CusAL.of(context).confirmLabel),
),
],
);
Expand Down
11 changes: 10 additions & 1 deletion lib/layout/init_guide_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _InitGuidePageState extends State<InitGuidePage> {
return Scaffold(
resizeToAvoidBottomInset: false,
body: Padding(
padding: const EdgeInsets.all(16.0),
padding: EdgeInsets.all(16.sp),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expand All @@ -78,12 +78,21 @@ class _InitGuidePageState extends State<InitGuidePage> {
controller: _usernameController,
decoration: InputDecoration(
labelText: CusAL.of(context).nameLabel,
// 设置透明底色
filled: true,
fillColor: Colors.transparent,
),
),
),
Padding(
padding: EdgeInsets.all(10.sp),
child: DropdownButtonFormField<CusLabel>(
decoration: const InputDecoration(
isDense: true,
// 设置透明底色
filled: true,
fillColor: Colors.transparent,
),
items: genderOptions.map((CusLabel gender) {
return DropdownMenuItem<CusLabel>(
value: gender,
Expand Down
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import 'layout/app.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await GetStorage.init();
await GetStorage().write('language', 'en');
// await GetStorage().write('language', 'en');
// await GetStorage().write('language', 'cn');
await GetStorage().write('language', 'system');
// await GetStorage().write('mode', 'dark');
// await GetStorage().write('mode', 'light');
await GetStorage().write('mode', 'system');
Expand Down
2 changes: 1 addition & 1 deletion lib/models/training_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class TrainingPlan {
planName: map['plan_name'] as String,
planCategory: map['plan_category'] as String,
planLevel: map['plan_level'] as String,
planPeriod: map['plan_period'] as int,
planPeriod: map['plan_period'] as int? ?? 0,
description: map['description'] as String?,
contributor: map['contributor'] as String?,
gmtCreate: map['gmt_create'] as String?,
Expand Down
10 changes: 5 additions & 5 deletions lib/views/diary/diary_modify_rich_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ class _DiaryModifyRichTextState extends State<DiaryModifyRichText> {
actions: [
TextButton(
onPressed: () {
Navigator.pop(context, true);
Navigator.pop(context, false);
},
child: Text(CusAL.of(context).confirmLabel),
child: Text(CusAL.of(context).cancelLabel),
),
ElevatedButton(
TextButton(
onPressed: () {
Navigator.pop(context, false);
Navigator.pop(context, true);
},
child: Text(CusAL.of(context).cancelLabel),
child: Text(CusAL.of(context).confirmLabel),
),
],
);
Expand Down
Loading

0 comments on commit d1b3273

Please sign in to comment.