i'm new to flutter and i wanted to create simple design for menu app as shown in image below ... i tried below code but it didn't give same design, is there any way to achieve it?
Full working code:
import 'package:flutter/material.dart';
main() => runApp(const DemoApp());
class DemoApp extends StatefulWidget {
const DemoApp({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _DemoState();
}
}
class _DemoState extends State<DemoApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
color: Colors.white,
),
Positioned(
bottom: 150,
// replace with your Card here
child: Card(
child: Container(
width: 250,
height: 300,
color: Colors.blue,
),
),
),
Positioned(
bottom: 320,
// replace with your image here
child: Container(
width: 200,
height: 280,
color: Colors.pink,
),
),
],
),
),
);
}
}
CodePudding user response:
Here is a solution for this. You can also refer to the following link to learn more. https://www.flutterbeads.com/flutter-position-widget-in-stack/
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
decoration: const BoxDecoration(
color: Colors.redAccent,
//add your gradiant here
),
child: SafeArea(
child: Stack(
alignment: AlignmentDirectional.topCenter,
children: [
Positioned(
top: 180,
child: Container(
width: MediaQuery.of(context).size.width * 0.9,
height: 500,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(7),
),
),
),
Positioned(
top: 20,
child: Container(
width: MediaQuery.of(context).size.width * 0.7,
height: 200,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(7),
),
//add your image here
//child: Center(child: Image.asset(name)),
),
),
],
),
),
),
);
}
}