简体   繁体   中英

Flutter positioning hyperlink on appbar

Is possible to position an hyperlink created with url_launcher on the appbar? Here a screen of what i mean https://ibb.co/X28TzNN "Sito Web" is the hyperlink i want to change position, need move it in the red cirle. Here my 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
        ]
      )
    );
  }
}

And that's is what i did for position the text in the top right

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

try actions in AppBar, You can have FlatButton or Inkwell or any Widget that gives you a touch event inside.

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, you don't need to use InkWell/Container. You can use actions in appBar with simple button and try something like this,

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

演示

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM