Flutter Web,How to align img and text in Row? - flutter-layout

In FlutterWeb,
Center(
child: Container(
padding: EdgeInsets.only(bottom: 6),//ugly
child: Text(
'123',
style: TextStyle(fontSize: 12, color: ColorUtil.mainBlue),
),
),
),
Is there any other method?

Related

How to get indent between image and appbar in Flutter app?

Here is the code without body of the widget:
Column(
children: [
Material(
elevation: 0,
child: Image.asset(
i.first,
fit: BoxFit.fitWidth,
),
),
SizedBox(
width: 130,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Text(
i.last
),
),
),
),
],
Need to add space between appbar and image.
How can i achieve additional space between image and appbar widgets?
You can use Padding Widget:
body: Padding(
padding: const EdgeInsets.all(8.0),
child: GridView.count(
crossAxisCount: 2,
children: [
...myImageAndCaption.map(
(i) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Material(
elevation: 0,
child: Image.asset(
i.first,
fit: BoxFit.fitWidth,
height: 150,
width: 150,
),
),
SizedBox(
width: 130,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Text(
i.last,
style: const TextStyle(
fontSize: 22,
letterSpacing: 1.0,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
),
),
],
),
),
],
),
),

How to solve RangeError (index): Invalid value: Valid value range is empty: 1 in Flutter/Dart

My code is giving me the output what i required but there is one error which i need support to resolve.
RangeError (index): Invalid value: Valid value range is empty: 1
Below is the csv which i am using:
german word,german sentence,english word,english sentence
die Ansage,Hören Sie auf die Ansagen.,announcement,Listen to the announcements.
Here is the code:
I am getting error on line wher i am calling csvTable[index1+1][0],
class _CsvState extends State<Csv> {
#override
Widget build(BuildContext context, ) {
return FutureBuilder<String>(
future: rootBundle.loadString('assets/questions.csv'),
builder: (BuildContext context, AsyncSnapshot<String> snapshot,) {
List<List<dynamic>> csvTable =
CsvToListConverter().convert(snapshot.data);
return Scaffold(
appBar: AppBar(
title: Text("A1 German Vocabulary"),
),
body: new TransformerPageView (
itemCount: csvTable.length-1,
loop: true,
viewportFraction: 0.8,
itemBuilder: (BuildContext context, int index1) {
return new Padding(
padding: new EdgeInsets.all(10.0),
child: new Material(
elevation: 8.0,
textStyle: new TextStyle(color: Colors.white),
borderRadius: new BorderRadius.circular(10.0),
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
new Positioned(
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
child: new Text(
csvTable[index1+1][0],
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
),
),
alignment: Alignment.center,
),
SizedBox(height: 20,),
new Container(
child: new Text(
csvTable[index1+1][1],
textAlign:TextAlign.center,
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
),
),
alignment: Alignment.center,
),
SizedBox(height: 20,),
new Container(
margin: const EdgeInsets.only(left: 10.0, right: 20.0),
child: Divider(
color: Colors.black,
height: 36,
)),
new Container(
child: new Text(
csvTable[index1+1][2],
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
height: 2
),
),
alignment: Alignment.center,
),
SizedBox(height: 20,),
new Container(
child: new Text(
csvTable[index1+1][3],
textAlign:TextAlign.center,
style: new TextStyle(
fontSize: 24.0,
color: Colors.black,
),
),
alignment: Alignment.center,
),
],
),
left: 10.0,
right: 10.0,
top: 100.0,
)
],
),
),
);
},
// itemCount:811
),
);
});
}
}

Anroid-layout How can make custom button like this?

those three things are clickable buttons, I don't know how to make it....
enter image description here
return Scaffold(
backgroundColor: Colors.grey[200],
body: Padding(
padding: const EdgeInsets.all(28.0),
child: Column(
children: [
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
Card(
child: new InkWell(
onTap: () {},
child: Container(
child: ListTile(
title: Text(
"Bignners Level Lessons",
),
subtitle: Text("write your text"),
),
height: 100.0,
),
),
),
],
),
),
);
}
}

Is it possible to put A Column in a Row in Flutter?

I tried putting a column in a row. But it does not work.
Then I tried putting the row and column in the same safe area using different child properties. It does not work.
The column is supposed to be in the middle of the row.
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.teal,
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 100.0,
width: 100.0,
color: Colors.yellow,
child: Text('Container 1'),
),
Container(
height: 100.0,
width: 100.0,
color: Colors.green,
child: Text('Container 1'),
),
Container(
width: double.infinity,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
height: 100.0,
color: Colors.red,
child: Text('Container 1'),
),
Container(
height: 100.0,
color: Colors.blue,
child: Text('Container 1'),
),
],
),
),
),
);
}
}
The error message is "BoxConstraints forces an infinite width."
Try expanded widget with flex attribute, you can put the column in a row:
Container(
width: 300,
height: 100,
child: Row(
children: <Widget>[
Expanded(flex: 1,
child: Container(
color: Colors.red,
width: double.infinity,
height: double.infinity,
),
),
Expanded(flex: 2,
child: Column(
children: <Widget>[
Expanded(flex:1,
child: Container(
color: Colors.yellow,
width: double.infinity,
height: double.infinity,
),
),
Expanded(flex:1,
child: Container(
color: Colors.blue,
width: double.infinity,
height: double.infinity,
),
),
],
),
),
Expanded(flex: 1,
child: Container(
color: Colors.green,
width: double.infinity,
height: double.infinity,
),
),
],
),
),
also, you can place column using a container
body: SafeArea(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 100.0,
color: Colors.red,
),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 100.0,
height: 100.0,
color: Colors.yellow,
),
Container(
width: 100.0,
height: 100.0,
color: Colors.green,
),
],
),
),
Container(
width: 100.0,
color: Colors.blue,
),
],
),
),

