简体   繁体   中英

How to set a backgroud color in flutter with a circle shape?

I want to achieve this:

在此处输入图像描述

and I got this:

在此处输入图像描述

This is my code:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(

          decoration:  BoxDecoration
            (color:  Color(0xffF24004),

          ),
          child: Container(
            width: 202,
            height: 196,
              margin: EdgeInsets.all(100.0),
              decoration: BoxDecoration(
                shape: BoxShape.circle, color : Color(0xffF2B749),

              )),

        ),
      ),

    );

  }
}

I tried fit:BoxFit.cover but it doesn't work

So, how t solve this issue? Thank you in advance

You can give backgroundcolor to the Scaffold as well. Try out this below code.

Scaffold(
    backgroundColor: Color(0xffF24004),
    body: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          width: 202,
          height: 196,
          margin: EdgeInsets.all(100.0),
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: Color(0xffF2B749),
          ),
        ),
        // Add Another Icon Here
      ],
    ),
  ),

Remove the Center widget, you can also set the background color of the Scaffold directly

You can also use a Column right under the scaffold and set main, and cross axis alignments to center

But to achieve the design you posted you should probably use a Stack widget, coupled with Positioned widgets

Scaffold(
    backgroundColor: Color(0xffF24004),
    body: Center(
      child: Container(
        width: 202,
        height: 196,
        margin: EdgeInsets.all(100.0),
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: Color(0xffF2B749),
        ),
      ),
    ),
  ),

You have to give backgroundColor to Scaffold only:-

backgroundColor: Color(0xffF24004)

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