i am new to flutter. How can I indent the corners like in the picture? Thanks for answers.
exapmle
You should be checking if the problem you faced asked before. There are tons of sources related to this.
1- There are containers with one rounded border in the example video you provided. To achieve that, check the following code:
BoxDecoration(
color: color,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(100.0),
),
);
2- To have multiple containers on top of each other, you need to use the Stack widget like the following:
Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.90,
decoration: decoration(Colors.black),
),
Container(
height: MediaQuery.of(context).size.height * 0.70,
decoration: decoration(Colors.purple),
),
Container(
height: MediaQuery.of(context).size.height * 0.45,
decoration: decoration(Colors.pink),
),
Container(
height: MediaQuery.of(context).size.height * 0.20,
decoration: decoration(Colors.white),
),
],
),
Complete code main.dart:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) => 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) => Scaffold(
backgroundColor: Colors.grey,
body: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.90,
decoration: decoration(Colors.black),
),
Container(
height: MediaQuery.of(context).size.height * 0.70,
decoration: decoration(Colors.purple),
),
Container(
height: MediaQuery.of(context).size.height * 0.45,
decoration: decoration(Colors.pink),
),
Container(
height: MediaQuery.of(context).size.height * 0.20,
decoration: decoration(Colors.white),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Add',
backgroundColor: Colors.white,
child: const Icon(
Icons.add,
color: Colors.black,
),
),
);
BoxDecoration decoration(Color color) => BoxDecoration(
color: color,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(100.0),
),
);
}
You can also access the complete source code through GitHub.
If you have further questions, please don't hesitate to write in the comments.
Related
Screenshot of a mobile app ui design.
Play with this widget and follow flutter.dev/development/ui/layout
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
#override
Widget build(BuildContext context) {
return MaterialApp(title: _title, home: SampleW());
}
}
class SampleW extends StatelessWidget {
const SampleW({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueGrey,
body: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
child: Column(
children: [
Container(
height: constraints.maxHeight * .4,
alignment: Alignment.center,
child: CircleAvatar(
radius: constraints.maxWidth * .2,
backgroundColor: Colors.amber,
),
),
Container(
height: constraints.maxHeight, // will get by column
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24),
topRight: Radius.circular(24),
)),
)
],
),
),
),
);
}
}
This will give you
You can use like this:
Scaffold (
backgroundColor: Colors.red,
body: Align(
alignment: Alignment.bottomCenter,
child: Container(
height: MediaQuery.of(context).size.height * 0.6,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(12),topRight: Radius.circular(12)),
),
),
)
)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
i want to make button like this
The background is of different colors and shapes
Text and icon
Here is a complete code for making one of the buttons. you can play with bordet radius to build other buttons as well.
enter code here import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
final Overlay overlay = const Overlay();
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: '3D Button',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const Home(),
);
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: colors[50],
appBar: AppBar(
title: const Center(
child: Text("3D Button"),
),
),
// body: const ClickyButtonPage(),
body: Center(child: const Custom3DButton()),
);
}
}
const MaterialColor colors = Colors.blue;
const MaterialColor colors2 = Colors.grey;
class Custom3DButton extends StatelessWidget {
const Custom3DButton({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
double _width = 220;
double _height = 65;
double _sideWidth = 180;
var _borderRadius = const Radius.circular(50);
return Container(
width: _width,
height: 70.0,
child: GestureDetector(
child: Stack(children: <Widget>[
Positioned(
bottom: 0,
child: Container(
width: _width,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: colors[800],
),
),
),
Positioned(
left: 0,
bottom: 0,
child: Container(
width: _sideWidth * 5 / 6,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: _borderRadius, topLeft: _borderRadius),
color: colors2[400],
),
),
),
Container(
width: _width,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.blue,
),
),
Positioned(
left: 0,
child: Container(
width: _sideWidth,
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(_borderRadius),
color: Colors.white,
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.menu_rounded,
size: 34,
color: Colors.blue,
),
const SizedBox(
width: 10,
),
Text(
'SETTING',
style: TextStyle(color: colors[600], fontSize: 24),
),
],
),
),
),
),
]),
),
);
}
}
Here is the screen shot for this example;
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?
enter image description here
import 'package:flutter/material.dart';
main() => runApp(test());
class test extends StatefulWidget {
#override
_testState createState() => _testState();
}
class _testState extends State<test> {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Card over stack"),
),
body: Stack(
children: <Widget>[
Align(
alignment: Alignment.topCenter,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
color: Colors.lightBlueAccent),
height: 100,
),
),
Positioned(
top: 60,
right: 10,
left: 10,
child: Card(
child: ListTile(
leading: SizedBox(
height: 150.0,
width: 150.0, // fixed width and height
child: Image.asset("assets/images/test.png"))),
),
),
],
),
),
);
}
}
Stack is the rignt choice, check screenshot below:
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,
),
),
],
),
),
);
}
}
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)),
),
),
],
),
),
),
);
}
}
I'm wanted to achieve the following UI in the screenshot and achieved by the below code on two different phones. But the same is not working on many other devices. Is there a way to handle the size of CircularProgressIndicator(currently I'm using Transform.scale() which is not giving me generic result) so that it fits around the sibling container inside the stack?
Edit:
The reason for using CircularProgressIndicator is to show progress.
Widget build(BuildContext context) {
final mediaq = MediaQuery.of(context).size;
return Stack(alignment: Alignment.center, children: [
Transform.scale(
scale: mediaq.width <= 360 ? 2.35 : 2.70,
child: const CircularProgressIndicator(
backgroundColor: Colors.white,
color: Colors.orange,
strokeWidth: .75,
value: 1,
),
),
Container(
decoration: const BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [Colors.red, Colors.orange],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
fixedSize: Size(mediaq.width * .24, mediaq.height * .12),
shape: const CircleBorder(side: BorderSide.none),
),
onPressed: () {},
child: const Text("child")),
),
]);
}
Re wrote your code and here is my output
Transform.scale(
scale: mediaq.width> 375 ? 3.10 : 2.35,
child: const CircularProgressIndicator(
backgroundColor: Colors.white,
color: Colors.white,
strokeWidth: .75,
value: 1,
),
),
Output:
Iphone 12 Pro Max (W:428 , H:926)
Iphone SE (Second Generation) (W:375, H: 667)
Also you can try this package for responsive ui.
You can use flutter_screenutil package to make your UI more responsive, instead of MediaQuery.
I have done your screen using flutter_screenutil package.
Please try this out. I assumed the heights, widths, and radius. You can modify these as per your requirement. I have also attached the UI I got.
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(375, 667),
minTextAdapt: true,
builder: () {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const ButtonTest(),
);
});
}
}
class ButtonTest extends StatefulWidget {
const ButtonTest({Key? key}) : super(key: key);
#override
_ButtonTestState createState() => _ButtonTestState();
}
class _ButtonTestState extends State<ButtonTest> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Container(
height: 94.h, // You can change here
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
),
),
child: Padding(
padding: EdgeInsets.all(
2.0.w, // You can change here
),
child: GestureDetector(
onTap: () {
print("Button Pressed");
},
child: Container(
height: 92.h, // You can change here
width: 92.h, // You can change here
decoration: const BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
],
),
),
child: const Center(
child: Text(
'child',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
)),
),
),
),
),
),
);
}
}
I'd like to draw a circle around a number on top of an image. So the inside of the circle is transparent and the border of the circle is white. Alas, the double CircleAvatar trick to have a CircleAvatar's border doesn't work for transparent background. An example can be found here https://drive.google.com/file/d/1QFIH9ty8cajoLlI9-Vv3q4mOscRLRvAf/view
Stack(
children: <Widget>[
Image.network(
this.widget.rando.etapes[index].couvertureUrl,
width: 90.0,
height: 90.0,
fit:BoxFit.cover),
Container(
width: 90.0,
alignment: Alignment.center,
child: Container(
child:CircleAvatar(
backgroundColor: Colors.transparent,
radius: 30,
child: Text((index+1).toString(),
style:TextStyle(color: Colors.white,
fontSize: 25.0,
fontWeight: FontWeight.w600)),
),
),
)
]
),
You can do it by using 'Container' and decoration parameter instead of 'CircleAvatar'.
Here is a my test code.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Widget _buildBody() {
return Container(
height: 190,
width: 190,
child: Stack(
children: <Widget>[
Image.network(
'https://images.unsplash.com/photo-1441974231531-c6227db76b6e?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1351&q=80',
width: 190.0,
height: 190.0,
fit: BoxFit.cover),
Center(
child: Container(
width: 90.0,
height: 90.0,
decoration: BoxDecoration(
color: Colors.transparent,
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 5.0,
style: BorderStyle.solid,
),
),
child: Center(
child: Text(
'1',
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
fontWeight: FontWeight.w600,
),
),
),
),
),
],
),
);
}
}