[英]Flutter positioning hyperlink on appbar
是否可以在应用栏上放置使用 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,
);
}
}
在 AppBar 中尝试actions
,您可以拥有FlatButton
或Inkwell
或任何为您提供触摸事件的小部件。
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),
))),
],
)
@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';
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.