andrea pirola
andrea pirola

Reputation: 101

Flutter change text position on top right

how can i change the position of my text in the top right? I try with "text.Align" but i think is for the alignment of text, and dont change the position... I try to put "new Align" but with no results, i try to change from the main file but nothing, i dont find the right propierties... Here my main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Test',
      theme: ThemeData(
        brightness: Brightness.dark
      ),
      home: Scaffold(
        body: Center(
          child: Hyperlink('www.test.com', 'test'),
        ),
      )
    );
  }
}

and here my hyperlink.dart

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

class Hyperlink extends StatelessWidget {
  final String _url;
  final String _text;

  Hyperlink(this._url, this._text);

  _launchURL() async {
    if (await canLaunch(_url)) {
      await launch(_url);
    } else {
      throw 'Could not launch $_url';
    }
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Text(_text,
        textAlign: TextAlign.right,
        style: TextStyle(
          color: Colors.white,
          decoration: TextDecoration.underline),
      ),
      onTap: _launchURL,
    );
  }
}

Upvotes: 2

Views: 15859

Answers (1)

Pro
Pro

Reputation: 3003

@andrea, you can put Text widget in Container and use Container alignment in hyperlink.dart like so,

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Container(
          alignment: Alignment.topRight,
          child: Text(
            _text,
            style: TextStyle(
                color: Colors.black, decoration: TextDecoration.underline),
          )),
      onTap: _launchURL,
    );
  }

Screenshot:

screenshot

Upvotes: 2

Related Questions