How to cut list in flutter application? - flutter

I want to make a note app but I faced a problem.When I dont scroll my list it looks great(for me ) but when I scroll it green background moving to the top of application and I want to cut it and make fixed size.I also want make this list more custom,make a bigger margin between elements and change form to the rounded rectangle
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Positioned(
top: 0.0,
child: Row(
children: <Widget>[
Container(
child: Text(
"Notes",
style: TextStyle(
color: Color.fromRGBO(107, 119, 141, 1),
fontSize: 72,
),
),
),
Container(
margin: EdgeInsets.only(top: 50),
child: Text(
"Never Settle",
style: TextStyle(
fontSize: 12,
color: Color.fromRGBO(107, 119, 141, 0.25),
),
),
),
SizedBox(width: 20),
Container(
child: Image.asset(
'assets/images/magnifier.png',
height: 44,
width: 44,
),
),
SizedBox(width: 30),
Container(
child: Image.asset(
'assets/images/3dot.png',
height: 44,
width: 44,
),
),
],
),
),
Positioned(
top: 75.0,
child: ListView.builder(
itemCount: dList.length,
itemBuilder: (context, index) {
return Ink(
color: Colors.green,
child: ListTile(
title: Text(
dList[index],
style: TextStyle(
fontSize: 25,
),
),
)
);
},
),
),
Positioned(
height: 55,
width: 55,
// top:0.0,
right: 20.0,
bottom: 20.0,
child: Image.asset(
'assets/images/plus.png',
height: 22,
width: 22,
),
),
],
),
),
);
}
}
enter image description hereenter image description here

So I think this happens to you becouse you are using Stack widget. It looks nice, until you move list, becouse in fact it is floating over your top bar.
What I suggest you to do is using Scaffold and Column, here is your modified code:
Scaffold(
body: Container(
color: Colors.blue,
child: Column(
children: <Widget>[
SizedBox(height: 50),
Container(
color: Colors.indigo,
child: Row(
children: <Widget>[
Container(
child: Text(
"Notes",
style: TextStyle(
color: Color.fromRGBO(107, 119, 141, 1),
fontSize: 72,
),
),
),
Container(
margin: EdgeInsets.only(top: 50),
child: Text(
"Never Settle",
style: TextStyle(
fontSize: 12,
color: Color.fromRGBO(107, 119, 141, 0.25),
),
),
),
SizedBox(width: 20),
Container(
child: Icon(Icons.search, size: 40, color: Colors.red),
),
SizedBox(width: 30),
Container(
child: Icon(Icons.menu, size: 40, color: Colors.red),
),
],
),
),
Expanded(
child: Container(
color: Colors.green,
child: ListView.separated(
separatorBuilder: (BuildContext context, int index) =>
const Divider(),
itemCount: dList.length,
itemBuilder: (context, index) {
return Ink(
color: Colors.green,
child: ListTile(
title: Text(
dList[index],
style: TextStyle(
fontSize: 25,
),
),
));
},
),
),
),
],
),
),
floatingActionButton:
FloatingActionButton(onPressed: () => {}, child: Icon(Icons.add)),
)
And how it looks like:
What scaffold does is providing you perfect material design layout structure, it also wraps your code with Material, so you can use its benefits.
Scaffold also gives you opportunity to set your FloatingActionButton, you can find it on the bottom of the code, look how easy it's done, you don't need to create your own round button - it's already provided.
Read more about Scaffold
Another tip for you is using Icon() instead of importing your own images, three reasons for that:
It's super easy to do, you just write Icon(Icons.search), and it's done
Icons are scallable and modifable, you can change size, color
They support Material design
If you wrap Icon with IconButton, you can instantly get a beutiful button with tapping animation.
Read more about Icon and IconButton
List of Icons
If you want to make customized list tiles try this as your ListViews itemBuilder:
return Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 8),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black38.withOpacity(0.2)),
borderRadius:
BorderRadius.all(Radius.circular(20))),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
dList[index],
style: TextStyle(
fontSize: 25,
),
),
),
),
);
Result:
If you wrap something with Container it will get inside of its body, then you can decorate this container with rounded borders, color, borders and more.
Read more about Container
Last tip for you is using ListView.separated instead of ListViev.builder if you want to easly get a separator between your tiles.
Try to adjust code for you and good luck, if you have any questions feel free to ask.

