android - Flutter 在应用栏上定位超链接

标签 android flutter dart flutter-layout

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

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,
    );
  }
}

最佳答案

@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';
    }
  }
}

demo

关于android - Flutter 在应用栏上定位超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59218249/

相关文章:

firebase - 如何将 Firestore 文档列表绑定(bind)到 Flutter 中的下拉菜单?

android Facebook : Not showing info in dialog

android - 如何让 Horizo​​ntalScrollView 与一个自定义 View 子项一起滚动

flutter - 如何实现这一目标?

flutter - 如何从我的 Flutter 代码中打开 Web 浏览器 (URL)?

Flutter 桌面 - 从 Dart 代码更改窗口标题

android - 按下主页按钮后如何停止播放音频?

android - 我的 Tic Tac Toe 应用程序有一个错误

flutter - 如何让黄色容器扩展并填充其紫色 parent 可用的其余空间

flutter - 跨多个屏幕使用的Flutter Stateful Widget得以重建