GotJimmy / accordion

Other
47 stars 44 forks source link

GetX Instance "ListController" block app #34

Closed vladox1975 closed 1 year ago

vladox1975 commented 1 year ago

Hi,

In the debugging console it tells me that a large number of ListController instances are being created. That ends up crashing my interface and disconnecting debugging.

imagen

vladox1975 commented 1 year ago

imagen

vladox1975 commented 1 year ago

imagen

vladox1975 commented 1 year ago

I run the clean command and pub get; but still the problem.

GotJimmy commented 1 year ago

Can you send me the code with the Accordion (and all accordion sections) so I can have a look?

vladox1975 commented 1 year ago

Hi,

import 'package:accordion/accordion.dart'; import 'package:flutter/material.dart'; import 'dart:convert'; import 'package:http/http.dart' as http;

Other imports....

class Ayuda extends StatefulWidget { @override _AyudaState createState() => _AyudaState(); }

class _AyudaState extends State { _AyudaState() {

}

List listaCertificados = []; List widgetsCertificados = []; Future recibirCertificados() async { listaCertificados.clear(); try { var url = Uri.parse( ); //an API final respuesta = await http.get(url); if (respuesta.statusCode == 200) { setState(() { var parsedJson = json.decode(respuesta.body); if (parsedJson["success"]) { for (final itemLote in parsedJson["resultado"]) listaCertificados.add(new Ayudas.fromJson(itemLote)); } int cont = 1; for (final item in listaCertificados) { YoutubePlayerController _controller = YoutubePlayerController( initialVideoId: item.video.toString(), flags: YoutubePlayerFlags( autoPlay: false, mute: false, loop: true, hideThumbnail: true, controlsVisibleAtStart: false), );

        widgetsCertificados.add(
       **AccordionSection(**
          leftIcon: Icon(
            Icons.help_rounded,
            color: Colors.white,
          ),
          isOpen: false,
          headerBackgroundColor:
              cont.isOdd ? Colors.blue : Color.fromRGBO(22, 101, 180, 1),
          header: Text(item.descripcion,
              style: TextStyle(color: Colors.white, fontSize: 17)),
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                child: Text(item.detalle),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(0, 15, 0, 0),
                child: YoutubePlayer(
                  controller: _controller,
                  liveUIColor: Colors.amber,
                ),
              )
            ],
          ),
        ));
        cont += 1;
      }
    });
  }
} catch (e) {

}

}

@override void initState() { if (mounted) { // setState(() => recibirCertificados(); // ); super.initState(); } }

@override Widget build(BuildContext context) { Responsive responsive = new Responsive(context); return new WillPopScope( onWillPop: () async { Navigator.of(context).pop(); return false; }, child: new Scaffold( appBar: new AppBar( toolbarHeight: responsive.dp(14), leading: new IconButton( icon: new Icon( Icons.arrow_back_rounded, size: 35.0, ), onPressed: () { Navigator.of(context).pop(); }), backgroundColor: Color.fromRGBO(22, 101, 180, 1), flexibleSpace: FlexibleSpaceBar( centerTitle: true, title: BannerSuperior( nombre: Users.objUser.nombre == '' ? null : Users.objUser.nombre, porcTopLogo: 0, porcBottomLogo: 1, porcTopLogin: 4, porcBottomLogin: 0, tipoOro: false, tipoInsumo: false, ), ), ), body: SafeArea( child: Container( margin: EdgeInsets.fromLTRB(0, 15, 0, 0), child: Accordion( maxOpenSections: 1, children: widgetsCertificados, ), ), ), ), ); } }

GotJimmy commented 1 year ago

Hard to say without all the imports. But you seem to create a list of AccordionSection separately ... have you tried moving the creation of those sections directly into the Accordion? Just a guess. Another idea would be to use the included example app and base your app on that by changing it. Getting the debug message from GetX is normal (see example app) and not an error itself.