Set background color to green ins scaffold and set transparent color to link then try

Related

How to show buttons like parallelly in flutter

I am trying to show the buttons in parallelly view like showing the below image. How to align buttons in parallelly in flutter for android application. But I do not know how to align it. I have attached images for more info. If anyone knows the answer please help to find the solution.
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
const SizedBox(
height: 510,
),
SizedBox(
width: 300, // <-- Your width
height: 50, // <-- Your height
child: ElevatedButton(
onPressed: () {
//validateForm();
Navigator.push(context,
MaterialPageRoute(builder: (c) => const PhoneLoginScreen()));
},
style: ElevatedButton.styleFrom(
primary: Color(0xff557de3),
shape: StadiumBorder()
),
child: const Text(
"SIGN IN WITH",
style: TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.bold
),
),
),
),
const SizedBox(
height: 20,
),
SizedBox(
width: 300, // <-- Your width
height: 50, // <-- Your height
child: ElevatedButton(
onPressed: () {
onGoogleSignIn(context);
},
style: ElevatedButton.styleFrom(
primary: Color(0xFF557de3),
shape: CircleBorder(),
padding: EdgeInsets.all(24),
//primary: Color(0xFFF5F1F1),
),
child: const Text(
"GMAIL",
style: TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.bold
),
),
),
),
SizedBox(
width: 300, // <-- Your width
height: 50, // <-- Your height
child: ElevatedButton(
onPressed: () {
onGoogleSignIn(context);
},
style: ElevatedButton.styleFrom(
primary: Color(0xFF557de3),
shape: CircleBorder(),
padding: EdgeInsets.all(24),
//primary: Color(0xFFF5F1F1),
),
child: const Text(
"PHONE",
style: TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.bold
),
),
),
),
],
),
),
)
From my code:
Expecting like this:
I would probably switch to a Wrap widget considering your expectation.
See Flutter documentation
Main differences are:
Add infinite width to the first widget, so it always takes all the space available.
Removed width on the others. I don't see the need for a 300 width. I might have missed something.
Handle spacing directly with the Wrap widget properties
SingleChildScrollView(
child: Wrap(
alignment: WrapAlignment.center,
runSpacing: 20.0, // Or more
spacing: 20, // Or more
children: [
SizedBox(
width: double.infinity, // <-- Your width
height: 50, // <-- Your height
child: // Button
),
SizedBox(
height: 50, // <-- Your height
child: // Button
),
SizedBox(
height: 50, // <-- Your height
child: // Button
),
],
),
),
You could use Row widget for this inside the Column widget.
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
EmailButton(),
PhoneButton(),
],
),

How to make list items clickable so as to redirect user to their specific different pages without making different page for each item

I have created a list view of items in my app, and now I want the items to be clickable so that each item redirects the user to their respective page. What will be the easier way to do this without making a different page for each item on the list? Here's the code for the list which picks up data from json format.
Expanded(
child: ListView.builder(
// scrollDirection: Axis.horizontal,
itemCount: cryptoData.length,
itemBuilder: (context, index) {
return Container(
padding: EdgeInsets.fromLTRB(20, 10, 16, 0),
height: 100,
width: double.maxFinite,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 5,
child: Container(
child: Padding(
padding: EdgeInsets.all(7),
child: Stack(children: <Widget>[
Align(
alignment: Alignment.centerRight,
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 5, top: 5),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
cryptoIcon(
cryptoData[index]),
SizedBox(
height: 10,
),
// Spacer(),
cryptoChange(
cryptoData[index]),
SizedBox(
width: 10,
),
SizedBox(
width: 20,
)
],
),
],
))
],
),
)
]),
),
),
),
);
}),
),
Widget cryptoIcon(data) {
return Padding(
padding: const EdgeInsets.only(left: 0),
child: Align(
alignment: Alignment.centerLeft,
child: Image(
image: AssetImage('${data['image']}'),
)),
);
}
Widget cryptoChange(data) {
return Padding(
padding: EdgeInsets.only(left: 50),
child: RichText(
text: TextSpan(
text: '${data['change']}',
style: TextStyle(
fontFamily: "Raleway",
fontWeight: FontWeight.w900,
color: Color.fromARGB(255, 4, 35, 93),
fontSize: 14),
children: <TextSpan>[
TextSpan(
text: '\n${data['changeValue']}',
style: TextStyle(
color: Color.fromARGB(255, 4, 35, 93),
fontSize: 12,
)),
],
),
),
);
}
}
One possible way is that store data used in each list view element/tile as an object and pass that data to next page. You'll design page once and it will appear with new data every time you click different list view element/tile. If you can share code I can answer more accurately.

