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

Sterlin V
  • 666
  • 2
  • 7
  • 12

1 Answers1

1

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

Align(
  alignment: Alignment.center,
  child: Text(
    _number,
    textAlign: TextAlign.center,
  ),
),
Tirth Patel
  • 5,443
  • 3
  • 27
  • 39