0

I want to have a button of fixed width and height inside a container. But, for some reason button takes height and width of Container. I tried using SizedBox and ButtonTheme but they don't work as well.

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

void main() {
  debugPaintSizeEnabled = true;
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      // home: EditorScreen(),
      home: Scaffold(
        body: SafeArea(
          child: Container(
            height: 65,
            width: double.infinity,
            color: Colors.black,
            child: SizedBox(
              height: 50,
              width: 50,
              child: ButtonTheme(
                minWidth: 50,
                height: 50,
                child: FlatButton(
                  onPressed: () {},
                  color: Colors.red,
                  child: Text("Test"),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
5
  • ButtonTheme is not necessary. Commented Dec 19, 2020 at 11:12
  • flutter.dev/docs/development/ui/layout/constraints - read the first 3 paragraphs Commented Dec 19, 2020 at 11:47
  • 1
    your welcome - i said 3 paragraphs, but to be honest check all 29 examples they provide Commented Dec 19, 2020 at 13:05
  • I ended up checking the whole article lol. Commented Dec 19, 2020 at 14:11
  • 1
    "I ended up checking the whole article" - good for you ;-) Commented Dec 19, 2020 at 14:15

3 Answers 3

1

Specify for parent container alignment property.

Sign up to request clarification or add additional context in comments.

Comments

0

You could try adding padding to the container

Comments

0

If you add the button center of the container then wrap with Center widget or if you want some other alignment then please specify that using alignment property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.