flutter Problem : How to make Upcoming section in Top Right in card

I want to make Upcoming section in top right but I am not understatig how to do it.
I want to make Upcoming section in top right but I am not understatig how to do it.
I want to make Upcoming section in top right but I am not understatig how to do it.
This is ny code
InkWell(
onTap: () {
// Navigator.pushReplacement(
// context,
// MaterialPageRoute(
// builder: (context) => HomePage(),
// ),
// );
// setState(() {
// isSelect = 1;
// });
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: SizedBox(
height: 147,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.center,
children: [
Stack(
children: [
Container(
padding: EdgeInsets.only(right: 15, left: 15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: AssetImage("assets/orange_card.png"),
fit: BoxFit.fill,
),
),
height: 147,
width: MediaQuery.of(context).size.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(top: 16.0),
child:Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Explorer Package",
style: TextStyle(
fontSize: tSize18,
fontWeight: FontWeight.w500),
),
SizedBox(
height: 6,
),
Text(
"Best package for price",
style: TextStyle(
fontSize: tSize14,
),
),
SizedBox(
height: 13,
),
Text(
"\$99 USD",
style: TextStyle(
fontSize: tSize27,
fontWeight: FontWeight.w500),
),
],
),
),
Padding(
padding: EdgeInsets.only(bottom: 8),
child: Image.asset(
'assets/onbb.png',
height: 114,
width: 114,
),
),
],
),
),
Positioned(
bottom: 130,
right: 0,
child: Container(
decoration: BoxDecoration(
color: Color(0xff158998),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
topRight: Radius.circular(20),
),
),
width:160,
height: 25,
child: Center(
child: Text(
'Upcoming Plans',
style: TextStyle(
color: Colors.white,
fontSize: tSize14,
),
),
),
),
),
],
),
Positioned(
width: 18,
bottom: 0,
child: Center(
child: Container(
height: 15,
width: 15,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Theme(
data: ThemeData(
//here change to your color
unselectedWidgetColor:
Color(0xff3a99a4),
),
child: Radio(
activeColor: Colors.green,
overlayColor:
MaterialStateProperty.all(
Colors.red),
value: isSelect,
groupValue: 1,
onChanged: (int? value) {
// setState(() {
// isSelect = value!;
// });
},
),
),
),
),
),
],
),
),
),
),
In actuall i want like this
But It becoming like this. I want Upcoming section which is in top right.
It would probably make your life easier to clean up the code. You have multiple stacks, which is usually a sign the layout can be simplified. But your problem can be fixed in a couple of small changes. The explanation and an image of running app is below the code.
Upcoming Plans Changes:
Positioned(
// bottom: 130,
top: 0,
right: 0,
child: Container(
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Color(0xff158998),
borderRadius: BorderRadius.all(Radius.circular(20)
),
),
width:160,
height: 28,
child: const Center(
child: Text(
'Upcoming Plans',
style: TextStyle(
color: Colors.white,
fontSize: 14,
),
),
),
),
),
Explorer Package container change
Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.only(right: 15, left: 15),
The container with "Explorer Package" and the one with "Upcoming plans" (layered above it) need to have offsets, either by Position or margin.
First, anchor the "Upcoming Plans" to the TOP, not the bottom. That way, no matter how high the explorer package is, it will look ok. Then, set the margin for the Explorer container to offset it from the package.
Finally, I think you want symmetric radii for the Upcoming Plans container border.
I've adapted the code and ran it. I changed some of the background colors so you can clearly see what I'm doing. I think you want it to look like this:
Again, it would make it MUCH easier for you and others in the future if you simplify the layout. Use one stack and try to remove the fixed heights. It makes your card harder to reuse (especially if you get new graphics assets). Good luck.

Flutter increase ListTile height

