moving list view
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
||||
import 'package:sendtrain/classes/activity_action.dart';
|
||||
import 'package:sendtrain/models/activity_timer_model.dart';
|
||||
|
||||
@ -12,22 +13,36 @@ class ActivityActionView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class ActivityActionViewState extends State<ActivityActionView> {
|
||||
final ItemScrollController itemScrollController = ItemScrollController();
|
||||
final ScrollOffsetController scrollOffsetController =
|
||||
ScrollOffsetController();
|
||||
final ItemPositionsListener itemPositionsListener =
|
||||
ItemPositionsListener.create();
|
||||
final ScrollOffsetListener scrollOffsetListener =
|
||||
ScrollOffsetListener.create();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ActivityTimerModel atm =
|
||||
Provider.of<ActivityTimerModel>(context, listen: true);
|
||||
List<List<Map<String, dynamic>>> sets = atm.activity!.actions[0].items();
|
||||
|
||||
// we need to set the scroll controller
|
||||
// so we can update the selected item position
|
||||
atm.setScrollController(itemScrollController);
|
||||
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
child: ScrollablePositionedList.builder(
|
||||
padding: const EdgeInsets.fromLTRB(10, 0, 10, 20),
|
||||
itemCount: widget.action.activityActionSet.total,
|
||||
itemScrollController: itemScrollController,
|
||||
scrollOffsetController: scrollOffsetController,
|
||||
itemPositionsListener: itemPositionsListener,
|
||||
scrollOffsetListener: scrollOffsetListener,
|
||||
itemBuilder: (BuildContext context, int setNum) {
|
||||
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];
|
||||
|
||||
@ -35,6 +50,11 @@ class ActivityActionViewState extends State<ActivityActionView> {
|
||||
onTap: () {
|
||||
atm.setAction(setNum, actionNum, 'manual');
|
||||
atm.setActionCount();
|
||||
|
||||
itemScrollController.scrollTo(
|
||||
index: setNum,
|
||||
duration: Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOutCubic);
|
||||
},
|
||||
child: Row(children: [
|
||||
Ink(
|
||||
@ -43,8 +63,9 @@ class ActivityActionViewState extends State<ActivityActionView> {
|
||||
color: atm.isCurrentItem(setNum, actionNum)
|
||||
? Theme.of(context).colorScheme.primaryContainer
|
||||
: Theme.of(context).colorScheme.onPrimary,
|
||||
child:
|
||||
Text(textAlign: TextAlign.center, '${setNum + 1}.${actionNum + 1} ')),
|
||||
child: Text(
|
||||
textAlign: TextAlign.center,
|
||||
'${setNum + 1}.${actionNum + 1} ')),
|
||||
Expanded(
|
||||
child: Ink(
|
||||
padding: const EdgeInsets.all(15),
|
||||
|
@ -64,9 +64,9 @@ class ActivityCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
ImageProvider findMediaByType(List<Media>? media, String type) {
|
||||
var found = media!.where((m) => m.type == 'image');
|
||||
var found = media?.where((m) => m.type == 'image');
|
||||
|
||||
if (found.isNotEmpty) {
|
||||
if (found != null) {
|
||||
return NetworkImage(found.first.reference);
|
||||
} else {
|
||||
// Element is not found
|
||||
|
@ -26,8 +26,6 @@ class _ActivityViewState extends State<ActivityView> {
|
||||
|
||||
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
AppBar(
|
||||
// surfaceTintColor: ThemeData.dark(useMaterial3: true).colorScheme.primary,
|
||||
// backgroundColor: ThemeData.dark(useMaterial3: true).colorScheme.primaryContainer,
|
||||
centerTitle: true,
|
||||
title: const Text('Activity', style: TextStyle(fontSize: 15)),
|
||||
),
|
||||
@ -71,7 +69,6 @@ class _ActivityViewState extends State<ActivityView> {
|
||||
builder: (context, atm, child) {
|
||||
return IconButton(
|
||||
alignment: AlignmentDirectional.center,
|
||||
iconSize: 30,
|
||||
icon: atm.isActive
|
||||
? const Icon(Icons.pause_rounded)
|
||||
: const Icon(Icons.play_arrow_rounded),
|
||||
@ -99,7 +96,7 @@ class _ActivityViewState extends State<ActivityView> {
|
||||
child: Consumer<ActivityTimerModel>(
|
||||
builder: (context, atm, child) {
|
||||
return Text(
|
||||
style: const TextStyle(fontSize: 15),
|
||||
style: const TextStyle(fontSize: 12),
|
||||
textAlign: TextAlign.right,
|
||||
'${atm.currentAction['actionID'] + 1} of ${atm.totalActions()}');
|
||||
})),
|
||||
|
@ -72,7 +72,7 @@ class SessionCard extends StatelessWidget {
|
||||
type: 'fundamental',
|
||||
categories: ['technique', 'conditioning'],
|
||||
description:
|
||||
"Session focussed on attempting a climb at or beyond your perceived limit.",
|
||||
"Session focused on attempting a climb at or beyond your perceived limit.",
|
||||
actions: [
|
||||
ActivityAction(
|
||||
id: 1,
|
||||
@ -109,7 +109,7 @@ class SessionCard extends StatelessWidget {
|
||||
type: 'Hypertrophy',
|
||||
categories: ['Strength', 'Power'],
|
||||
description:
|
||||
"Block pull on a edge of a specific size and time to induce a hypotrophic effect on the formarms.",
|
||||
"Block pull on a edge of a specific size and time to induce a hypertrophic effect on the formarms.",
|
||||
actions: [
|
||||
ActivityAction(
|
||||
id: 1,
|
||||
|
Reference in New Issue
Block a user