如何解决问题Appbar图标单击导航 [英] How solve problem Appbar icon clicked to navigate

查看:100
本文介绍了如何解决问题Appbar图标单击导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试开发flutter应用程序.在此应用程序中,我使用带有用户图标的Appbar浏览另一个页面.

I try to develop flutter application. In this application I used Appbar with user icon to navigate another page.

现在,我单击显示错误的图标(人形图标).

Now I am clicked that icon(person icon) it shows error.

.

它没有通过互联网提供的适当文档.我找不到答案.我的源代码是

It has not proper documentation though internet. I couldn't found answer. My source code is

class MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        home: new Scaffold(
            appBar: new AppBar(
              title: new Text("Web Issue finder"),
              actions: <Widget>[
                new IconButton(
                  icon: Icon(Icons.person),
//                  tooltip: "Admin",
                  onPressed: (){
                    Navigator.push(
                      context,
                      MaterialPageRoute(builder: (_) => AdminAuth()),
                    );
                  }
                )
              ],
            ),
            body: new FutureBuilder(
                future: loadStates(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    return new ListView.builder(
                      itemBuilder: (context, index) {
                        if (index >= snapshot?.data?.length ?? 0) return null;

                        return new ListTile(
                          title: new Text("${snapshot.data[index]}"),
                          onTap: () {
                            debugPrint("${snapshot.data[index]} clicked");
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                builder: (context) =>
                                    IssueAddScreen(state: snapshot.data[index]),
                              ),
                            );
                          },
                        );
                      },
                    );
                  } else {
                    return new Center(child: new CircularProgressIndicator());
                  }
                })));
  }

这是导航类

import 'package:flutter/material.dart';


class AdminAuth extends StatelessWidget{

//  final String state;

//  IssueAddScreen({Key key, @required this.state}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "iWallet",
      home: Scaffold(
        appBar: AppBar(title: Text("admin auth"),),
        body: Text("cvgbh"),
      ),

    );
  }

}

仍然无法解决该错误,但我仍然遵循一些文档和堆栈溢出问题.

Still I can't fix that error I am followed some documentation and stack overflow questions.

Flutter文档化

Github问题和答案

Stackoverflow问题与答案

推荐答案

IconButton(onPressed: () {
           Navigator.of(context).push(new MaterialPageRoute(builder: (context)=> AdminAuth));
        },)

这篇关于如何解决问题Appbar图标单击导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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