Flutter, How to remove white spaces around dialog box?

I am calling this dialog while getting data from server. This dialog box is having white spaces around it. I can I remove this white space around my dialog box. Here is my code.
var bodyProgress = new Container(
decoration: new BoxDecoration(
color: Colors.blue[200],
borderRadius: new BorderRadius.circular(10.0)
),
width: 300.0,
height: 200.0,
//color: Colors.blue,
alignment: AlignmentDirectional.center,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Center(
child: new SizedBox(
height: 50.0,
width: 50.0,
child: new CircularProgressIndicator(
value: null,
strokeWidth: 7.0,
),
),
),
new Container(
margin: const EdgeInsets.only(top: 25.0),
child: new Center(
child: new Text(
"Signing up...",
style: new TextStyle(
color: Colors.white
),
),
),
),
],
),
);
Here I am calling this dialog. I've tried with both AlertDialog() and SimpleDialog() having same issue with both.
showDialog(context: context, child: new AlertDialog(
content: bodyProgress,
));
Inside AlertDialog set contentPadding 0
contentPadding: EdgeInsets.zero,
make title to have Container, and add
width: MediaQuery.of(context).size.width,
Then give 0 (or what value you want to have for horizontal patting) to insetPadding like this:
insetPadding: EdgeInsets.symmetric(horizontal: 0),
Below is my example show dialog code, contains alertDialog with horizontal padding = 15 :
Future<void> _showLogoutDialog(BuildContext context) async {
return showDialog<void>(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: EdgeInsets.only(top: 12, left: 24, right: 12),
contentPadding: EdgeInsets.only(top: 12, left: 24, bottom: 20),
insetPadding: EdgeInsets.symmetric(horizontal: 15),
titleTextStyle: TextStyle(
color: ColorStyles.primary_blue500,
fontFamily: 'Muli',
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
fontSize: 16.0,
),
contentTextStyle: TextStyle(
color: ColorStyles.grey2,
fontFamily: 'Muli',
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
fontSize: 14.0,
),
title: Container(
width: screenUsableHeight(context),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Log out'),
IconButton(
icon: Icon(
Icons.close,
color: ColorStyles.grey2,
size: 28,
),
onPressed: () => Navigator.of(context).pop(),
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
tooltip: "close",
)
],
),
),
//EN: Logging out
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('Do you want to leave?'),
],
),
),
actions: <Widget>[
FlatButton(
child: Text(
'Yes',
style: TextStyle(
color: ColorStyles.primary_blue500,
fontFamily: 'Muli',
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
fontSize: 16.0,
),
), //EN: Yes
onPressed: () {
_logOut(context);
},
),
FlatButton(
child: Text(
'No',
style: TextStyle(
color: ColorStyles.grey2,
fontFamily: 'Muli',
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
fontSize: 16.0,
),
), //EN: No
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
This looks like:
display of alert dialog
titlePadding: EdgeInsets.zero,
contentPadding: EdgeInsets.zero,
Don't use AlertDialog at all. Just send bodyProgress to showDialog
showDialog(context: context, builder: (_) => bodyProgress,);
add the file to your project https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/dialog.dart, use the CustomAlertDialog and set the contentPadding to 0.0 by using EdgeInsets.all(0.0), finally adjust the border raidius to that of your bodyprogress
use like this ->
using get: ------------->
Get.generalDialog(
pageBuilder: (BuildContext buildContext, Animation animation,
Animation secondaryAnimation) =>
AlertDialog(
contentPadding: EdgeInsets.zero,
// this padding user for outside of alert padding
insetPadding: EdgeInsets.symmetric(horizontal: 10),
content: Container(
height: Get.height - 300, // Change as per your requirement
width: Get.width, // Change as per your requirement
child: <Your Widget>
),
),
));
using alert dialog:------>
CustomAlertDialog(
content: new Container(
width: 260.0,
height: 230.0,
decoration: new BoxDecoration(
shape: BoxShape.rectangle,
color: const Color(0xFFFFFF),
borderRadius:
new BorderRadius.all(new Radius.circular(32.0)),
),
child: <Your widget>
),
);
});

Resources