是否可以在应用栏上放置使用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,
);
}
}
最佳答案
@andrea,您不需要使用InkWell /容器。您可以通过简单的按钮在appBar中使用 Action ,然后尝试类似的操作,
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';
}
}
}
关于android - Appbar上的Flutter定位超链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59218249/