Add Badge on a hamburger menu icon in flutter - flutter

Hi Please help I am trying to add a red Badge on a hamburger menu icon in the flutter app like below

You can achieve this with badges plugin here
Add this to your package's pubspec.yaml file under dependencies:
badges: ^2.0.2
then import,
import 'package:badges/badges.dart';
finally add Badge in AppBar,
AppBar(
leading: Badge(
position: BadgePosition.topEnd(top: 10, end: 10),
badgeContent: null,
child: IconButton(
icon: Icon(Icons.menu),
onPressed: () {},
),
),
title: Text('Badge Demo', style: TextStyle(color: Colors.black)),
backgroundColor: Colors.white,
)

Using Stack, similar sample code:
class NotificationIcon extends StatelessWidget {
final bool active;
final double marginTopLeft;
const NotificationIcon({Key key, this.active = true, this.marginTopLeft})
: super(key: key);
#override
Widget build(BuildContext context) {
final color = active ? Colors.white : const Color(0xff40a9ff);
final margin = marginTopLeft ?? 17;
return Container(
width: 24,
height: 24,
child: Stack(
children: [
Center(
child: Icon(
Icons.notifications,
color: color,
),
),
Positioned(
right: margin,
top: margin,
child: Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
shape: BoxShape.circle,
),
child: Center(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color,
),
width: 5,
height: 5,
),
),
),
)
],
),
);
}
}

It can be easily done using the Stack widget. I have given an example of how you can use stack to achieve that. Note that you have to use Scaffold.of(yourContext).openDrawer() to open the attached drawer (as I've done here) since the hamburger icon is manually placed there.
import 'package:flutter/material.dart';
void main() {
runApp(Example());
}
class Example extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: "Example",
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: InkWell(
splashColor: Colors.lightBlue,
onTap: () => Scaffold.of(context).openDrawer(),
child: Center(
child: Container(
margin: EdgeInsets.only(left: 10),
width: 40,
height: 25,
child: Stack(
children: [
Icon(
Icons.menu,
color: Colors.grey[850],
),
Positioned(
left: 25,
top: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: Center(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.red,
),
width: 10,
height: 10,
),
),
),
)
],
),
),
),
),
title: Text("Hello"),
actions: [
],
),
body: Center(child: Text("Welcome")),
),
);
}
}

Widget build(BuildContext context) {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
return Scaffold(
key: _scaffoldKey,
drawer: Drawer(),
appBar: AppBar(
backgroundColor: Colors.red,
title: Text(
"Some Text",
style: TextStyle(color: Colors.white),
),
leading: InkWell(
splashColor: Colors.lightBlue,
onTap: () {
_scaffoldKey.currentState.openDrawer();
},
child: Center(
child: Container(
margin: EdgeInsets.only(left: 10),
width: 40,
height: 25,
child: Stack(
children: [
Icon(
Icons.menu,
color: Colors.white,
),
Positioned(
left: 25,
top: 0,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
child: Center(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.red,
),
width: 10,
height: 10,
),
),
),
)
],
),
),
),
),
),
body: SafeArea(
child: Container(
),
),
);
}
Please use this. And if you want to show the number as well, you can use Badge too.

Related

Widget getting pushed behind Status Bar in Custom App Bar

