程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法在初始化程序中访问实例成员“小部件”。?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决无法在初始化程序中访问实例成员“小部件”。??

开发过程中遇到无法在初始化程序中访问实例成员“小部件”。?的问题如何解决?下面主要结合日常开发的经验,给出你关于无法在初始化程序中访问实例成员“小部件”。?的解决方法建议,希望对你解决无法在初始化程序中访问实例成员“小部件”。?有所启发或帮助;

我在 StatefulWidget 小部件中有一个 UserType 变量,我想要做的是当用户在不同的 BottomNavigationbarItem 之间导航时将此 UserType 变量的值传递到不同的 Screen,我想将此 UserType 变量传递到上传页面() 像下面的代码一样,但我遇到了错误,无法在初始化程序中访问实例成员“小部件”。请帮帮我?

the Value of UserType variable is alredy passed from othre page using HomePagecontroller(UserType:controllUserType)

User curentuser= _firebaseAuth.currentUser;
class HomePage extends StatefulWidget {
  final String UserType;
  const HomePage({Key key,@required this.UserType}):super(key: key);
  @overrIDe
  _HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
  final List<Widget>_children =
  [
      TimelinePage(),SearchPage(),//search(),UploadPage(UserSID: curentuser.uID,usertypes: Widget.UserType),NotificationsPage(),ProfilePage(userProfileID: curentuser.uID),];
  @overrIDe
  Widget build(BuildContext context) {
    return Scaffold(
      body: buildHomeScreen(),);
  }
  Scaffold buildHomeScreen() {
    return Scaffold(
      backgroundcolor: colors.black,body: _children[_CurrentIndex],bottomNavigationbar: CupertinoTabbar(
        currentIndex: _CurrentIndex,backgroundcolor: colors.black,onTap: onTabchangePage,activecolor: colors.green,inactivecolor: colors.white,items: [
          BottomNavigationbarItem(icon: Icon(Icons.home),Title: Text('home'),),BottomNavigationbarItem(icon: Icon(Icons.search)),BottomNavigationbarItem(icon: Icon(Icons.photo_camera,size: 40,)),BottomNavigationbarItem(icon: Icon(Icons.notifications)),BottomNavigationbarItem(icon: Icon(Icons.person_add_alt_1_sharp)),],);
  }
}
voID onTabchangePage(int index) {
  setState(() {
    _CurrentIndex=  index;
  });[here is the image for the error][1]

}
}

解决方法

更改您的代码如下,

User curentuser= _firebaseAuth.currentUser;
class HomePage extends StatefulWidget {
  final String UserType;
  late List<Widget>_children;
  HomePage({Key key,required this.UserType}):super(key: key){
  _children = 
  [
      TimeLinePage(),SearchPage(),//search(),UploadPage(UserSID: curentuser.uid,usertypes: widget.UserType),NotificationsPage(),ProfilePage(userProfileID: curentuser.uid),];
}
  @override
  _HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: buildHomeScreen(),);
  }
  Scaffold buildHomeScreen() {
    return Scaffold(
      backgroundColor: Colors.black,body: widget._children[_CurrentIndex],bottomNavigationBar: CupertinoTabBar(
        currentIndex: _CurrentIndex,backgroundColor: Colors.black,onTap: onTabchangePage,activeColor: Colors.green,inactiveColor: Colors.white,items: [
          BottomNavigationBarItem(icon: Icon(Icons.home),title: Text('home'),),BottomNavigationBarItem(icon: Icon(Icons.search)),BottomNavigationBarItem(icon: Icon(Icons.photo_camera,size: 40,)),BottomNavigationBarItem(icon: Icon(Icons.notifications)),BottomNavigationBarItem(icon: Icon(Icons.person_add_alt_1_sharp)),],);
  }
}
void onTabchangePage(int index) {
  setState(() {
    _CurrentIndex=  index;
  });[here is the image for the error][1]

}
}

大佬总结

以上是大佬教程为你收集整理的无法在初始化程序中访问实例成员“小部件”。?全部内容,希望文章能够帮你解决无法在初始化程序中访问实例成员“小部件”。?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: