为什么我收到此Tabbar控制器错误? [英] Why im getting this Tabbar controller error?

查看:105
本文介绍了为什么我收到此Tabbar控制器错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我修复了这样的错误

   Expanded(
              child: TabBarView(
                controller: _tabController,
                children: <Widget>[
                  Openalldocs(
                    searchinginput: searchcontroller,
                  ),
                  Center(
                    child: Text('It\'s cloudy here'),
                  ),
                  Center(
                    child: Text('It\'s cloudy here'),
                  ),
                ],

这个错误

he following assertion was thrown while finalizing the widget tree:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4109 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true.
2

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack
#2      Element.markNeedsBuild
package:flutter/…/widgets/framework.dart:4109
#3      State.setState
package:flutter/…/widgets/framework.dart:1287
#4      _OpenalldocsState._onsearchChanged
package:wichtigdenyady/homesearchingall/openalldocs.dart:54
#5      _OpenalldocsState.dispose
package:wichtigdenyady/homesearchingall/openalldocs.dart:42
#6      StatefulElement.unmount
package:flutter/…/widgets/framework.dart:4721

我要来这里

这里是我的代码在我在下一行设置}}并在dispose中的其他位置设置了no user found = false之后,在没有代码停留的底部的方法中设置了第一个错误,这是在onsearchchanged方法中抛出的

Heres my code the first error is thrown in the onsearchchanged method after I set no user found = false in the next line where this tays }) and the other in the where in the dispose ,method on the bottom where no code stays just this }


class Openalldocs extends StatefulWidget {
  final TextEditingController searchinginput;
  static const route = '/openalldocs';

  const Openalldocs({Key key, this.searchinginput}) : super(key: key);

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

class _OpenalldocsState extends State<Openalldocs> {
  List _allResults = [];
  List _resultsList = [];
  Future resultsLoaded;
  bool nosuerfound = false;
  String userID = FirebaseAuth.instance.currentUser.uid;

  @override
  void initState() {
    super.initState();
    widget.searchinginput.addListener(_onsearchChanged);
    setState(() {
      nosuerfound = true;
    });
  }

  @override
  void dispose() {
    widget.searchinginput.removeListener(_onsearchChanged());
    super.dispose();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    resultsLoaded = getusers();
  }

  _onsearchChanged() {
    if (this.mounted)
      setState(() {
        nosuerfound = false;
      });
    searchResults();
  }

  searchResults() {
    var showResults = [];
    if (widget.searchinginput.text != "") {
      for (var tripsnapshot in _allResults) {
        var title = DatbaseService.instance
            .userDataFromSnapshot(tripsnapshot)
            .username
            .toLowerCase();
        if (title.contains(widget.searchinginput.text.toLowerCase())) {
          setState(() {
            nosuerfound = true;
          });
          showResults.add(tripsnapshot);
        }
      }
    } else {
      setState(() {
        nosuerfound = true;
      });
      showResults = List.from(_allResults);
    }
    setState(() {
      _resultsList = showResults;
    });
  }

  getusers() async {
    var firestore = FirebaseFirestore.instance;

    QuerySnapshot qn = await firestore.collection('meinprofilsettings').get();
    setState(() {
      _allResults = qn.docs;
    });
    searchResults();
    return "Complete";
  }

  @override
  Widget build(BuildContext context) {
    final user = Provider.of<Userforid>(context);
    if (nosuerfound == true) {
      return Container(
          child: ListView.builder(
              itemCount: _resultsList.length,
              itemBuilder: (BuildContext context, int index) {
                return ListTile(
                  onTap: () {
                    DatbaseService.instance.createorGetConversation(
                        user.uid, _resultsList[index].id,
                        (String _conversationID) {
                      NavigationService.instance.navigateToRoute(
                        MaterialPageRoute(builder: (context) {
                          return MeineBeitraege(
                              _conversationID,
                              _resultsList[index].id,
                              _resultsList[index].data()['username'],
                              _resultsList[index].data()['url'],
                              _resultsList[index].data()['email']);
                        }),
                      );
                    });
                  },
                  leading: Container(
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(60),
                      child: Container(
                          height: 50,
                          width: 50,
                          decoration: BoxDecoration(
                            color: Colors.white,
                          ),
                          child: _resultsList[index].data()['url'] != null &&
                                  _resultsList[index].data()['url'] !=
                                      "profilepictureer"
                              ? Image.network(
                                  _resultsList[index].data()['url'],
                                  fit: BoxFit.cover,
                                )
                              : Image.asset(
                                  'assets/profilepictureer.png') // Your widget is here when image is no available.
                          ),
                    ),
                    decoration: new BoxDecoration(
                      shape: BoxShape.circle,
                      border: new Border.all(color: Colors.black, width: 4),
                    ),
                  ),
                  title: Text(_resultsList[index].data()['username']),
                  subtitle: Text(_resultsList[index].data()['email']),
                );
              }));
    } else {
      return Padding(
        padding: const EdgeInsets.fromLTRB(0, 30, 0, 0),
        child: Container(
            child: Text(
          "No match",
          style: TextStyle(fontSize: 16),
        )),
      );
    }
  }
}