I'm currently trying to make my appBar appear like the picture below but seem to be running into one particular issue every time I try doing so.
I have given the appBar a height of 100 and my idea was to distribute the height in a 40 60 ratio between the two Containers(amber and red). Things look fine when there's only the amber Container but as soon as I try adding the red Container, the amber Container somehow gets pushed up behind the status bar and I have no idea what is causing this.
This is till the point things look great with the amber Container
This is when the above anomaly occurs
This is my code. (the part commented out is the design for the Red Container)
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
HomeScreenState createState() => HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {
bool _toggleDropDown = false;
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
backgroundColor: Colors.green,
titleSpacing: 0,
title: Column(
children: [
Container( //Amber Container
width: double.infinity,
height: 40,
color: Colors.amber,
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 5),
height: 15,
width: double.infinity,
// color: Colors.red,
child: const Text(
'Delivering To',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
Container(
height: 25,
width: double.infinity,
padding: const EdgeInsets.only(left: 5),
// color: Colors.blue,
child: Row(
children: [
const Text(
'Current Location',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold),
),
const SizedBox(width: 20),
Container(
height: double.infinity,
width: 20,
// color: Colors.yellow,
child: InkWell(
onTap: () {
setState(() {
_toggleDropDown = !_toggleDropDown;
});
},
child: Icon(
!_toggleDropDown
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: Colors.red,
),
))
],
),
),
],
),
),
// Container( //Red Container
// height: 60,
// width: double.infinity,
// color: Colors.red,
// padding: EdgeInsets.only(top: 8),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// InkWell(
// onTap: () {},
// child: Icon(
// Icons.search,
// size: 25,
// )),
// Row(
// children: [
// InkWell(
// onTap: () {},
// child: const Icon(
// Icons.shopping_cart_outlined,
// color: Colors.white,
// size: 25,
// ),
// ),
// InkWell(
// onTap: () {},
// child: const Icon(
// Icons.notifications_none_outlined,
// color: Colors.white,
// size: 25,
// ),
// )
// ],
// )
// ],
// ),
// )
],
)),
),
);
}
}
FYI : I have also tried wrapping the Scaffold with SafeArea and the output that produces looks like this:
The issue is here AppBar is not getting height:100. While using PreferredSize you can just use Column or just using toolbarHeight: 100 on AppBar.
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
backgroundColor: Colors.green,
titleSpacing: 0,
toolbarHeight: 100, //<this
Or just do
return Scaffold(
appBar: AppBar(
elevation: 0,
toolbarHeight: 100, //<this
The trick lies in wrapping your Scaffold() with a SafeArea() widget.
Scaffold represents the whole screen of a device, each and every pixel of your screen.
SafeArea takes into account notches, status bars, bottom navigation bars and bottom navigation buttons.
Here's a quick how-to:
class _MyScreenState extends State<DonationDetails> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(), //your ui components goes here
));
}
}
UPDATE TO YOUR USE CASE
import 'package:flutter/material.dart';
class HomeScreenTest extends StatefulWidget {
HomeScreenTestState createState() => HomeScreenTestState();
}
class HomeScreenTestState extends State<HomeScreenTest> {
bool _toggleDropDown = false;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
automaticallyImplyLeading: false,
leading: null,
backgroundColor: Colors.green,
titleSpacing: 0,
title: Container(
width: double.infinity,
height: 40,
color: Colors.amber,
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 5),
height: 15,
width: double.infinity,
// color: Colors.red,
child: const Text(
'Delivering To',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
Container(
height: 25,
width: double.infinity,
padding: const EdgeInsets.only(left: 5),
// color: Colors.blue,
child: Row(
children: [
const Text(
'Current Location',
style: TextStyle(
color: Colors.grey, fontWeight: FontWeight.bold),
),
const SizedBox(width: 20),
Container(
height: double.infinity,
width: 20,
// color: Colors.yellow,
child: InkWell(
onTap: () {
setState(() {
_toggleDropDown = !_toggleDropDown;
});
},
child: Icon(
!_toggleDropDown
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: Colors.red,
),
))
],
),
),
],
),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(80),
child: Container(
//Red Container
height: 60,
width: double.infinity,
color: Colors.red,
padding: EdgeInsets.only(top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.shopping_cart_outlined,
color: Colors.white,
size: 25,
),
),
Row(
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.shopping_cart_outlined,
color: Colors.white,
size: 25,
),
),
IconButton(
onPressed: () {},
icon: Icon(
Icons.notifications_none_outlined,
color: Colors.white,
size: 25,
),
),
],
)
],
),
),
),
),
),
);
}
}
You can use bottom in 'AppBar'.
Move the red Container to bottom with PreferredSize widget as parent. like this.
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(100),
child: AppBar(
elevation: 0,
// backgroundColor: Theme.of(context).scaffoldBackgroundColor,
backgroundColor: Colors.green,
titleSpacing: 0,
title: Container(
//Amber Container
width: double.infinity,
height: 40,
color: Colors.amber,
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 5),
height: 15,
width: double.infinity,
// color: Colors.red,
child: const Text(
'Delivering To',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
Container(
height: 25,
width: double.infinity,
padding: const EdgeInsets.only(left: 5),
// color: Colors.blue,
child: Row(
children: [
const Text(
'Current Location',
style: TextStyle(
color: Colors.grey, fontWeight: FontWeight.bold),
),
const SizedBox(width: 20),
Container(
height: double.infinity,
width: 20,
// color: Colors.yellow,
child: InkWell(
onTap: () {
setState(() {
_toggleDropDown = !_toggleDropDown;
});
},
child: Icon(
!_toggleDropDown
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: Colors.red,
),
))
],
),
),
],
),
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(80),
child: Container(
//Red Container
height: 60,
width: double.infinity,
color: Colors.red,
padding: EdgeInsets.only(top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
InkWell(
onTap: () {},
child: Icon(
Icons.search,
size: 25,
)),
Row(
children: [
InkWell(
onTap: () {},
child: const Icon(
Icons.shopping_cart_outlined,
color: Colors.white,
size: 25,
),
),
InkWell(
onTap: () {},
child: const Icon(
Icons.notifications_none_outlined,
color: Colors.white,
size: 25,
),
)
],
)
],
),
),
),
),
),
);

