I am reproducing the design from the following image:
Code:
import 'package:flutter/material.dart';
class PlanetBox extends StatelessWidget {
const PlanetBox({super.key});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.all(10),
width: 200,
height: 300,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Column(children: [
Image.asset('assets/images/planets/1_sun.png',
alignment: Alignment.topCenter),
const SizedBox(height: 20),
const Text(
"Sun",
textAlign: TextAlign.left,
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
const SizedBox(height: 5),
const Text(
"The Sun is the star at the center of the Solar System. It is a nearly perfect ball of hot plasma, heated to incandescence by nuclear fusion reactions in its core.",
textAlign: TextAlign.left,
style: TextStyle(fontSize: 15),
)
]));
}
}
currently, my planet image is inside the box decoration
How can I change the position of the planet image (assets/images/planets/1_sun.png) and also add a background text (light grey 3 on the right side in reference design) in a container?
2
Answers
You can add some background text by using a Stack Widget to place the children of the Container on top of each other like the following:
In this example the "3" is rendered similar to your reference picture.
And of course you could also add another
Positioned
widget for your image to position it with a distance to a corner.Your major concern is for you to position your planet image?
So, you can do that simply by wrapping your card widget in Stack widget and then add the image with a Positioned widget to which you can give it a negative property and you will be good to go.
Using Niko’s code from above, I made a few changes and implemented the pageview builder. You can check the whole code here