So I'm trying to remove the bottom margin of raisedButton so it will look like it is merged with the card below it.
here's what it looks like
here is my code
Expanded(
child: Card(
elevation: 5,
// shape:
// RoundedRectangleBorder(borderRadius: BorderRadius.circular(22)),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Apakah anak sudah bisa ... ?",
style: TextStyle(fontWeight: FontWeight.bold)),
),
],
),
Row(
children: <Widget>[
Expanded(
child: RaisedButton(
child: Text(
"Iya",
style: TextStyle(color: Colors.white),
),
color: Colors.green[300],
onPressed: () {}),
),
Expanded(
child: RaisedButton(
child: Text(
"Tidak",
style: TextStyle(color: Colors.white),
),
color: Colors.red[200],
onPressed: () {}))
],
)
],
),
),
)
or do you guys have any other alternative solution to achieve that?
You can explicitly set your Row height to match the height of your RaisedButton. Simply wrap it inside a Container and add the height attribute.
If you want to, you can access the default height by using Theme.of(context).buttonTheme.height. Theme.of returns the ThemeData used in the current context.
Here a minimal example:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
child: Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Test'),
Container(
height: Theme.of(context).buttonTheme.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(
onPressed: () {},
child: Text('Yes'),
color: Colors.green,
),
RaisedButton(
onPressed: (){},
child: Text('No'),
color: Colors.red,
)
],
),
),
],
)
),
),
)),
);
}
}
I had the same problem. NikasPor's answer didnt work for me, unfortunately. The way I fixed it is by seeting the crossAxisAlignment on the row to .stretch
Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children:[ /* Buttons Here */]
)
Related
import 'package:flutter/material.dart';
void main() => runApp(HomePage());
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
children: [
Container(
color: Colors.blue,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
ButtonBar(
children: <Widget>[
FlatButton(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Center(
child: Text(
"ljsdgnvsdnv",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18),
),
),
Text(
"sljdvnldnvsdb",
style: TextStyle(fontSize: 15),
),
],
),
height: 60,
width: 600,
color: Colors.orange,
),
onPressed: () {
print("Buton");
},
),
],
)
],
),
),
],
),
),
);
}
}
I can't set the height of my containers after some limit(also the widht of the second container), it doesn't give any errors but at the same time it doesn't change it's height. In flutter inspector their height and widht values are the values which are I assigned but it doesn't look like it. What should I do? (Text are random)
I just tried your code and didn't find any error while running it. But if the error that you are talking about are linked with the size of the container and some limit that you have added, than it's because you are trying to create an widget bigger than the zone that contain the widget.
You should check the limit that you have by trying:
mainAxisSize: MainAxisSize.max,
And than you could give value that are within the zone.
Hello I am new on flutter and I am currently working on a design which I saw but the problem is that I am having issue on putting the Icon on the right side and the Row is not same size as others. I hope you can help me so it will broaden my knowledge on this flutter. I just started Flutter this week.
Design intended :
Current work :
Code :
#override
Widget build(BuildContext context) {
// TODO: implement build
Widget titleText = Container(
padding: const EdgeInsets.all(32),
child: Center(
child: Text('Select Screen Lock',style: TextStyle(fontSize: 32.0,fontWeight: FontWeight.bold),),
)
);
Widget subTitleText = Container(
padding: const EdgeInsets.all(32),
child: Center(
child: Text('Secure your phone with a screen lock style,',style: TextStyle(fontSize: 16,fontWeight: FontWeight.normal),),
),
);
Widget selectionContainer = Container(
width: 200,
child: IntrinsicWidth(
child: Column(
children: <Widget>[
_selectMenu('Password'),
_selectMenu('Pin Code'),
_selectMenu('Finger Print')
],
),
)
);
return MaterialApp(
home: Scaffold(
body: ListView(
children: <Widget>[
titleText,
subTitleText,
Center(
child:
selectionContainer,
)
],
),
),
);
}
Column _selectMenu(String title){
return Column(
children: <Widget>[
Row(
children: <Widget>[
Text(title), Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
size: 16,
)
],
)
],
);
}
Problem here:
Column _selectMenu(String title){
return Column(
children: <Widget>[
Row(
children: <Widget>[
Text(title), Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
size: 16,
)
],
)
],
);
First of all, remove Column(why we need it here?), and add space between items(please check mainAxisAlignment and crossAxisAlignment), then we get
Widget _selectMenu(String title){
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(title), Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
size: 16,
)
]);
I want to display a List and beneath it a Persistent footer, a Column with some rows. I use persistentFooterButtons of Scaffold.
The closest to what I get is this:
But I am unable to align the fields to the right.
When I work with Align or Spacer, the Widgets disappear.
The content of persistentFooterButtons.
FittedBox(
child: Column(
children: <Widget>[
FlatButton(
onPressed: () {
Navigator.pushNamed(context, RouteName.BAUSTELLEN);
},
child: Align(
alignment: Alignment.bottomLeft,
child: Text('Bestellen'),
),
),
Row(
children: <Widget>[
Text('$priceInfo '),
MyFutureBuilder(
future: sum,
builder: (context, double sum) {
var mySum = formatDoubleNumber(sum);
return Text('$mySum');
},
),
Container(
width: ImpexStyle.horizontalPadding,
),
],
),
Row(
children: <Widget>[
Text('Ihr Einkaufsrahmen '),
Text(
'$einkaufsrahmen',
style: TextStyle(
color: einkaufsrahmen == 0 ? Colors.red : Colors.black),
),
Container(
width: ImpexStyle.horizontalPadding,
),
],
),
],
),
);
If I put the elements directly to persitentFooterButtons, this is what I get, the text is scattered around and my list is not shown.
and the Code
Scaffold(
body: WarenkorbListe(),
persistentFooterButtons: <Widget>[
// WarenkorbFooter(),
FlatButton(
onPressed: () {
Navigator.pushNamed(context, RouteName.BAUSTELLEN);
},
child: Align(
alignment: Alignment.bottomLeft,
child: Text('Bestellen'),
),
),
Row(
children: <Widget>[
Text('$priceInfo '),
Container(
width: ImpexStyle.horizontalPadding,
),
],
),
Row(
children: <Widget>[
Text('Ihr Einkaufsrahmen '),
Text(
'$einkaufsrahmen',
style: TextStyle(
color: einkaufsrahmen == 0 ? Colors.red : Colors.black),
),
Container(
width: ImpexStyle.horizontalPadding,
),
],
),
],
);
Try to align with your column instead
FittedBox(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end, // this
children: <Widget>[
i am trying to retrieve data from firestore as dropdown list, got this tutorial and error show up, please help, totally new with flutter.
This function has a return type of 'Row', but doesn't end with a return statement.
Try adding a return statement, or changing the return type to 'void'.
here is the code :
class _MyHomePageState extends State<MyHomePage> {
var selectedCurrency, selectedType;
final GlobalKey<FormState> _formKeyValue = new GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(
Icons.edit,
color: Colors.white,
),
onPressed: () {}),
title: Container(
alignment: Alignment.center,
child: Text("Account Details",
style: TextStyle(
color: Colors.white,
)),
),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.edit,
size: 20.0,
color: Colors.white,
),
onPressed: null,
),
],
),
body: Form(
key: _formKeyValue,
autovalidate: true,
child: new ListView(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
children: <Widget>[
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.edit,
size: 25.0,
color: Color(0xff11b719),
),
SizedBox(width: 50.0),
],
),
SizedBox(height: 40.0),
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("currency").snapshots(),
builder: (context, snapshot) {
}),
SizedBox(
height: 150.0,
),
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RaisedButton(
color: Color(0xff11b719),
textColor: Colors.white,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text("Submit", style: TextStyle(fontSize: 24.0)),
],
)),
onPressed: () {},
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0))),
],
),
],
),
));
}
}
I'm totally new to Flutter myself, but it appears the method build of the MyHomePageState class does have a return statement. In fact, all the method body is wrapped inside that return statement:
Widget build(BuildContext context) {
return Scaffold(
...
)}
That build method returns a complete description of your page, including the Row you mentioned in your question deeply nested in structure:
return Scaffold(
...
body: Form(
...
child: new ListView(
...
children: <Widget>[
SizedBox(height: 20.0),
Row( <---------------- here it is
...
Or did I missed your point?
I am trying to match this design
on tap the card should expand
I cannot use a card wrapping an expansion tile because the expansion tile is basically only one row, I was trying to follow this example
flutter_catalog
I googled a lot and could not find an example of what I am trying to achieve, the closest thing I could find on stackoverflow was this other question is there not in flutter a collapsible / expansible card?
You can absolutely use a Card wrapping an ExpansionTile. The ExpansionTile has a title property which takes a Widget so you can pass any Widget you want into it.
Messy example code, but hopefully you get the idea:
class ExpandedTile extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0))),
elevation: 2,
margin: EdgeInsets.all(12.0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ExpansionTile(
backgroundColor: Colors.white,
title: _buildTitle(),
trailing: SizedBox(),
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Text("Herzlich Willkommen"),
Spacer(),
Icon(Icons.check),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Text("Das Kursmenu"),
Spacer(),
Icon(Icons.check),
],
),
)
],
),
),
);
}
Widget _buildTitle() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text("MODUL 1"),
Spacer(),
Text("Mehr"),
],
),
Text("Kursubersicht"),
Row(
children: <Widget>[
Text("6 Aufgaben"),
Spacer(),
FlatButton.icon(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0))),
padding: EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0),
color: Colors.blue,
textColor: Colors.white,
onPressed: () {},
icon: Icon(Icons.play_arrow),
label: Text("Fortsetzen"),
),
],
),
],
);
}
}
produces
and when tapped