2

I created these two files one is a class with a list, another is for animations, and the last one serves for display. How do I set the duration of the animation as I wrote in the list? if i put a number in duration like 60 but i want the duration is the int field duration list setEserciziAbs This is the code for model and list

class ExeAtempo{
  String nome;
  int duration;
  int id; 
  ExeAtempo({this.duration, this.id,this.nome});
}
const List setEserciziAbs =[
  {
    "nome": 'crunch',
    "duration" : 20,
    "id": 1
  },
  {
    "nome": 'pausa',
    "duration" : 30,
    "id": 2
  },
  {
    "nome": 'crunch',
    "duration" : 20,
    "id": 3
  },
  {
    "nome": 'reverse crunch',
    "duration" : 30,
    "id": 4
  }
];

this is the code for the animation and for the Pageview,

class AtempoController extends GetxController
    with SingleGetTickerProviderMixin {
  AnimationController _animationController;
  Animation _animation;
  Animation get animation => this._animation;
  List<ExeAtempo> _eserciziAtempo = setEserciziAbs
      .map(
        (esercizioAtempo) => ExeAtempo(
          id: esercizioAtempo['id'],
          nome: esercizioAtempo['nome'],
          duration: esercizioAtempo['duration']
        ),
      )
      .toList();
  List<ExeAtempo> get exesAtempo => this._eserciziAtempo;
  @override
  void onInit() {
    _animationController = AnimationController(duration: Duration(seconds: 30 ), vsync: this);
    _animation = Tween<double>(begin: 0, end: 1).animate(_animationController)..addListener(() {update();});
    super.onInit();
  }
}

with this code I visually display the widget for the list I wrote above


class BodyAtempo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    AtempoController _atempoController = Get.put(AtempoController());
    return Stack(
      children: [
        SafeArea(
          child: Column(
            children: [
              Expanded(
                
                child: PageView.builder(
                  itemCount: _atempoController.exesAtempo.length,
                  itemBuilder: (context, index) => EsercizioAtempoCard(
                    exeAtempo: _atempoController.exesAtempo[index],
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
class EsercizioAtempoCard extends StatelessWidget {
  const EsercizioAtempoCard({
    Key key, this.exeAtempo,
  }) : super(key: key);
  final ExeAtempo exeAtempo;
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(10),
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.blue[100],
      ),
      child: Column(
        children: [
          Text(exeAtempo.nome, style: TextStyle(color: Colors.black),)
        ],
      ),
    );
  }
}
Robbie53
  • 25
  • 3

0 Answers0