GridView.count: ListTiles are not disappearing above my List

I'm using the GridView.count widget which works alright. But when I'm scrolling down you can see the tiles going behind my other stuff above my GridView part. You can see it through the little Spaces. I want them to disappear when they go above their starting point.
Also please give me any advice on other parts of my code (3 weeks into Flutter).
enter image description here
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(backgroundColor: Colors.blueGrey[700],
appBar: AppBar(
backgroundColor: Colors.green[200],
foregroundColor: Colors.black,
centerTitle: true,
title: const Text("Stromberg Soundboard"),
),
body: ListView(
children: [
Container(
margin: EdgeInsets.all(3),
height: 250,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: const DecorationImage(
image: AssetImage('assets/bernd.jpeg'), fit: BoxFit.cover),
),
),
const SeasonsAndJokes(),
],
),
),
);
}
}
#override
Widget build(BuildContext context) {
return Column(
children: [
Container(
height: 30,
width: double.infinity,
margin: const EdgeInsets.only(left: 5, right: 5, bottom: 5),
color: Colors.green[100],
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
padding: const EdgeInsets.all(0),
alignment: Alignment.topLeft,
iconSize: 32,
disabledColor: Colors.white,
onPressed: lastSeason,
icon: const Icon(Icons.arrow_left_sharp),
),
Text(
seasonsText[indexische],
style: const TextStyle(fontWeight: FontWeight.bold),
textScaleFactor: 1.3,
),
IconButton(
padding: const EdgeInsets.all(0),
alignment: Alignment.topRight,
iconSize: 32,
onPressed: nextSeason,
icon: const Icon(Icons.arrow_right_sharp),
)
],
),
),
SizedBox(
height: 380,
child: GridView.count(
padding: const EdgeInsets.only(right: 5, left: 5),
crossAxisSpacing: 5,
mainAxisSpacing: 5,
crossAxisCount: 2,
childAspectRatio: 3,
children: [
for (int i = 0; i < titelSeasonOne.length; i++)
ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: const BorderSide(color: Colors.white38),
),
trailing: const Icon(
Icons.volume_up_sharp,
color: Colors.blueGrey,
),
tileColor: Colors.green[200],
textColor: Colors.black87,
title: Text(
titelSeasonOne[i],
textScaleFactor: 1,
),
onTap: () {
final player = AudioCache();
player.play(audioSeasonOne[i]);
},
),
],
),
)
],
);
}
}

How can I design chip with outside an image in flutter?

