【问题标题】:Flutter positioning hyperlink on appbarappbar上的flutter定位超链接
【发布时间】:2019-12-06 18:06:15
【问题描述】:

是否可以在应用栏上放置使用 url_launcher 创建的超链接?这里是我的意思https://ibb.co/X28TzNN“Sito Web”的屏幕是我要更改位置的超链接,需要将其移动到红色圆圈中。这里是我的 AppBar

class BackgroundImage extends StatelessWidget{
  final Widget body;
  BackgroundImage({this.body});
    @override
    Widget build(BuildContext context){
      return Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text('Blumax', style: TextStyle(
            fontWeight: FontWeight.w500,
            fontFamily: 'DancingScript',
            fontSize: 40
          ),),
          centerTitle: false,
        ),
        body: Stack(
          children: <Widget>[Container(
          decoration: BoxDecoration(
            image: DecorationImage(image: AssetImage("assets/whiteimage.jpg"), fit: BoxFit.cover),
          ),
        ),
          body
        ]
      )
    );
  }
}

这就是我为将文本放置在右上角所做的操作

  Widget build(BuildContext context) {
    return InkWell(
      child: Container(
        alignment: Alignment(0.9, -1.0),
      child: Text(
        _text,
        textAlign: TextAlign.right,
        style: TextStyle(
          fontFamily: 'RobotoMono',
          fontSize: 20,
          color: Colors.white,
          decoration: TextDecoration.underline),
      )),
      onTap: _launchURL,
    );
  }
}

【问题讨论】:

    标签: android flutter dart flutter-layout


    【解决方案1】:

    @andrea,你不需要使用 InkWell/Container。您可以通过简单的按钮在 appBar 中使用操作并尝试这样的操作,

    class MyAppState extends State<MyApp> {
      String _text = 'Link';
      String _url = 'https://www.test.com';
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
            home: Scaffold(
                appBar: AppBar(
                  title: Text('Test'),
                    actions: <Widget>[
                      FlatButton(
                        child: Text(_text, style: TextStyle(fontSize: 18.0, color: Colors.white)),
                        onPressed: _launchURL,
                      ),
                      IconButton(icon: Icon(Icons.more_vert, color: Colors.white), onPressed: (){})
                    ]
                ),
                body: Padding(
                      padding: EdgeInsets.all(20.0),
                      child: Center(
                        child: Text('')
                      )
                      )
                )
                );
      }
    
      _launchURL() async {
        if (await canLaunch(_url)) {
          await launch(_url);
        } else {
          throw 'Could not launch $_url';
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      尝试在 AppBar 中使用 actions,您可以使用 FlatButtonInkwell 或任何在内部为您提供触摸事件的 Widget。

      appBar: AppBar(
              title: Text(Lang.treeView),
              actions: <Widget>[
            InkWell(
            child: Container(
                alignment: Alignment(0.9, -1.0),
              child: Text(
                "ABC",
                textAlign: TextAlign.right,
                style: TextStyle(
                    fontFamily: 'RobotoMono',
                    fontSize: 20,
                    color: Colors.white,
                    decoration: TextDecoration.underline),
              ))),
              ],
            )
      

      【讨论】:

        猜你喜欢
        • 2021-02-10
        • 2020-11-24
        • 2019-08-08
        • 2019-05-08
        • 2021-02-23
        • 2018-07-07
        • 2018-10-28
        • 2018-03-09
        • 2019-01-27
        相关资源
        最近更新 更多