gpt4 book ai didi

android-studio - Flutter MaterialApp - 如何使用 AppBar 标题作为链接

转载 作者:IT王子 更新时间:2023-10-29 07:07:00 25 4
gpt4 key购买 nike

我想将新建项目模板创建的默认 Flutter 应用的 AppBar 的标题变成一个链接。这是我的代码:

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'WaterFlow Target',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'WaterFlow'),
);
}
}

在第 9 行中,您可以看到带有 title 参数的 MyHomePage 构造函数调用。

最佳答案

url_launcher 插件添加到您的 pubspec.yaml

dependencies:
url_launcher: 2.0.1

编写这段代码:

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class TitleLink extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
elevation: 0.5,
centerTitle: true,
title: new InkWell(
child: new Text("www.google.com"),
onTap: () => launch('https://google.com'),
),
),
body: new Center(child: new Text("Tap on Title to open Google"))
);
}
}

关于android-studio - Flutter MaterialApp - 如何使用 AppBar 标题作为链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48485633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com