How can I design like this in flutter?
The above image u can use as star.
I have tried like the following but it's not correct,
new Container(
child:
ButtonTheme (
buttonColor: buttonColor: Colors.teal,
child: Stack(
children: [
RaisedButton (
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(
color: Colors.transparent,
),
),
child: Text(
'123',
style: TextStyle(
color: Colors.white,
fontSize: 22.0,
fontFamily: 'MuseoSans',
),
),
onPressed: () {
//click actions
},
),
Positioned( // will be positioned in the top right of the container
top: 0,
left: 0,
child: new Image.asset('images/ic_star.png'),
)
]
)
),
)
Try this
Container(
child: ButtonTheme(
buttonColor: Colors.teal,
child: Stack(children: [
Container(
height: 40.0,
child: Padding(
padding: const EdgeInsets.only(left: 25.0),
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(
color: Colors.transparent,
),
),
child: Text(
'123',
style: TextStyle(
color: Colors.white,
fontSize: 22.0,
fontFamily: 'MuseoSans',
),
),
onPressed: () {
//click actions
},
),
),
),
Positioned(
// will be positioned in the top right of the container
top: 0,
left: 0,
child: new Image.asset(
'images/ic_star.png',
width: 50.0,
height: 50.0,
),
)
])),
)
It will look something like this -
Use 'Stack' widget
Here is pseudo code
It very bad code but simple example
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: 90,
height: 23,
child: Stack(
children: [
Align(
alignment: Alignment.centerRight,
child: Container(
decoration: BoxDecoration(
color: Colors.teal,
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: Text(
' 123123',
style: TextStyle(fontSize: 20, color: Colors.white),
),
),
),
Image.network('https://i.stack.imgur.com/SpWmJ.png', height: 23),
],
),
),
);
}
}
You have to change some size (like wrap content)

Flutter - Align widget all the way to the end of a card view. (View image included)

how can I get the flat button to fill the area under the divider all the way to the end of the card, it appears to not be able to go any further down.
See the white space under the FlatButton? I want it to look like the FlatButton is the end.
Doesn't have to be a flat button, any widget with onTap/press/(or a something hack-ish with gesture detector) listener would be fine.
Dart code is ->
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 16),
child: Text(_label, style: TextStyle(fontSize: 24, color: Color.fromARGB(190, 0, 0, 0), fontWeight: FontWeight.bold)),
),
Divider(color: Colors.black26, height: 2,),
Padding(
padding: const EdgeInsets.all(24.0),
child: Text(_information, style: TextStyle(fontSize: 20, color: Colors.black87)),
),
Divider(color: Colors.black26, height: 2,),
SizedBox(width: double.infinity, child: FlatButton(onPressed: () => _onTap(), color: Color.fromARGB(50, 100, 100, 100), child: Text('Done', style: TextStyle()), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5))))
],
),
),
),
);
}
Please see the code below, I'm using InkWell & Container :
import 'package:flutter/material.dart';
final Color darkBlue = const Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
//theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
String _label = "";
String _information = "";
return Padding(
padding: const EdgeInsets.all(4.0),
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))),
child: Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 16),
child: Text(_label,
style: TextStyle(
fontSize: 24,
color: Color.fromARGB(190, 0, 0, 0),
fontWeight: FontWeight.bold)),
),
Divider(
color: Colors.black26,
height: 2,
),
Padding(
padding: const EdgeInsets.all(24.0),
child: Text(_information,
style: TextStyle(fontSize: 20, color: Colors.black87)),
),
Divider(
color: Colors.black26,
height: 2,
),
Spacer(),
InkWell(
onTap: () {}, //_onTap(),
child: Container(
width: double.infinity,
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: const Color.fromARGB(50, 100, 100, 100)),
child: const Center(child: Text('Done', style: TextStyle())),
),
)
],
),
),
),
);
}
}
I solved my code like this, setting a height factor it did what i wanted automatically.
SizedBox(width: double.infinity, height: 60, child:
FlatButton(onPressed: () => _onTap(), color: Colors.transparent, child:
Text('Done', style: TextStyle()), shape: RoundedRectangleBorder(borderRadius:
BorderRadius.only(bottomLeft: Radius.circular(15), bottomRight: Radius.circular(15)))))
Only downside is that you have to specify a height rather than letting the widget adjust that based on content. Although there is probably a workaround for that.

