93 lines
3.1 KiB
Dart
93 lines
3.1 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.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:remixicon/remixicon.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);
|
|
//刷新ui
|
|
store.updatePlanDetail((dto) {
|
|
dto.stepsList = store.planDetail.stepsList.map((item) {
|
|
return item.copyWith(stepStatus: allDone ? 0 : 2);
|
|
}).toList();
|
|
});
|
|
//接口
|
|
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);
|
|
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(
|
|
allDone ? "Try again" : "All done!",
|
|
style: TextStyle(fontWeight: FontWeight.w700),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|