Flutter MaterialApp - 如何将AppBar标题用作链接

时间:2018-01-28 11:04:34

标签: android-studio dart flutter

我想将New Project模板创建的默认Flutter应用程序的AppBar标题转换为链接。这是我的代码:

having count(module) > 1

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

1 个答案:

答案 0 :(得分:0)

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