SendTrain/lib/widgets/activity_action_view.dart
2024-12-06 17:33:33 -05:00

214 lines
9.2 KiB
Dart

import 'dart:async';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:sendtrain/classes/activity_action.dart';
import 'package:sendtrain/models/activity_timer_model.dart';
import 'package:sendtrain/widgets/action_card.dart';
class ActivityActionView extends StatefulWidget {
ActivityActionView({super.key, required this.action});
ActivityAction action;
@override
State<ActivityActionView> createState() => ActivityActionViewState();
}
class ActivityActionViewState extends State<ActivityActionView> {
@override
Widget build(BuildContext context) {
int actionCount = 0;
ActivityTimerModel atm =
Provider.of<ActivityTimerModel>(context, listen: true);
List<List<Map<String, dynamic>>> sets = atm.activity!.actions[0].items();
return Expanded(
child: ListView.builder(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 20),
itemCount: widget.action.activityActionSet.total,
itemBuilder: (BuildContext context, int setNum) {
String title = widget.action.title;
Set actionSet = widget.action.activityActionSet;
Reps setReps = actionSet.reps;
int setRest = actionSet.rest ~/ 1000;
int currentAction = 0;
List<GestureDetector> content = [];
List<Map<String, dynamic>> set = sets[setNum];
// log('${sets.length}');
// log('${set.length}');
for (int actionNum = 0; actionNum < set.length; actionNum++) {
Map<String, dynamic> setItem = set[actionNum];
content.add(GestureDetector(
onTap: () {
atm.setAction(setNum, actionNum, 'manual');
atm.setActionCount();
},
child: Row(children: [
Ink(
// width: 90,
padding: const EdgeInsets.all(15),
color: atm.isCurrentItem(setNum, actionNum)
? Theme.of(context).colorScheme.primaryContainer
: Theme.of(context).colorScheme.onPrimary,
child:
Text(textAlign: TextAlign.right, 'Set ${setNum + 1} ')),
Expanded(
child: Ink(
padding: const EdgeInsets.all(15),
color: atm.isCurrentItem(setNum, actionNum)
? Theme.of(context).colorScheme.surfaceBright
: Theme.of(context).colorScheme.surfaceContainerLow,
child: Text(
textAlign: TextAlign.center,
'${setItem['name']}: ${setItem['amount']} ${setItem['type']}')))
])));
}
// actionCount = actionCount + 2;
// content.addAll([
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// width: 90,
// padding: const EdgeInsets.all(15),
// color: currentAction == atm.currentAction
// ? Theme.of(context).colorScheme.primaryContainer
// : Theme.of(context).colorScheme.onPrimary,
// child: Text(textAlign: TextAlign.right,'Set ${index + 1} '));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction == atm.currentAction
// ? Theme.of(context).colorScheme.surfaceBright
// : Theme.of(context).colorScheme.surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// '$title: ${setReps.amounts[index]} ${atm.setType}')))
// ])),
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction + 1, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// width: 90,
// padding: const EdgeInsets.all(15),
// color: currentAction + 1 == atm.currentAction
// ? Theme.of(context).colorScheme.primaryContainer
// : Theme.of(context).colorScheme.onPrimary,
// child: Text(textAlign: TextAlign.right,'Rest ${index + 1}'));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 1 == atm.currentAction
// ? Theme.of(context).colorScheme.surfaceBright
// : Theme.of(context).colorScheme.surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// 'Rest: $setRest seconds')))
// ])),
// ]);
// if (actionSet.type == 'alternating') {
// actionCount = actionCount + 2;
// content.addAll([
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction + 2, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 2 == atm.currentAction
// ? Theme.of(context).colorScheme.onPrimary
// : Theme.of(context).colorScheme.primaryContainer,
// child: Text('Set: ${index + 1} '));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 2 == atm.currentAction
// ? Theme.of(context).colorScheme.onSecondary
// : Theme.of(context)
// .colorScheme
// .surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// '$title: ${setReps.amounts[index]} ${atm.setType}')))
// ])),
// GestureDetector(
// onTap: () {
// setState(() {
// atm.setAction(currentAction + 3, 'manual');
// });
// },
// child: Row(children: [
// Consumer<ActivityTimerModel>(builder: (context, atm, child) {
// return Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 3 == atm.currentAction
// ? Theme.of(context).colorScheme.onPrimary
// : Theme.of(context).colorScheme.primaryContainer,
// child: Text('Set: ${index + 1} '));
// }),
// Expanded(
// child: Ink(
// padding: const EdgeInsets.all(15),
// color: currentAction + 3 == atm.currentAction
// ? Theme.of(context).colorScheme.onSecondary
// : Theme.of(context)
// .colorScheme
// .surfaceContainerLow,
// child: Text(
// textAlign: TextAlign.center,
// 'Rest: $setRest seconds')))
// ])),
// ]);
// }
if (setNum == 0) {
return Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(0),
topRight: Radius.circular(0),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
),
clipBehavior: Clip.antiAlias,
child: Column(children: content));
} else {
return Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10),
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
),
clipBehavior: Clip.antiAlias,
child: Column(children: content));
}
// return Column(children: contents);
},
));
}
}