How to create button using stack widgets and curved desgin with out background images.
Asked
Active
Viewed 47 times
2 Answers
1
hope it helps :)
import 'package:flutter/material.dart';
void main() {
runApp(
const MaterialApp(
home: MyApp(),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
width: 200,
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: const DecorationImage(
image: AssetImage(
'assets/images/button_background.png',
),
fit: BoxFit.cover,
),
),
child: RawMaterialButton(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
splashColor: Colors.green,
onPressed: () {
print('Hello World');
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.centerLeft,
child: const Text('Login', style: TextStyle(color: Colors.white)),
),
),
),
),
);
}
}

Kherel
- 14,882
- 5
- 50
- 80
1
I would suggest using background images because it's simpler, but if you really insist on not using them, here is an example of how to do it without background image:
class Sample extends StatelessWidget {
const Sample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(20)),
child: Container(
height: 60,
width: 250,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.green, Colors.yellow],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
child: RawMaterialButton(
onPressed: () {},
splashColor: Colors.green,
child: Stack(
children: [
Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 20),
child: const Text(
'Login',
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
Positioned(
right: 5,
top: -80,
height: 100,
width: 100,
child: Container(
decoration: const ShapeDecoration(
color: Colors.green,
shape: CircleBorder(),
),
),
),
Positioned(
right: -40,
top: -65,
height: 100,
width: 100,
child: Container(
decoration: ShapeDecoration(
color: Colors.brown.withOpacity(.9),
shape: const CircleBorder(),
),
),
),
],
),
),
),
),
),
);
}
}
P.S. feel free to adjust the color
s and height/width
values to your needs.

Ante Bule
- 1,834
- 1
- 2
- 8
-
background image easy to use but i learned new widget so only im asked Thank you so much bro – Mathan Tr Apr 24 '23 at 09:48