Column(
children: [
Padding(
padding: const EdgeInsets.only(
left: 15, bottom: 8, top: 1),
child: Row(
//crossAxisAlignment: CrossAxisAlignment.start,
//mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// ITEM NAME
Padding(
padding: const EdgeInsets.only(
left: 10, top: 10),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'${restaurantItems[i].name}',
style: TextStyle(
fontSize: 17,
color: kTextColor,
fontWeight: FontWeight.w700),
),
SizedBox(
width: width / 2,
),
// 'ADD' BUTTON CONTAINER
Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(8),
color: Colors.black87,
),
child: Padding(
padding: const EdgeInsets.only(
left: 9,
top: 3,
right: 5,
bottom: 3),
child: InkWell(
splashColor: Colors.white,
onTap: () {
// print(restaurantItems[i].name);
cart.addItem(
restaurantItems[i].id,
restaurantItems[i].name,
restaurantItems[i].price,
restaurant,
);
},
child: Row(
children: [
Text(
'ADD',
style: TextStyle(
color: Colors.white,
),
),
Icon(
Icons.add,
color: Colors.white,
size: 17,
),
],
),
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 10, top: 10, bottom: 11),
child: Text(
'₹${restaurantItems[i].price}',
style: TextStyle(
fontSize: 15,
color: kTextColor,
fontWeight: FontWeight.w500),
),
),
// Padding(
// padding: const EdgeInsets.only(
// left: 17, top: 17),
// child: InkWell(
// onTap: () {
// // Add to Cart
// },
// child: Row(
// children: [
// Padding(
// padding:
// const EdgeInsets.only(left: 15),
// child: Text(
// '${restaurantItems[i].quantity} Left',
// style: TextStyle(
// color: kTextLightColor,
// fontSize: 13,
// fontWeight: FontWeight.w700),
// ),
// )
// ],
// ),
// ),
// )
],
),
],
),
),
],
),
How can I fill the space between 'ITEM NAME' and 'ADD CONTAINER'? I have tried spacer(), but it doesn't work. Also, I have seen Expanded() widget but since I am new to flutter, I can't seem to get a hang of it. I have also added the Column widget, because of which the Spacer() widget is not working I guess.
Any help would be appreciated, thanks.
Use SizedBox widget between 'ITEM NAME' and 'ADD CONTAINER'. for example:
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.only(left: 10, top: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'test',
style: TextStyle(
fontSize: 17,
color: Colors.black,
fontWeight: FontWeight.w700),
),
// Spacer()
SizedBox(width: width/2,)
// 'ADD' BUTTON CONTAINER
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.black87,
),
child: Padding(
padding:
const EdgeInsets.only(left: 9, top: 3, right: 5, bottom: 3),
child: InkWell(
splashColor: Colors.white,
onTap: () {
// print(restaurantItems[i].name);
// cart.addItem(
// restaurantItems[i].id,
// restaurantItems[i].name,
// restaurantItems[i].price,
// restaurant,
// );
},
child: Row(
children: [
Text(
'ADD',
style: TextStyle(
color: Colors.white,
),
),
Icon(
Icons.add,
color: Colors.white,
size: 17,
),
],
),
),
),
),
],
),
),));
}
For providing space between widgets you can use SizedBox(width:10)
Use Spacer() to fill the space if you don't want to define size of width
Wrap your Column with ConstrainedBox and set the constraints value to BoxConstraints.expand(). The idea:
body: ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [const Text('ITEM NAME='), ElevatedButton(onPressed: () {}, child: const Text('ADD'))])
]))
Try this:
Text(
'${restaurantItems[i].name}',
style: TextStyle(
fontSize: 17,
color: kTextColor,
fontWeight: FontWeight.w700,
),
),
Spacer(flex: 1),
// 'ADD' BUTTON CONTAINER
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.black87,
),
child: Padding(
padding: const EdgeInsets.only(
left: 9,
top: 3,
right: 5,
bottom: 3,
),
child: InkWell(
splashColor: Colors.white,
onTap: () {
// print(restaurantItems[i].name);
cart.addItem(
restaurantItems[i].id,
restaurantItems[i].name,
restaurantItems[i].price,
restaurant,
);
},
child: Row(
children: [
Text(
'ADD',
style: TextStyle(
color: Colors.white,
),
),
Icon(
Icons.add,
color: Colors.white,
size: 17,
), // Icon
], // <Widget>[]
), // Row
), // InkWell
), // Padding
), // Container
Spacer(flex: 4),
Related
I use the component as in the description, I can’t figure out how to remove the answer (child component) in the component itself, or at least how to check if it exists, then show it, if not, then don’t show it.
https://gist.github.com/lomanu4/3abba49f6fbcecbde4c07df82c3ce11c
class _ComentCardState extends State<ComentCard> {
bool childcomment = false;
#override
Widget build(BuildContext context) {
return Column(children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: CommentTreeWidget<Comment, Comment?>(
Comment(
avatar: 'null',
userName: widget.snap['name'],
content: '${widget.snap['text']} '),
[
Comment(avatar: 'null', userName: 'null', content: 'null'),
],
treeThemeData: childcomment
? TreeThemeData(lineColor: Colors.green[500]!, lineWidth: 3)
: TreeThemeData(lineColor: Colors.green[500]!, lineWidth: 3),
avatarRoot: (context, data) => PreferredSize(
preferredSize: const Size.fromRadius(18),
child: Row(
children: [
CircleAvatar(
radius: 18,
backgroundColor: Colors.grey,
backgroundImage:
NetworkImage(widget.snap['profilePic'].toString()),
),
],
),
),
avatarChild: (context, data) => const PreferredSize(
preferredSize: Size.fromRadius(12),
child: CircleAvatar(
radius: 12,
backgroundColor: Colors.grey,
backgroundImage: AssetImage('lib/assets/homescreen.png'),
),
),
contentChild: (context, data) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(12)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'dangngocduc',
style: Theme.of(context).textTheme.caption?.copyWith(
fontWeight: FontWeight.w600, color: Colors.black),
),
const SizedBox(
height: 4,
),
Text(
'${data!.content}',
style: Theme.of(context).textTheme.caption?.copyWith(
fontWeight: FontWeight.w300, color: Colors.black),
),
],
),
),
DefaultTextStyle(
style: Theme.of(context).textTheme.caption!.copyWith(
color: Colors.grey[700], fontWeight: FontWeight.bold),
child: Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
children: const [
SizedBox(
width: 8,
),
Text('Reply'),
],
),
),
)
],
);
},
contentRoot: (context, data) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(12)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.snap['name'],
style: Theme.of(context).textTheme.caption!.copyWith(
fontWeight: FontWeight.w600, color: Colors.black),
),
const SizedBox(
height: 4,
),
Text(
'${data.content}',
style: Theme.of(context).textTheme.caption!.copyWith(
fontWeight: FontWeight.w300, color: Colors.black),
),
const SizedBox(
height: 4,
),
],
),
),
DefaultTextStyle(
style: Theme.of(context).textTheme.caption!.copyWith(
color: Colors.grey[700], fontWeight: FontWeight.bold),
child: Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
children: [
SizedBox(
width: 8,
),
Text('Like'),
SizedBox(
width: 24,
),
Expanded(child: Text('Reply')),
Container(
padding: const EdgeInsets.all(8),
child: const Icon(
Icons.favorite_border,
size: 16,
),
)
],
),
),
),
],
);
},
),
),
]);
}
So I'm trying to create an expandable card. But the problem is, I don't even know how to start with the design.
So I'm trying to achieve this output
And this is my current progress
I tried putting two containers in a column, but it just doesn't look right.
Can someone please help me out. I need to achieve the top part of the card.
This is the code for my current progress
Widget buildTabCards() {
return Container(
padding: EdgeInsets.only(
top: 10.0,
left: 10,
right: 10,
),
child: Column(children: [
Card(
elevation: 5.0,
color: Colors.white,
child: Padding(
padding: EdgeInsets.only(
top: 7,
bottom: 10,
),
child: Column(
children: <Widget>[
buildCardDateandTime(),
buildCardAvatar(),
],
),
),
),
Widget buildCardDateandTime() {
return Container(
child: Row(
children: [
Padding(
padding: EdgeInsets.only(
left: 15,
right: 5,
top: 2,
),
child: Icon(
MdiIcons.clockOutline,
size: 22,
color: AppColors.blue,
),
),
Text(
"12 June, 2021, 8:00 AM",
style: TextStyle(
fontFamily: "Poppins",
color: Colors.black87,
letterSpacing: 0.3,
fontSize: 20,
fontWeight: FontWeight.w400,
),
),
SizedBox(width: 5),
Padding(padding: EdgeInsets.only(left: 50)),
IconButton(
icon: Icon(
MdiIcons.fromString('dots-vertical'),
size: 30,
color: AppColors.blue,
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
);
}
Widget buildCardAvatar() {
return Padding(
padding: EdgeInsets.only(
left: 25,
top: 5,
bottom: 10,
),
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Container(
padding: EdgeInsets.all(15.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(200),
),
color: Colors.red,
),
child: Text(
"JS",
style: TextStyle(
fontSize: 18.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 5.0,
),
Padding(padding: EdgeInsets.only(left: 10)),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"John Renzo",
style: TextStyle(
fontSize: 20.0,
color: Colors.black54,
fontWeight: FontWeight.w500,
),
),
Text(
"Sangalang",
style: TextStyle(
fontSize: 20.0,
color: Colors.black54,
fontWeight: FontWeight.w500,
),
)
]))
]));
}
First declare a variable
bool extended = false;
then
Padding(
padding: const EdgeInsets.only(left: 12.0, right: 12.0, top: 9.0, bottom: 9.0),
child: Container(
width: MediaQuery.of(context).size.width,
child: InkWell(
onTap: () {
setState(() {
if (extended == null || !extended)
extended = true;
else
extended = false;
});
},
enableFeedback: false,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
child: Center(
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10.0,
),
Row(
children: <Widget>[
Expanded(
child: Text(
'Text',
style: TextStyle(fontSize: 16.0),
),
),
Icon(
extended ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right,
size: 26,
color: Colors.grey,
)
],
),
SizedBox(
height: 10.0,
),
extended
? Container(
height: 100,
)
: Container()
],
),
),
),
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(7.0),
),
boxShadow: <BoxShadow>[
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.09),
offset: Offset(0.0, -2.0),
blurRadius: 12.0,
),
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.09),
offset: Offset(0.0, 6.0),
blurRadius: 12.0,
),
],
),
),
);
You can use ExpansionPanel to achieve your results
List<bool> isExpanded = []; //the size/length should be equal to the size of your data list
ExpansionPanelList(children: [
//generate the panels from your data list
ExpansionPanel(
headerBuilder: (context, isExpanded) {
return _headerHere();
},
body: _bodyHere(),
isExpanded: isExpanded[0], //index of your card
canTapOnHeader: true,// to make the complete header clickable
)
],
expansionCallback: (panelIndex, expanded) {
setState(() {
isExpanded[panelIndex] = !expanded;
});
},
),
So I'm new to flutter, and I'm trying to make a card. But I can't seem to get my desired output.
I tried to separate the different widgets, by using rows and columns, but I kept messing it up.
This is my target output
Target output
This is my current progressCurrent progress
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildhomePageAppBar(),
body: buildExhibitorBody(),
);
}
Widget buildExhibitorBody() {
return Container(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
buildExhibitorText(),
SizedBox(
height: 10,
),
buildExhibitorCards(),
SizedBox(height: 10),
],
),
),
);
}
Widget buildhomePageAppBar() {
double profileDimension = 35;
return AppBar(
backgroundColor: Colors.white,
titleSpacing: 0,
title: Padding(
padding: EdgeInsets.only(
left: 20,
),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(
top: 5,
bottom: 5,
),
child: Image(
image: AssetImage('assets/images/plain_logo.png'),
height: 30,
),
),
SizedBox(width: 5),
Text(
'Virtex',
style: TextStyle(
color: Colors.black87,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
)
],
),
),
actions: [
Padding(
padding: EdgeInsets.only(
top: 10,
bottom: 10,
),
child: Container(
height: profileDimension,
width: profileDimension,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.black54,
width: 2,
),
borderRadius: BorderRadius.circular(50),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image(
width: profileDimension,
height: profileDimension,
image: AssetImage(
'assets/images/profile-image.jpeg',
),
fit: BoxFit.cover,
),
),
),
),
SizedBox(width: 20),
],
);
}
Widget buildExhibitorText() {
return Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 20,
bottom: 10,
),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Text(
"Exhibitors",
textAlign: TextAlign.justify,
style: TextStyle(
fontFamily: "DMSans",
letterSpacing: -0.2,
fontSize: 20.0,
color: Colors.black,
fontWeight: FontWeight.w400,
),
),
),
],
),
),
);
}
Widget buildExhibitorCards() { // I think my problem is I don't know how to do the layout here
return Container(
width: 400,
height: 150,
child: Column(children: <Widget>[
Card(
elevation: 1,
child: Padding(
padding: const EdgeInsets.only(),
child: Row(children: [
buildCardImage(),
buildCardExhibitor(),
buildCardIndustry(),
buildCardGo(),
])),
),
]),
);
}
Widget buildCardExhibitor() {
return Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Container(
padding: EdgeInsets.all(10),
width: 40,
height: 40,
child: Center(
child: Row(
children: <Widget>[
Text(
"EN",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
Text('Exhibitor Name')
],
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(200),
),
color: Colors.red,
),
),
]);
}
Widget buildCardImage() {
return Container(
height: 100,
width: 100,
child: Image(
image: AssetImage('assets/images/onboarding-2.jpg'),
height: 100,
),
);
}
Widget buildCardIndustry() {
return Padding(
padding: EdgeInsets.only(
left: 40,
right: 40,
),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
"Industry 1",
style: TextStyle(
fontFamily: "DMSans",
color: Colors.grey,
letterSpacing: 0.3,
fontSize: 12,
),
),
Text(
"Industry 2",
style: TextStyle(
fontFamily: "DMSans",
letterSpacing: -0.3,
fontSize: 12,
color: Colors.grey,
fontWeight: FontWeight.w500,
),
),
],
),
),
);
}
Widget buildCardGo() {
return Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Text(
'Go to Booth',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(width: 5),
IconButton(
icon: Icon(
MdiIcons.fromString('arrow-right'),
size: 30,
color: Colors.black,
),
onPressed: () {
Navigator.of(context).pop();
},
),
]);
}
}
I would greatly appreciate any kind of help.
Look:
My own Code
import 'package:flutter/material.dart';
class CardLayout extends StatelessWidget {
Widget buildCardImage = Container(
margin: EdgeInsets.only(right: 10.0),
width: 150,
height: 150,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage("https://picsum.photos/250?image=9"),
),
),
);
Widget buildCardExhibitor =
Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Container(
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(200),
),
color: Colors.red,
),
child: Text(
"EN",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 10.0,
),
Text(
'Exhibitor Name',
style: TextStyle(
fontSize: 15.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
]);
Widget buildCardIndustry = Padding(
padding: EdgeInsets.all(8.0),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding:
EdgeInsets.only(left: 10.0, right: 10.0, top: 5, bottom: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(100),
),
color: Colors.blueGrey.shade400,
),
child: Text(
'Industry 1',
style: TextStyle(
fontFamily: "DMSans",
color: Colors.white,
letterSpacing: 0.3,
fontSize: 12,
),
),
),
SizedBox(
width: 10.0,
),
Container(
padding:
EdgeInsets.only(left: 10.0, right: 10.0, top: 5, bottom: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(100),
),
color: Colors.blueGrey.shade400,
),
child: Text(
'Industry 2',
style: TextStyle(
fontFamily: "DMSans",
color: Colors.white,
letterSpacing: 0.3,
fontSize: 12,
),
),
),
],
),
),
);
Widget buildCardGo = Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Text(
'Go to Booth',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(width: 3),
IconButton(
icon: Icon(
Icons.arrow_forward_rounded,
size: 30,
color: Colors.blue,
),
onPressed: () {
//Navigator.pop(context);
},
),
]);
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text('Exhibitor'),
actions: [
IconButton(
icon: Icon(Icons.filter_list_rounded),
onPressed: () {
Navigator.pop(context);
})
],
),
body: Container(
margin: EdgeInsets.only(top: 10.0),
width: MediaQuery.of(context).size.width,
//height: 150.0, // remove this line -------------- (1) [EDIT]
child: Column(
// wrap card with column and add listtile as children -------------- (2) [EDIT]
children: [
ListTile(
leading: Text('Exhibitor'),
trailing: IconButton(
icon: Icon(Icons.filter_list_rounded),
onPressed: () {
Navigator.pop(context);
}),
),
Card(
elevation: 5.0,
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(5.0),
child: Row(
children: <Widget>[
buildCardImage,
Expanded(
child: Column(
children: <Widget>[
buildCardExhibitor,
buildCardIndustry,
buildCardGo
],
))
],
),
),
),
],
),
),
));
}
}
I am trying to improve the UI of my Xylophone app. So at first, all the buttons were expanded vertically and stretched horizontally. But now I want to have different sizes of buttons and their sizes must change in a decreasing order. This is what it looks like:
But I feel like I am not doing it right! Is this considered hard coding?
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: FlatButton(
child: Text(
'A',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
color: Colors.red,
onPressed: () {
playSound(1);
},
),
),
SizedBox(
height: 5,
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 8.0,
),
child: FlatButton(
child: Text(
'B',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
color: Colors.orange,
onPressed: () {
playSound(2);
},
),
),
),
SizedBox(height: 5.0,),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 16.0,
right: 16.0,
),
child: FlatButton(
child: Text(
'C',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
color: Colors.yellow,
onPressed: () {
playSound(3);
},
),
),
),
SizedBox(height: 5.0,),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 24.0,
right: 24.0,
),
child: FlatButton(
child: Text(
'D',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
color: Colors.green,
onPressed: () {
playSound(4);
},
),
),
),
SizedBox(
height: 10,
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 32,
right: 32,
),
child: FlatButton(
child: Text(
'E',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
color: Colors.teal,
onPressed: () {
playSound(5);
},
),
),
),
SizedBox(
height: 7.0,
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 40.0,
right: 40.0,
),
child: FlatButton(
child: Text(
'F',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
color: Colors.blue,
onPressed: () {
playSound(6);
},
),
),
),
SizedBox(
height: 10,
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 48.0,
right: 48.0,
),
child: FlatButton(
child: Text(
'G',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
color: Colors.purple,
onPressed: () {
playSound(7);
},
),
),
),
],
),
),
),
);
}
You can use the flutter_screenutil package or set measurements as a percentage of the device's screen size width/height like so:
#override
Widget build(BuildContext context) {
final height = MediaQuery.of(context).size.height;
final width = MediaQuery.of(context).size.width;
return Column(children:[
SizedBox(height: 0.05*height,),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 0.1*width,
right: 0.1*width,
),]
);
}
I'd suggest that you store the properties in a list, then iterate over this list to create the children dynamically.
This will also allow you to set the size based on the current index (which is also the id of the sound you want to play).
This will separate your data from the code that creates the children, and should make it easy to change.
Is there a way to programmatically trigger the IconButton ripple animation? The following is some code:
#override
Widget build(BuildContext context) {
return Material(
child: Container(
margin: EdgeInsets.only(top: 12, left: 18, right: 18),
padding: EdgeInsets.only(top: 8, bottom: 8),
decoration: BoxDecoration(
color: _bgColor,
border: new Border.all(color: _bgColor),
borderRadius: BorderRadius.all(Radius.circular(
10.0) // <--- border radius here
),
),
child: Row(children: [
IconButton(
padding: EdgeInsets.only(right: 16),
icon: Icon(Icons.play_arrow, color: Colors.white, size: 48),
tooltip: 'Start ${issue.issueName}',
onPressed: () {},
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(
issue.title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
softWrap: true,
),
),
Text(
issue.issueName,
style: TextStyle(
color: Colors.white,
),
),
],
),
),
])));
}