Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在颤振中显示底部导航栏上方的抽屉_Flutter_Dart - Fatal编程技术网

Flutter 在颤振中显示底部导航栏上方的抽屉

Flutter 在颤振中显示底部导航栏上方的抽屉,flutter,dart,Flutter,Dart,我在应用程序栏中有一个抽屉,需要在底部导航栏上显示它,但不能将两者放在同一个视图中,我不知道该怎么做。 及 这是appbar所在视图代码的一部分 class ContactsPage extends StatefulWidget { final String title; final String token; final String qr; String code; final String name; ContactsPage({this.name, this.t

我在应用程序栏中有一个抽屉,需要在底部导航栏上显示它,但不能将两者放在同一个视图中,我不知道该怎么做。 及

这是appbar所在视图代码的一部分

class ContactsPage extends StatefulWidget {
  final String title;
  final String token;
  final String qr;
  String code;
  final String name;

  ContactsPage({this.name, this.token, this.qr, this.code, Key key, this.title})
      : super(key: key);

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

class _ContactsPageState extends State<ContactsPage> {
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  List<Contact> contactList;
  bool showHorizontalBar = false;
  bool ready = false;

  @override
  void initState() {
    super.initState();
    var userService = new UserService();
    userService.getContacts(widget.token).then((value) => {
          print(value),
          if (value == '0')
            {
              Navigator.pushReplacement(
                  context, MaterialPageRoute(builder: (context) => LoginPage()))
            }
          else if (value == '3')
            {
              Navigator.pushReplacement(
                  context, MaterialPageRoute(builder: (context) => LoginPage()))
            }
          else
            {
              setState(() {
                contactList = value;
                ready = true;
              })
            },

          print(contactList),
        });
  }

  void showMessage(String message, [MaterialColor color = Colors.red]) {
    _scaffoldKey.currentState..removeCurrentSnackBar();
    _scaffoldKey.currentState.showSnackBar(
        new SnackBar(backgroundColor: color, content: new Text(message)));
  }

  _navigateAndDisplaySelection(BuildContext context) async {
    final result = await Navigator.push(
      context,
      MaterialPageRoute(
          builder: (context) => Scanner(
                qr: widget.qr,
                token: widget.token,
              )),
    );

    if (result != null) {
      showMessage('$result', Colors.red);
    }
  }

  Widget _addPerson() {
    return FloatingActionButton(
      onPressed: () {
        _navigateAndDisplaySelection(context);
      },
      child: Icon(Icons.group_add),
      backgroundColor: Color(0xff83bb37),
    );
  }

  Widget buildMenuIcon() {
    return IconButton(
      icon: Icon(showHorizontalBar ? Icons.close : Icons.more_horiz),
      onPressed: () {
        setState(() {
          showHorizontalBar = !showHorizontalBar;
        });
      },
    );
  }

  Widget _simplePopup() => PopupMenuButton<int>(
        itemBuilder: (context) => [
          PopupMenuItem(
            child: Row(
              children: <Widget>[
                IconButton(
                  icon: Icon(
                    Icons.delete,
                    color: Color(0xff83bb37),
                  ),
                  onPressed: () => {},
                ),
                IconButton(
                  icon: Icon(
                    Icons.favorite,
                    color: Color(0xff83bb37),
                  ),
                  onPressed: () => {},
                ),
                IconButton(
                  icon: Icon(
                    Icons.mail,
                    color: Color(0xff83bb37),
                  ),
                  onPressed: () => {},
                ),
                IconButton(
                  icon: Icon(
                    Icons.calendar_today,
                    color: Color(0xff83bb37),
                  ),
                  onPressed: () => {},
                ),
                IconButton(
                  icon: Icon(
                    Icons.call,
                    color: Color(0xff83bb37),
                  ),
                  onPressed: () => {},
                ),
              ],
            ),
          )
        ],
        icon: Icon(
          Icons.more_horiz,
          size: 20,
          color: Color(0xff4d4c48),
        ),
      );

  Widget _card(String first_name, String last_name, String email) {
    return Card(
      clipBehavior: Clip.antiAlias,
      child: Column(
        children: [
          SizedBox(
            height: 5.0,
          ),
          ListTile(
            leading: ClipRRect(
              borderRadius: BorderRadius.circular(13.0),
              child: Image.asset(
                'assets/images/mujer.jpg',
                width: 60.0,
                height: 70.0,
                fit: BoxFit.cover,
              ),
            ),
            title: Row(
              children: [
                Text(
                  first_name,
                  style: TextStyle(
                      fontWeight: FontWeight.bold, color: Color(0xff4d4c48)),
                ),
                SizedBox(width: 5.0),
                Text(
                  last_name,
                  style: TextStyle(
                      fontWeight: FontWeight.bold, color: Color(0xff4d4c48)),
                )
              ],
            ),
            subtitle: Container(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    email,
                    style: TextStyle(color: Color(0xff4d4c48)),
                  ),
                  SizedBox(
                    height: 5.0,
                  ),
                  Text(
                    'Prowebglobal',
                    style: TextStyle(
                        color: Color(0xff4d4c48), fontWeight: FontWeight.w600),
                  ),
                ],
              ),
            ),
            trailing: _simplePopup(),
            onTap: () {
              Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (context) =>
                          ContactDetails(token: widget.token, email: email)));
            },
          ),
          SizedBox(
            height: 20.0,
          ),
        ],
      ),
    );
  }

  Widget textContainer(String string, Color color) {
    return new Container(
      child: new Text(
        string,
        style: TextStyle(
            color: color, fontWeight: FontWeight.normal, fontSize: 16.0),
        textAlign: TextAlign.start,
        maxLines: 2,
        overflow: TextOverflow.ellipsis,
      ),
      margin: EdgeInsets.only(bottom: 10.0),
    );
  }

  Widget _titulo() {
    return new Container(
      alignment: Alignment.topLeft,
      padding: EdgeInsets.only(left: 20.0),
      child: new Text(
        'Contactos',
        style: TextStyle(
            color: Color(0xff83bb37),
            fontWeight: FontWeight.bold,
            fontSize: 25.0),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      backgroundColor: Colors.white,
      drawer: NavDrawer(
        token: widget.token,
      ),
      appBar: AppBar(
          centerTitle: true,
          backgroundColor: Color(0xfff0f0f0),
          title: Image.asset(
            'assets/images/logo-iso.png',
            height: 50.0,
            fit: BoxFit.contain,
            alignment: Alignment.center,
          ),
          iconTheme: new IconThemeData(color: Color(0xff707070)),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.search),
              onPressed: () {
              },
            ),
          ]),
      body: Column(children: [
        SizedBox(
          height: 20.0,
        ),
        Expanded(
          flex: 2,
          child: _titulo(),
        ),
        Expanded(
          flex: 20,
          child: Container(
            child: ready
                ? ListView(
                    children: contactList
                        .map(
                          (Contact contact) => _card("${contact.first_name}",
                              "${contact.last_name}", "${contact.email}"),
                        )
                        .toList())
                : Center(
                    child: Image.asset(
                      "assets/images/logo-gif.gif",
                      height: 125.0,
                      width: 125.0,
                    ),
                  ),
          ),
        ),
      ]),
      floatingActionButton: _addPerson(),
    );
  }
}
class ContactsPage扩展StatefulWidget{
最后的字符串标题;
最终字符串标记;
最终字符串qr;
字符串代码;
最后的字符串名;
ContactsPage({this.name,this.token,this.qr,this.code,Key-Key,this.title})
:super(key:key);
@凌驾
_ContactsPageState createState()=>_ContactsPageState();
}
类_ContactsPageState扩展状态{
最终GlobalKey _scaffoldKey=新的GlobalKey();
列出联系人名单;
bool showHorizontalBar=假;
bool ready=false;
@凌驾
void initState(){
super.initState();
var userService=new userService();
userService.getContacts(widget.token).then((值)=>{
打印(值),
如果(值='0')
{
导航器。更换(
上下文,MaterialPage路由(生成器:(上下文)=>LoginPage())
}
else if(值='3')
{
导航器。更换(
上下文,MaterialPage路由(生成器:(上下文)=>LoginPage())
}
其他的
{
设置状态(){
联系人列表=值;
就绪=正确;
})
},
打印(联系人列表),
});
}
void showMessage(字符串消息,[MaterialColor=Colors.red]){
_scaffoldKey.currentState..removeCurrentSnackBar();
_scaffoldKey.currentState.showSnackBar(
新SnackBar(背景颜色:颜色,内容:新文本(消息));
}
_navigateAndDisplaySelection(BuildContext上下文)异步{
最终结果=等待Navigator.push(
上下文
材料路线(
生成器:(上下文)=>扫描仪(
qr:widget.qr,
token:widget.token,
)),
);
如果(结果!=null){
showMessage(“$result”,颜色为红色);
}
}
小部件_addPerson(){
返回浮动操作按钮(
已按下:(){
_导航显示选择(上下文);
},
子:图标(图标。组添加),
背景颜色:颜色(0xff83bb37),
);
}
Widget buildMenuIcon(){
返回图标按钮(
图标:图标(显示水平线?图标。关闭:图标。更多水平线),
已按下:(){
设置状态(){
showHorizontalBar=!showHorizontalBar;
});
},
);
}
小部件_simplePopup()=>PopupMenuButton(
itemBuilder:(上下文)=>[
PopupMenuItem(
孩子:排(
儿童:[
图标按钮(
图标:图标(
图标。删除,
颜色:颜色(0xff83bb37),
),
按下:()=>{},
),
图标按钮(
图标:图标(
我的最爱,
颜色:颜色(0xff83bb37),
),
按下:()=>{},
),
图标按钮(
图标:图标(
Icons.mail,
颜色:颜色(0xff83bb37),
),
按下:()=>{},
),
图标按钮(
图标:图标(
Icons.calendar_今天,
颜色:颜色(0xff83bb37),
),
按下:()=>{},
),
图标按钮(
图标:图标(
图标。呼叫,
颜色:颜色(0xff83bb37),
),
按下:()=>{},
),
],
),
)
],
图标:图标(
图标。更多信息,
尺码:20,
颜色:颜色(0xff4d4c48),
),
);
小部件卡片(字符串名字、字符串姓氏、字符串电子邮件){
回程卡(
clipBehavior:Clip.antiAlias,
子:列(
儿童:[
大小盒子(
身高:5.0,
),
列表砖(
前导:ClipRRect(
边界半径:边界半径。圆形(13.0),
子:Image.asset(
“assets/images/mujer.jpg”,
宽度:60.0,
身高:70.0,
适合:BoxFit.cover,
),
),
标题:世界其他地区(
儿童:[
正文(
名字,
样式:TextStyle(
fontWeight:fontWeight.bold,颜色:颜色(0xff4d4c48)),
),
尺寸箱(宽度:5.0),
正文(
姓,
样式:TextStyle(
fontWeight:fontWeight.bold,颜色:颜色(0xff4d4c48)),
)
],
),
字幕:集装箱(
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
正文(
电子邮件,
样式:TextStyle(颜色:颜色(0xff4d4c48)),
),
大小盒子(
身高:5.0,
),
正文(
“Prowebglobal”,
样式:TextStyle(
颜色:颜色(0xff4d4c48),fontWeight:fontWeight.w600),
),
],
),
),
尾随:_simplePopup(),
onTap:(){
导航器。推(
上下文
材料路线(
生成器:(上下文)=>
联系人详细信息(令牌:widget.token,电子邮件:email));
},
),
大小盒子(
class HomePage extends StatefulWidget {
  HomePage({
    this.token,
    this.code,
    Key key,
  }) : super(key: key);

  final String token;
  final String code;

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

class _HomePageState extends State<HomePage> {
  String currentPage = 'contacts';

  changePage(String pageName) {
    setState(() {
      currentPage = pageName;
    });
  }

  @override
  Widget build(BuildContext context) {
    final Map<String, Widget> pageView = <String, Widget>{
      "contacts": ContactsPage(
        code: widget.code,
        token: widget.token,
      ),
      "profile": ProfilePage(
        token: widget.token,
      ),
    };

    return Scaffold(
      body: pageView[currentPage],
      bottomNavigationBar: new BottomNavigationDot(
        paddingBottomCircle: 21,
        color: Colors.black.withOpacity(0.5),
        backgroundColor: Colors.white,
        activeColor: Colors.black,
        items: [
          new BottomNavigationDotItem(
              icon: Icons.home,
              onTap: () {
                changePage("contacts");
              }),
          new BottomNavigationDotItem(icon: Icons.brush, onTap: () {}),
          new BottomNavigationDotItem(icon: Icons.notifications, onTap: () {}),
          new BottomNavigationDotItem(icon: Icons.favorite, onTap: () {}),
          new BottomNavigationDotItem(
              icon: Icons.person,
              onTap: () {
                changePage("profile");
              }),
        ],
        milliseconds: 400,
      ),
    );
  }
}