Custom Button in Flutter

What I am trying to achieve is below:
Should I be using Row with Icon and Text?
Here is my code and its output
RaisedButton(
elevation: 10,
onPressed: () {},
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 55,
color: Colors.deepPurple,
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Text(
'Settings',
style: TextStyle(
fontSize: 25,
),
),
],
),
),
);
OUTPUT:
Any help would be appreciated.
Here you go
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(), //.copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
get borderRadius => BorderRadius.circular(8.0);
#override
Widget build(BuildContext context) {
return Center(
child: Material(
elevation: 10,
borderRadius: borderRadius,
child: InkWell(
onTap: () {},
child: Container(
padding: EdgeInsets.all(0.0),
height: 60.0,//MediaQuery.of(context).size.width * .08,
width: 220.0,//MediaQuery.of(context).size.width * .3,
decoration: BoxDecoration(
borderRadius: borderRadius,
),
child: Row(
children: <Widget>[
LayoutBuilder(builder: (context, constraints) {
print(constraints);
return Container(
height: constraints.maxHeight,
width: constraints.maxHeight,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: borderRadius,
),
child: Icon(
Icons.settings,
color: Colors.white,
),
);
}),
Expanded(
child: Text(
'Settings',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
),
),
),
],
),
),
),
),
);
}
}
John Joe's answer is correct. Here is another solution that does the same with plain Container widget. I am posting it here just in case someone interested.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: Colors.white),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: MyWidget(),
),
],
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
height: 48.0,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 2.0),
blurRadius: 8.0,
spreadRadius: 2.0)
]),
child: Stack(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 48.0,
height: 48.0,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
),
child: Align(
alignment: Alignment.center,
child: Icon(Icons.settings))),
Expanded(
child: Center(
child: Text("Hellow world",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: Colors.black)),
)),
],
),
SizedBox.expand(
child: Material(
type: MaterialType.transparency,
child: InkWell(onTap: () {}),
),
),
],
),
),
);
}
}
See the live demo here.
You can use Column and Row.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Column(
children: <Widget>[
_firstWidget(),
SizedBox(height: 15),
_secondWidget(),
],
)),
);
}
Widget _firstWidget() {
return InkWell(
onTap: () {},
child: Card(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
height: 55,
width: 30,
decoration: myBoxDecoration(),
child: Icon(
Icons.settings,
color: Colors.white,
),
)),
Expanded(
flex: 3,
child: Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Programs & Services',
style: TextStyle(
fontSize: 25,
),
))),
],
),
));
}
Widget _secondWidget() {
return InkWell(
onTap: () {},
child: Card(
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
elevation: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: 1,
child: Container(
decoration: myBoxDecoration(),
height: 55,
width: 30,
child: Icon(
Icons.settings,
color: Colors.white,
),
)),
Expanded(
flex: 3,
child: Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Settings',
style: TextStyle(
fontSize: 25,
),
))),
],
),
));
}
BoxDecoration myBoxDecoration() {
return BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.all(
Radius.circular(5.0) // <--- border radius here
),
);
}
Output
Darish's answer seems to me the best, since the splash is displayed on top of everything and makes a very good visual effect.
Even so, since the answer is from so long ago, I wanted to put here the updated code to NullSafety and also correct some bugs and remove unnecessary things.
For the rest it is perfect.
Here my code:
class MyWidget extends StatelessWidget {
const MyWidget({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8.0),
boxShadow: const [
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 2.0),
blurRadius: 8.0,
spreadRadius: 2.0,
)
],
),
child: SizedBox(
height: 48,
child: Stack(
children: [
Row(
children: <Widget>[
Container(
width: 48.0,
height: 48.0,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(8),
),
child: const Center(
child: Icon(Icons.settings, color: Colors.white),
),
),
const Expanded(
child: Center(
child: Text("Hellow world"),
),
),
],
),
Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () {},
borderRadius: BorderRadius.circular(8.0),
),
),
],
),
),
);
}
}