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 createState() => ActivityActionViewState(); } class ActivityActionViewState extends State { @override Widget build(BuildContext context) { int actionCount = 0; ActivityTimerModel atm = Provider.of(context, listen: true); List>> 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 content = []; List> set = sets[setNum]; // log('${sets.length}'); // log('${set.length}'); for (int actionNum = 0; actionNum < set.length; actionNum++) { Map 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(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(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(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(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); }, )); } }