116 lines
3.6 KiB
Dart
116 lines
3.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:plan/api/endpoints/plan_api.dart';
|
|
import 'package:plan/data/models/plan_acttion_type.dart';
|
|
import 'package:plan/page/plan/detail/viewmodel/plan_detail_store.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class FooterBtn extends StatefulWidget {
|
|
const FooterBtn({super.key});
|
|
|
|
@override
|
|
State<FooterBtn> createState() => _FooterBtnState();
|
|
}
|
|
|
|
class _FooterBtnState extends State<FooterBtn> {
|
|
///切换全部完成、或者全部不完成
|
|
void _toggleAllDone() {
|
|
final store = context.read<PlanDetailStore>();
|
|
final allDone = store.planDetail.stepsList.every((item) => item.stepStatus == 2);
|
|
//如果是新增,再点击会首页
|
|
if (store.isNew && allDone) {
|
|
context.pop();
|
|
return;
|
|
}
|
|
//刷新ui
|
|
store.updatePlanDetail((dto) {
|
|
dto.stepsList = store.planDetail.stepsList.map((item) {
|
|
return item.copyWith(stepStatus: allDone ? 0 : 2);
|
|
}).toList();
|
|
});
|
|
|
|
//如果是全部完成
|
|
if (!allDone) {
|
|
store.updatePlanDetail((dto) {
|
|
final now = DateTime.now();
|
|
final formatted = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
|
|
print(formatted);
|
|
dto.planEndTime = formatted;
|
|
});
|
|
}
|
|
|
|
//接口
|
|
editPlanStepApi(
|
|
store.planId,
|
|
act: allDone ? PlanActionType.cancelAll : PlanActionType.completeAll,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<PlanDetailStore>(
|
|
builder: (context, store, _) {
|
|
bool oneDone = store.planDetail.stepsList.any((item) => item.stepStatus == 2);
|
|
//是否全部完成
|
|
bool allDone = store.planDetail.stepsList.every((item) => item.stepStatus == 2);
|
|
//按钮文字
|
|
var btnText = allDone ? "Try again" : "All done!";
|
|
if (store.isNew && allDone) {
|
|
btnText = "add new plan";
|
|
}
|
|
|
|
return AnimatedSize(
|
|
duration: Duration(milliseconds: 300),
|
|
child: Container(
|
|
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
|
|
decoration: BoxDecoration(
|
|
border: Border(
|
|
top: BorderSide(
|
|
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
|
// color: CupertinoColors.,
|
|
),
|
|
),
|
|
),
|
|
height: oneDone ? null : 0,
|
|
child: GestureDetector(
|
|
onTap: _toggleAllDone,
|
|
child: Container(
|
|
height: 45,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(5),
|
|
color: Colors.white,
|
|
border: Border.all(color: Colors.black),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
spacing: 10,
|
|
children: [
|
|
Visibility(
|
|
visible: !allDone,
|
|
replacement: Icon(
|
|
CupertinoIcons.refresh_circled,
|
|
size: 20,
|
|
),
|
|
child: Icon(
|
|
CupertinoIcons.checkmark_circle_fill,
|
|
color: Colors.green,
|
|
size: 20,
|
|
),
|
|
),
|
|
Text(
|
|
btnText,
|
|
style: TextStyle(fontWeight: FontWeight.w700),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|