0

I am trying to create button widget from scratch and here is the code I have:

import 'package:flutter/material.dart';

class Button extends StatelessWidget {
  String _number;

  static const double _buttonMargin = 20.0;
  Button(this._number);

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(border: Border.all()),
        height: 50.0,
        width: 50.0,
        margin: const EdgeInsets.all(_buttonMargin),
        child: Text(
          _number,
          textAlign: TextAlign.center,
        ));
  }
}

I would like to know how can I align the numbers to be exactly in the middle of the container? The screenshot of what it looks like is attached. enter image description here

0

1 Answer 1

1

Wrap the Text widget using Align & set the alignment property to Alignment.center.

Align(
  alignment: Alignment.center,
  child: Text(
    _number,
    textAlign: TextAlign.center,
  ),
),
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.