Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

dart - how to fix flutter errror: another exception was thrown

Hello the dart code below has a series of errors when it executes the code I have the error below, how can I do to fix it?

Error:

 Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed
 assertion: line 4263 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.

React.js Code:

.. //Classe per la ricerca dei cantieri class RapportiniScreen extends StatefulWidget { const RapportiniScreen({Key key, this.animationController}) : super(key: key);

  final AnimationController animationController;

  @override
  _RapportiniScreenState createState() => _RapportiniScreenState();
}

class _RapportiniScreenState extends State<RapportiniScreen>
    with TickerProviderStateMixin {
  bool isShowingMainData = true;
  final ScrollController scrollController = ScrollController();
  Animation<double> topBarAnimation;
  double topBarOpacity = 0.0;


  @override
  void dispose() {
     listViews.clear();
    super.dispose();
  }

  //Disabilito il bottone di back su android
  bool myInterceptor(bool stopDefaultButtonEvent) {
    return true;
  }

  //Funzione di inizializzazione della View
  @override
  void initState() {
    BackButtonInterceptor.add(myInterceptor);
    topBarAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
            parent: widget.animationController,
            curve: Interval(0, 0.5, curve: Curves.fastOutSlowIn)));

    scrollController.addListener(() {
      if (scrollController.offset >= 24) {
        if (topBarOpacity != 1.0) {
          setState(() {
            topBarOpacity = 1.0;
          });
        }
      } else if (scrollController.offset <= 24 &&
          scrollController.offset >= 0) {
        if (topBarOpacity != scrollController.offset / 24) {
          setState(() {
            topBarOpacity = scrollController.offset / 24;
          });
        }
      } else if (scrollController.offset <= 0) {
        if (topBarOpacity != 0.0) {
          setState(() {
            topBarOpacity = 0.0;
          });
        }
      }
    });
    super.initState();
  }

  //Funzione che si occupa di aggiungere gli elementi alla lista dei widget
  Future<bool> addAllListData() async {
    //Eseguo il caricamento dei rapportini
    await ricercaRapportini("");

    try {
      //Aggiunta alla list della view corrispondente al cantiere
      if (rapportiniricercati != null) {
        //Eseguo la ricerca dei cantieri
        for (int i = 0; i < rapportiniricercati.length; i++) {
          //Aggiunta alla list della view corrispondente al cantiere
          listViews.add(
            new SchedaRapportiniView(
              animation: Tween<double>(begin: 0.0, end: 1.0).animate(
                  CurvedAnimation(
                      parent: widget.animationController,
                      curve: Interval((1 / 5) * 2, 1.0,
                          curve: Curves.fastOutSlowIn))),
              animationController: widget.animationController,
              rtemp: rapportiniricercati[i],
            ),
          );
        }
      }
    } catch (err) {
      print("Errore: " + err);
    }
    return true;
  }

  //Widget UiListView
  Widget getMainListViewUI() {
    return new ListView.builder(
        controller: scrollController,
        padding: EdgeInsets.only(
          top: AppBar().preferredSize.height +
              MediaQuery.of(context).padding.top +
              24,
          bottom: 62 + MediaQuery.of(context).padding.bottom,
        ),
        itemCount: listViews.length,
        scrollDirection: Axis.vertical,
        itemBuilder: (BuildContext context, int index) {
          widget.animationController.forward();
          return listViews[index];
        });
  }

  //Widget per la AppBarUI
  Widget getAppBarUI() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        AnimatedBuilder(
          animation: widget.animationController,
          builder: (BuildContext context, Widget child) {
            return FadeTransition(
              opacity: topBarAnimation,
              child: Transform(
                transform: Matrix4.translationValues(
                    0.0, 30 * (1.0 - topBarAnimation.value), 0.0),
                child: Container(
                  decoration: BoxDecoration(
                    color: TemaApp.white.withOpacity(topBarOpacity),
                    borderRadius: const BorderRadius.only(
                      bottomLeft: Radius.circular(32.0),
                    ),
                    boxShadow: <BoxShadow>[
                      BoxShadow(
                          color: TemaApp.grey.withOpacity(0.4 * topBarOpacity),
                          offset: const Offset(1.1, 1.1),
                          blurRadius: 10.0),
                    ],
                  ),
                  child: Column(
                    children: <Widget>[
                      SizedBox(
                        height: MediaQuery.of(context).padding.top,
                      ),
                      Padding(
                        padding: EdgeInsets.only(
                            left: 16,
                            right: 16,
                            top: 16 - 8.0 * topBarOpacity,
                            bottom: 12 - 8.0 * topBarOpacity),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            Expanded(
                              child: Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: Text(
                                  'Rapportini',
                                  textAlign: TextAlign.left,
                                  style: TextStyle(
                                    fontFamily: TemaApp.fontName,
                                    fontWeight: FontWeight.w700,
                                    fontSize: 22 + 6 - 6 * topBarOpacity,
                                    letterSpacing: 1.2,
                                    color: TemaApp.darkerText,
                                  ),
                                ),
                              ),
                            ),
                            //Bottone che effettua la ricerca dei rapportini
                            IconButton(
                                icon: Icon(Icons.search),
                                onPressed: () {
                                  showSearch(
                                      context: context,
                                      delegate: DataSourceRapportini(
                                          rapportiniricercati));
                                })
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
            );
          },
        )
      ],
    );
  }

  //Build
  @override
  Widget build(BuildContext context) {
    final _screenSize = MediaQuery.of(context).size;
    return FutureBuilder<bool>(
        future: addAllListData(),
        builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
          if (snapshot.hasError) {
            return new Container();
          } else {
            return new Container(
              color: TemaApp.background,
              height: _screenSize.height,
              child: Scaffold(
                backgroundColor: Colors.transparent,
                resizeToAvoidBottomPadding: true,
                body: Stack(
                  children: <Widget>[
                    getMainListViewUI(),
                    getAppBarUI(),
                    SizedBox(
                      height: MediaQuery.of(context).padding.bottom,
                    )
                  ],
                ),
              ),
            );
          }
        });
  }
}