I want to have a list tile that has a decent sized leading image, then a description of the item and an icon.
What I am finding, despite searching for answers online, is that I am unable to increase the height of the list tile no matter what height the leading image is.
Code:
ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 100,
minHeight: 260,
maxWidth: 104,
maxHeight: 264,
),
child: Image.asset('lib/images/burger_texas_angus.jpg', fit: BoxFit.fill),
),
title: Text('Texas Angus Burger'),
subtitle: Text('With fries and coke.'),
trailing: Icon(
Icons.menu,
),
onTap: () {},
onLongPress: () {},
dense: false,
),
Want it to end up looking something like this, where they have a nice big square leading icon which appears to dictate the height of the listtile, whereas everything I am doing crams the image into a narrow tile.
Ok so the answer to this is that it isn't possible. A ListTile is a very, very basic built-in widget that can only be a particular height, and there is nothing you can do about it.
If you want to do anything visually cool, with pictures etc like I have shown in my question, you have to create a custom CARD instead.
I will show my resulting code for a basic card layout that will give a similar result to the image I posted, in case anyone needs some help with this:
Container(
width: MediaQuery.of(context).size.width * 0.94,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0.0),
),
color: Colors.white70,
elevation: 10,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(2.0),
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.28,
maxHeight: MediaQuery.of(context).size.width * 0.28,
),
child: Image.asset(
'lib/images/burger_texas_angus.jpg',
fit: BoxFit.fill
),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * 0.5,
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
child: Text(
'Texas Angus Burger',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
),
Container(
width: MediaQuery.of(context).size.width * 0.5,
child: Padding(
padding: const EdgeInsets.fromLTRB(5, 10, 0, 0),
child: Text(
'100% Australian Angus grain-fed beef with cheese and pickles. Served with fries.',
style: TextStyle(
fontSize: 12,
),
),
),
),
],
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(5, 40, 0, 0),
child: Text(
'\$ 24.00',
style: TextStyle(
fontSize: 14,
),
),
),
],
),
],
),
),
),
],
),
),
Try this:
Container(height: 100, child: ListTile(
title: Text("My Title"),
trailing: Icon(Icons.arrow_right),
));
you can wrap ListTile with Container and give it width and height
ListTile(
leading: Container(
height: 80,
width: 80,
child: CircleAvatar(
backgroundImage: AssetImage(
'assets/images/splash_view_images/splash.png'),
),
),
title: Text('some text'),
subtitle:
Text('some text.'),
),

I want to do the expandable list view as below in attached image. How can I achieve this type of functionality in flutter?

How can I achieve this?. I have tried customizing ExpansionTile but not able to get similar effects on expansion and collapse. Mainly the prefix icon is bigger in size and so the expandable text is not close to the date. Also, the suffix icon for expanding/collapsing not fully covered with the background color.
I am also attaching an image that I have tried. I have used https://pub.dev/packages/expandable#-readme-tab- to achieve a similar effect but no luck.
I am really stuck at this place and want any kind of help.
Your help will be appreciated.
Thanks.
Just implemented, try this:
ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return ExpandableNotifier(
child: Card(
elevation: 4,
child: Expandable(
collapsed: Container(
width: MediaQuery.of(context).size.width,
height: 105,
child: ExpandableButton(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.all(10),
child: ClipOval(
child: Container(
height: 80,
width: 80,
color: Colors.yellow,
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Welkom bij Haaer',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
Text(
'2019/06/01 11:04',
style: TextStyle(
color: Colors.grey,
fontSize: 12.0,
),
),
Text(
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla',
softWrap: true,
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
],
),
),
),
Container(
color: Colors.yellow,
width: 30,
height: 105,
child: Icon(
Icons.keyboard_arrow_right,
color: Colors.white,
),
),
],
),
),
),
expanded: Container(
height: 200,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.all(10),
child: ClipOval(
child: Container(
height: 80,
width: 80,
color: Colors.purple,
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Welkom bij Haaer',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
Text(
'2019/06/01 11:04',
style: TextStyle(
color: Colors.grey,
fontSize: 12.0,
),
),
Text(
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla'
'blablablablablablablablablablablablablablablablablablablablablabla',
softWrap: true,
),
SizedBox(
height: 5,
),
Container(
width: 80,
height: 20,
child: RaisedButton(
padding: EdgeInsets.all(0),
color: Colors.purple,
child: Text('show'),
onPressed: () {},
),
),
],
),
),
),
ExpandableButton(
child: Container(
color: Colors.purple,
width: 30,
height: 200,
child: Icon(
Icons.keyboard_arrow_down,
color: Colors.white,
),
),
),
],
),
),
),
),
);
},
),