Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I wanted to add a back button on my appBar and wanted to make the appBar transparent so that it shows only the back button.
Simran, this is a little tricky but it is possible with the combination of Stack, SingleChildScrollView and AppBar. Here is quick example demonstrating this,
return Scaffold(
body: Stack(children: <Widget>[
Container(
color: Colors.white,// Your screen background color
),
SingleChildScrollView(
child: Column(children: <Widget>[
Container(height: 70.0),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
])
),
new Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
title: Text(''),// You can add title here
leading: new IconButton(
icon: new Icon(Icons.arrow_back_ios, color: Colors.grey),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: Colors.blue.withOpacity(0.3), //You can make this transparent
elevation: 0.0, //No shadow
),),
]),
);
Note: You can make the AppBar completely transparent. However, you'll need to design your widgets accordingly to make sure back button is visible. In the example above, i just set the opacity.
Hope this helps. Good luck!
Just WRAP your widget into a Stack and then add an IconButton on top of the Stack and Navigator.pop(context) on button onPressed().
That should solve your problem.
return Stack(
alignment: Alignment.topLeft,
children: <Widget>[
YourScrollViewWidget(),
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: (){
Navigator.pop(context);
},
)
],
);
Related
This is my source code:
Scaffold(
body: Center(
child: Container(
color: Colors.green,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
fit: FlexFit.loose, child: Image.asset('images/demo.png')),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Container(
color: Colors.yellow,
child: Text('Cancel'),
),
),
Expanded(
child: Container(
color: Colors.red,
child: Text('Okay'),
),
),
],
),
],
),
),
),
);
This is the result:
I want it to be like this:
without using fixed sizes because the image dimensions may vary.
I already tried to use flexible on the row children. The problem with that solution is that the green container is being expanded like this:
which I don't want to happen.
EDIT, Did a little more searching and found what you seem to be looking for:
The IntrinsicWidth widget makes sure children have uniform width, which will be the width of the widest element (without the overlapping issue like in the Stack widget based solution). So this code accomplishes what you're trying to do:
Scaffold(
body: Center(
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 1,
fit: FlexFit.tight,
child: Image.asset('images/demo.png'),
),
Row(
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.yellow,
child: Text('Cancel'),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.red,
child: Text('Okay'),
),
),
],
),
],
),
),
),
);
Screenshot:
OLD ANSWER:
If you don't mind overlapping a little bit of the bottom of the image with the buttons, the stack class sizes itself to its non positioned children, so this would work for you:
Scaffold(
body: Center(
child: Stack(
fit: StackFit.loose,
children: [
Image.asset('images/demo.png'),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
flex: 1,
child: Container(
color: Colors.yellow,
child: Text('Cancel'),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.red,
child: Text('Okay'),
),
),
],
),
),
],
),
),
);
Screenshot:
Maybe this will help.
You can use Spacer(); between the two text Cancel & Okay. Spacer() will put second text to end of row.
Row(
children[
Container(child: Text('Cancel', style...)),
Spacer(),
Container(Text('Okay', style...)),
]
);
maybe you can get the width of the image and pass it to the container that wraps the column:
import 'dart:io';
File image = new File('image.png'); // Or any other way to get a File instance.
var decodedImage = await decodeImageFromList(image.readAsBytesSync());
final width = decodedImage.width;
I want to recreate a ListView as shown below. However when I'm trying to replicate it, my text is overflowing and the image isn't getting aligned with the text.
This is my code:
Expanded(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Card(
color: Colors.red,
child: ListView.builder(
padding: EdgeInsets.all(10.0),
itemCount: filteredUsers.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>\[
Row(
children: <Widget>\[
CircleAvatar(),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>\[
Text(
'Hello John',
style: TextStyle(
fontSize: 14.0,
color: Colors.grey,
),
),
SizedBox(
height: 5.0,
),
Text(
'the fox ran over the tree and jumped over the dog and cat that were sleeping under it ',
style: TextStyle(
fontSize: 16.0,
color: Colors.black,
),
),
SizedBox(
height: 5.0,
),
\],
),
\],
),
\],
),
);
},
),
),
),
),
This is my output:
Trying to achieve something similar to this:
There is ListTile available for the exact purpose.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: ListView(children: [
DemoListTile(),
DemoListTile(),
DemoListTile(),
DemoListTile(),
])),
);
}
}
class DemoListTile extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ListTile(
title: const Text("Hello World"),
isThreeLine:
true, //will fix the alignment if the subtitle text is too big
subtitle: const Text(
"Flutter demo big ss text here and there to break things everywhere, but still can't break things here"),
leading: CircleAvatar(backgroundColor: Colors.blue),
trailing: Icon(Icons.arrow_right));
}
}
which gives
To make text overflowing i use often the AutoSizeText Package:
https://pub.dev/packages/auto_size_text
With the AutoSizeText Widget your code can look like this:
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Container(
width: MediaQuery.of(context).size.width - 120,
child: AutoSizeText(
'the fox ran over the tree and jumped over the dog and cat that were sleeping under it ',
style: TextStyle(
fontSize: 16.0,
color: Colors.black,
),
textAlign: TextAlign.justify,
maxLines: 5,
),
),
),
With MediaQuery you can give the Container a dynamic width depending on your device width.
Optionale: You can give the Container a padding and you can set the textAlign property to justify for better look.
As someone already has mentioned, ListTile() would do the job perfectly.
If you want to stick with your own layout for the ListView elements, I would recommend you to you use the flex()-Widget for position the different parts inside the Column and to use the Expanded()-Widget for moving something (like an arrow) to the end of the list element.
Of course you can also use flex()-Widgets for the row to push the arrow to the end of the list element.
To prevent text overflow, just use the TextOverflow.ellipsis or something similar.
How do I put a image.network() inside a card?
new Card(
child: new Container(
Image.network(data[index]['image'], width:200.0, height: 200.0,fit: BoxFit.cover),
child: new Text(data[index]['title']),
padding: const EdgeInsets.all(20.0),
),
)
It works fine if I remove the Image.network(...) line.
new Card(
child: new Container(
child: new Text(data[index]['title']),
padding: const EdgeInsets.all(20.0),
),
)
I solved it myself but will put the code here just in case anyone else has this issue. As there is no documentation on how to do what I wanted to do. I am sure there maybe better ways to get the outcome like (text over the bottom of the image, but this question was how to get an image from network to show in a card)
new Card(
child: new Container(
child: new Column(
children: <Widget>[
Column(
children: <Widget>[
Image.network(data[index]['image'], fit: BoxFit.fitWidth),
Text(data[index]['title'], style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold)),
]
),
],
),
),
)
I solved it myself but will put the code here just in case anyone else has this issue. As there is no documentation on how to do what I wanted to do. I am sure there maybe better ways to get the outcome like (text over the bottom of the image, but this question was how to get an image from network to show in a card)
new Card(
child: new Container(
child: new Column(
children: <Widget>[
Column(
children: <Widget>[
Image.network(data[index]['image'], fit: BoxFit.fitWidth),
Text(data[index]['title'], style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold)),
]
),
],
),
),
)
I want to show a popup on a button tap. When I am trying to show AlertDialog with my custom design child Container of this AlertDialog not covering whole space. It has some padding from corners.
I have implemented in this way:
AlertDialog(
shape: OutlineInputBorder(
borderRadius: BorderRadius.circular(16.0)
),
content: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
color: Colors.redAccent,
width: screenSize.width,
height: screenSize.height*.90,
child: Text('test'),
)
],
),
),
)
For more info I am adding screenshot.
I found the solution for this. I resolve this issue by adding following tag in AlertDialog:
contentPadding: EdgeInsets.all(0.0),
I have trouble integrating images with interactive pins on Flutter.is it even possible? if so, how can I do it? Im looking for something similar to WordPress's Image Mapper plugin!
The Stack widget is what you want:
Stack(
children: <Widget>[
<your image>,
Positioned(
left: 50.0,
top: 30.0,
child: <your pin>
),
...
],
)