//Classe che si occupa della gestione della ricerca dei rapportini
class DataSourceRapportini extends SearchDelegate<String> {
  List<Rapporto> listaRapportini = new List();
  DataSourceRapportini(this.listaRapportini);

  @override
  List<Widget> buildActions(BuildContext context) {
    return [
      IconButton(
          icon: Icon(Icons.clear),
          onPressed: () {
            query = "";
          })
    ];
  }

  @override
  Widget buildLeading(BuildContext context) {
    return IconButton(
        icon: AnimatedIcon(
          icon: AnimatedIcons.menu_arrow,
          progress: transitionAnimation,
        ),
        onPressed: () {
          Navigator.pop(context);
        });
  }

  @override
  Widget buildResults(BuildContext context) {
    return Container(
        //Do what you want to show in the result, when click keyboard action Search.

        );
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    var suggestionList = ricercaRapportini(query);

    return ListView.builder(
      itemBuilder: (context, index) => ListTile(
        leading: Icon(Icons.build),
        title: Text("Nome Cantiere: " +
            suggestionList[index].getCantiere().getNomeCantiere() +
            "
Cliente: " +
            suggestionList[index].getCantiere().getRagioneSociale() +
            "
IdRapporto: " +
            suggestionList[index].getIdRapportoUtente().toString()+"
Commessa:"+suggestionList[index].getCantiere().getCommessa()),
        //Funzione che esegue il tap sul ListTile
        //Quando viene eseguito il tap viene visualizzata la schermata del rapportino
        onTap: () {
          final gr = new GestioneRapportini(suggestionList[index]);
          Navigator.push(context, MaterialPageRoute(builder: (context) => gr));
        },
      ),
      itemCount: suggestionList.length,
    );
  }

  //Funzione che esegue la ricerca dei rapportini
  List<Rapporto> ricercaRapportini(String testoricerca) {
    List<Rapporto> ltemp = new List();
    ltemp = listaRapportini;
    if (testoricerca.length > 0) {
      //Ricerca per nome cantieri
      ltemp = rapportiniricercati
          .where((l) => l
              .getCantiere()
              .getNomeCantiere()
              .toLowerCase()
              .startsWith(testoricerca))
          .toList();
      //Ricerca per ragione sociale
      ltemp = ltemp +
          rapportiniricercati
              .where((l) => l
                  .getCantiere()
                  .getRagioneSociale()
                  .toLowerCase()
                  .startsWith(testoricerca))
              .toList();
      
      //Ricerca per commessa
      ltemp = ltemp +
          rapportiniricercati
              .where((l) => l
                  .getCantiere()
                  .getCommessa()
                  .toLowerCase()
                  .startsWith(testoricerca))
              .toList();
    }

    return ltemp;
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...