如果您有任何问题,请发表评论.如果您需要更多信息,请同时发表评论

If you have any question please leave a comment . if you need more information please leave also a comment

推荐答案

将您的 TabBarView 更改为此:

         Container(
            height: 200,
            child: TabBarView(
              controller: _tabController,
              children: <Widget>[
                SingleChildScrollView(
                  child: Center(
                    child: Text('It\'s cloudy here'),
                  ),
                ),
                SingleChildScrollView(
                  child: Center(
                    child: Text('It\'s cloudy here'),
                  ),
                ),
                SingleChildScrollView(
                  child: Center(
                    child: Text('It\'s cloudy here'),
                  ),
                ),
              ],
            ),
          ),

完整代码:

    import 'package:flutter/material.dart';

    void main() {
      runApp(MyApp());
    }

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            backgroundColor: Colors.grey,
            body: Center(
              child: Searchuserinhomepage(),
            ),
          ),
        );
      }
    }

    class Searchuserinhomepage extends StatefulWidget {
      @override
      _SearchuserinhomepageState createState() => _SearchuserinhomepageState();
    }

    class _SearchuserinhomepageState extends State<Searchuserinhomepage>
        with TickerProviderStateMixin {
      TabController _tabController;

      final searchcontroller = new TextEditingController();
      bool isSearching = false;
      bool isuserssearching = false;
      bool ishashtagssearching = false;
      bool alluserssearching = false;

      Widget searchUserslist() {
        return searchUserslist();
      }

      @override
      void initState() {
        super.initState();
        _tabController = TabController(length: 3, vsync: this);
      }

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.grey[500],
          resizeToAvoidBottomInset: false,
          appBar: AppBar(
            automaticallyImplyLeading: false,
            leading: IconButton(
              icon: Icon(Icons.arrow_back_ios),
              onPressed: () {},
            ),
            backgroundColor: Colors.transparent,
            elevation: 0.0,
          ),
          body: GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              FocusScope.of(context).requestFocus(FocusNode());
            },
            child: Container(
              margin: EdgeInsets.symmetric(
                horizontal: 20,
              ),
              child: Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.fromLTRB(0, 0, 50, 0),
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: Container(
                          height: 45,
                          margin: EdgeInsets.symmetric(vertical: 5),
                          padding: EdgeInsets.symmetric(horizontal: 16),
                          decoration: BoxDecoration(
                            color: Colors.grey[100],
                            border: Border.all(
                                color: Colors.grey[100],
                                width: 0,
                                style: BorderStyle.solid),
                            borderRadius: BorderRadius.circular(18),
                          ),
                          child: Row(
                            children: [
                              Expanded(
                                child: Padding(
                                  padding: const EdgeInsets.fromLTRB(0, 0, 0, 3),
                                  child: TextField(
                                      controller: searchcontroller,
                                      decoration: InputDecoration(
                                        prefixIcon: Icon(
                                          Icons.search,
                                          color: Colors.black,
                                        ),
                                        border: InputBorder.none,
                                        hintText: "search...",
                                      ),
                                      onTap: () {
                                        setState(() {
                                          isSearching = true;
                                          alluserssearching = true;
                                          ishashtagssearching = false;
                                          isuserssearching = false;
                                        });
                                      }),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                      isSearching
                          ? GestureDetector(
                              onTap: () {
                                searchcontroller.clear();
                              },
                              child: Container(
                                child: Text(
                                  " Delete",
                                  style: TextStyle(fontSize: 17),
                                ),
                              ),
                            )
                          : Container()
                    ],
                  ),
                  isSearching
                      ? TabBar(
                          controller: _tabController,
                          tabs: [
                            Tab(
                              icon: Icon(Icons.cloud_outlined),
                            ),
                            Tab(
                              icon: Icon(Icons.beach_access_sharp),
                            ),
                            Tab(
                              icon: Icon(Icons.brightness_5_sharp),
                            ),
                          ],
                        )
                      : Container(),
                  Container(
                    height: 200,
                    child: TabBarView(
                      controller: _tabController,
                      children: <Widget>[
                        SingleChildScrollView(
                          child: Center(
                            child: Text('It\'s cloudy here'),
                          ),
                        ),
                        SingleChildScrollView(
                          child: Center(
                            child: Text('It\'s cloudy here'),
                          ),
                        ),
                        SingleChildScrollView(
                          child: Center(
                            child: Text('It\'s cloudy here'),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        );
      }
    }

输出:

这篇关于为什么我收到此Tabbar控制器错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