Scroll only one Widget inside Stack() in Flutter - flutter

I'm new to Flutter and I'm trying to build my first app.
I want my HomePage to have a small image on the top and its content on the rest of the page. When scrolling, I want the image to behave like a Parallax effect, staying fixed and the grey ClipPath() widget scrolling over it.
I've already tried a few approaches and I'm not sure if I'm using the correct elements on this page but this was the only way I managed to position everything the way I wanted so far.
However, even using SingleChildScrollView() as this the Container/ClipPath() father, I still can't scroll the page.
Could you please help me with that? Thank you all.
// hope.page.dart:
import 'package:flutter/material.dart';
import 'package:remind_md/ui/shared/clippers/content.clipper.dart';
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
toolbarHeight: 40,
actions: <Widget>[
// action button
IconButton(
icon: Icon(Icons.notifications, color: Colors.white),
onPressed: () {
},
),
// action button
IconButton(
icon: Icon(Icons.settings, color: Colors.white),
onPressed: () {
},
),
],
),
body: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xff82d9e8), Color(0xff27acc1)],
begin: Alignment.bottomLeft,
end: Alignment.topRight
)
),
child: OverflowBox(
alignment: Alignment(-0.75,-1.05),
maxHeight: MediaQuery.of(context).size.height * 2,
child: Image.asset(
'images/home_doctors.png',
scale: 1.05,
),
)
),
Positioned(
top: MediaQuery.of(context).size.height*0.2 ,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Container(
child: ClipPath(
clipper: ContentClipper(),
child: Container(
padding: EdgeInsets.only(top: 40),
width: MediaQuery.of(context).size.width,
color: Color(0xfff4f4f4),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
width: 200,
height: 100,
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(7)),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Stack(
children: <Widget>[
Positioned(
right: 3,
top: 0,
child: Opacity(
opacity: 0.2,
child: Image.asset('images/card_calendar.png', width: 100, height: 75)
),
),
Positioned(
top: 0,
left: 5,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'12 dias',
textAlign: TextAlign.left,
style: TextStyle(fontFamily: 'BrunoAce', fontSize: 26, color: Color(0xff27acc1))
),
Text(
'até próxima',
textAlign: TextAlign.left,
style: TextStyle(fontFamily: 'BrunoAce', fontSize: 18, color: Color(0xff27acc1))
),
Text(
'consulta.',
textAlign: TextAlign.justify,
style: TextStyle(fontFamily: 'BrunoAce', fontSize: 18, color: Color(0xff27acc1))
),
],
),
)
]
),
),
),
),
Container(
width: 200,
height: 100,
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(7)),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Stack(
children: <Widget>[
Positioned(
right: 3,
top: 0,
child: Opacity(
opacity: 0.2,
child: Image.asset('images/pill_case.png', width: 100, height: 75)
),
),
Positioned(
top: 0,
left: 5,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'31 dias',
textAlign: TextAlign.left,
style: TextStyle(fontFamily: 'BrunoAce', fontSize: 26, color: Color(0xff27acc1))
),
Text(
'até comprar',
textAlign: TextAlign.left,
style: TextStyle(fontFamily: 'BrunoAce', fontSize: 18, color: Color(0xff27acc1))
),
Text(
'medicamento.',
textAlign: TextAlign.justify,
style: TextStyle(fontFamily: 'BrunoAce', fontSize: 18, color: Color(0xff27acc1))
),
],
),
)
]
),
),
),
)
],
),
Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(7)),
child: Row(
children: <Widget>[
Container(
child: Image.asset('images/card_pills.png'),
height: 80,
width: 80,
decoration: BoxDecoration(
color: Color(0xfff47e71),
borderRadius: BorderRadius.all(Radius.circular(7))
),
)
],
),
),
Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(7)),
child: Row(
children: <Widget>[
Container(
child: Image.asset('images/card_stet_heart.png'),
height: 80,
width: 80,
decoration: BoxDecoration(
color: Color(0xff3865b9),
borderRadius: BorderRadius.all(Radius.circular(7))
),
)
],
),
),
Card(
elevation: 2,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(7)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text('Histórico', style: TextStyle(fontFamily: 'BrunoAce', fontSize: 24, color: Color(0xff27acc1), ) ),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset('images/list_credit_card.png'),
Text('1 - <MEDICAMENTO> - 19/08/2020', style: TextStyle(fontFamily: 'BrunoAce', fontSize: 16, color: Color(0xff27acc1) ) ),
],
),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset('images/list_credit_card.png'),
Text('1 - <MEDICAMENTO> - 19/08/2020', style: TextStyle(fontFamily: 'BrunoAce', fontSize: 16, color: Color(0xff27acc1) ) ),
],
),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset('images/list_pill.png'),
Text('30 - <MEDICAMENTO> - 19/08/2020', style: TextStyle(fontFamily: 'BrunoAce', fontSize: 16, color: Color(0xff27acc1) ) ),
],
),
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.asset('images/list_pill.png'),
Text('1 - <MEDICAMENTO> - 19/08/2020', style: TextStyle(fontFamily: 'BrunoAce', fontSize: 16, color: Color(0xff27acc1) ) ),
],
),
Divider()
],
),
),
)
],
)
)
),
),
),
),
]
),
);
}
}

Wrap the SingleChildScrollView widget with an expanded widget. It should do the work. Because for the singleChildScrollView to work, it does not some height and width to scroll. Hope it helps.

Related

How can i made this decoration?

Screen
Hello all, how can i make tis fade in ? between 2 container. I have a row with 3 columns and an another to columns.
This is my app :
class _FilmPageState extends State<FilmPage> {
final urlImage = "assets/images/Spider-Man No way home poster.jpg";
#override
Widget build(BuildContext context) => Scaffold(
drawer: NavigationMenu(),
// endDrawer: NavigationDrawerWidget(),
appBar: PreferredSize(
preferredSize: Size.fromHeight(270),
child: AppBar(
elevation: 0,
flexibleSpace: Image(
image: AssetImage(urlImage),
fit: BoxFit.cover,
),
),
),
body: Column(
children: [
FilmTitle(),
FilmSection(),
],
)
);
}
This is my film section, with the row, colums and containers :
Inside we have the details about the section, I want to know how can i make the border side decoration not full like a screen ?
class FilmSection extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
color: digital_blueb,
child: Column(
children: [
Row(
children: [
Column(
children: [
Container(
width: 70,
height: 125,
child: Center(
child: Text("85%", style: TextStyle(fontSize: 20, color: Colors.white)),
),
decoration: ShapeDecoration(
color: digital_blueb,
shape: CircleBorder(
side: BorderSide(
width: 5,
color: digital_green,
)
)
),
),
Container(
child: Center(
child: (Text("Note du public", style: TextStyle(color: Colors.grey[500], fontWeight: FontWeight.bold,fontSize: 15))
),
),
),
],
),
Column(
children: [
Container(
height: 110,
width: 50,
child: VerticalDivider(color: Colors.white),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(left: 10),
child: Column(
children: [
Text("2h30",style: TextStyle(color: Colors.grey[500], fontWeight: FontWeight.bold)),
],
),
),
SizedBox(height: 15),
Container(
margin: EdgeInsets.only(left: 10),
child: Column(
children: [
Text("15 Décembre 2021", style: TextStyle(color: Colors.grey[500], fontWeight: FontWeight.bold)),
],
),
),
SizedBox(height: 15),
Container(
margin: EdgeInsets.only(left: 10),
child: Column(
children: [
Text("Action/Aventure", style: TextStyle(color: Colors.grey[500], fontWeight: FontWeight.bold)),
],
),
),
SizedBox(height: 15),
Container(
margin: EdgeInsets.only(left: 10),
child: Column(
children: [
Text("Tous publics", style: TextStyle(color: Colors.grey[500], fontWeight: FontWeight.bold)),
],
),
),
],
),
],
),
Try this, in your FilmTitle(), Stack a gradient color container:
Stack(
children:[
AspectRatio(
ratio: 1,
child: image.Network(''),
),
AspectRatio(
ratio: 1,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [
0.1,
0.7,
0.9,
],
colors: [
Colors.transparent,
Colors.transparent,
digital_blueb,
],
)
),
),
],
),

what is equivalent of guidelines (constraint layout) in flutter?

I want to create view like image, the first view (blue view) is 30% of screen height
and the second view (red view) is center vertical of first view (15% of the first view from bottom to top, and 15% of the first view from bottom to bottom).
if in android XML constraint layout I can use guidelines to handle that, but in flutter what I can use to create like that view?
import 'package:flutter/material.dart';
import 'package:flutter_app2/custom_text.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => new _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
Card statsWidget() {
return new Card(
elevation: 1.5,
margin: EdgeInsets.only(bottom: 210.0, left: 20.0, right: 20.0),
color: Colors.white,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
verticalDirection: VerticalDirection.down,
children: <Widget>[
new Padding(
padding: EdgeInsets.all(20.0),
child: new Row(
children: <Widget>[
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.center,
child: new Text(
"Photos",
textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.grey,
fontSize: 16.0,
),
)),
new Align(
alignment: Alignment.center,
child: new Text(
"22k",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xff167F67),
),
)),
],
),
flex: 1,
),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.center,
child: new Text(
"Followers",
textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.grey,
fontSize: 16.0,
),
)),
new Align(
alignment: Alignment.center,
child: new Text(
"232k",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xff167F67),
),
)),
],
),
flex: 1,
),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Align(
alignment: Alignment.center,
child: new Text(
"Following",
textAlign: TextAlign.center,
style: new TextStyle(
color: Colors.grey, fontSize: 16.0),
)),
new Align(
alignment: Alignment.center,
child: new Text(
"332k",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xff167F67),
),
)),
],
),
flex: 1,
)
],
),
)
],
));
}
#override
build(BuildContext context) {
return new Material(
type: MaterialType.transparency,
child: new Stack(
children: [
new Column(
children: <Widget>[
headerWidget(),
bodyWidget(),
],
),
new Center(
child: statsWidget(),
),
],
));
}
Widget headerWidget() {
var header= new Expanded(
child: new Container(
decoration: new BoxDecoration(
color: const Color(0xff167F67),
),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Center(
child: new Container(
margin: EdgeInsets.only(bottom: 10.0),
height: 80.0,
width: 80.0,
decoration: new BoxDecoration(
color: const Color(0xff167F67),
image: new DecorationImage(
image: new NetworkImage(
"https://4.bp.blogspot.com/-QXHUYmKycZU/W-Vv9G01aAI/AAAAAAAAATg/eF1ArYpCo7Ukm1Qf-JJhwBw3rOMcj-h6wCEwYBhgL/s1600/logo.png"),
fit: BoxFit.cover,
),
border:
Border.all(color: Colors.white, width: 2.0),
borderRadius: new BorderRadius.all(
const Radius.circular(40.0)),
),
),
),
new Text(
"Developer Libs",
textAlign: TextAlign.center,
style: new TextStyle(
color: Color(0xffffffff),
),
)
],
),
),
flex: 1,
);
return header;
}
Widget bodyWidget() {
var bodyWidget=new Expanded(
child: new Container(
decoration: new BoxDecoration(
color: const Color(0xffffffff),
),
child: new Padding(
padding:
EdgeInsets.only(left: 50.0, right: 50.0, top: 50.0),
child: new Column(
children: <Widget>[
new CustomText(
label: "contact#developerlibs",
textColor: 0xff858585,
iconColor: 0xff167F67,
fontSize: 15.0,
icon: Icons.email)
.text(),
],
),
)),
flex: 2,
);
return bodyWidget;
}
}
I found this code and it's good but If I try in other phone resolution the second view is not center of first view. like below image
you can play with something like this :
LayoutBuilder(
builder: (context, constraints) {
final firstHeight = constraints.biggest.height * .3;
final secondHeight = 200.0;
return SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: firstHeight + secondHeight / 2,
child: Stack(
children: [
Positioned(
top: 0,
height: firstHeight,
left: 0,
right: 0,
child: Container(
color: Colors.blue,
),
),
Positioned(
top: firstHeight - secondHeight / 2,
left: 0,
height: secondHeight,
child: Container(
width: 200,
color: Colors.red,
),
),
],
),
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
Container(
height: 200,
margin: const EdgeInsets.only(
bottom: 8,
),
color: Colors.green,
),
],
),
);
},
)
result :
I think what you can use is wrap your image in an expanded widget and use its flex property. Flex basically ensures how much space a widget takes.So by default flex is set to 1. Hence wrap both your widgets with an expanded widget and set the flex property accordingly. I hope it solves your problem.

How to center text and prevent text from overflowing using Flutter

My UI currently looks like this:
I want to center the text in the middle of the space that is left over after the image is placed. However, I also want to make sure that my text does not overflow due to the size. How can I do that? My code is as follows:
Widget build(BuildContext context) {
return Card(
color: Theme.of(context).scaffoldBackgroundColor,
elevation: 0,
child: Column(
children: [
Divider(
thickness: 2,
color: Colors.white,
height: 0,
),
Row(
children: [
Container(
padding: EdgeInsets.all(0),
width: 100,
height: 100,
child: CircleAvatar(
radius: 50,
backgroundImage: NetworkImage(imageUrl),
),
),
Container(
padding: EdgeInsets.all(40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
alignment: Alignment.topCenter,
child: Text(
name,
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
),
Container(
alignment: Alignment.bottomLeft,
padding: EdgeInsets.all(15),
child: Text(
modalityText,
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
),
],
),
],
),
);
}
Here, this is one way of doing what you want
Widget build(BuildContext context) {
return Card(
color: Theme.of(context).scaffoldBackgroundColor,
elevation: 0,
child: Column(
children: [
Divider(
thickness: 2,
color: Colors.white,
height: 0,
),
Row(
children: [
Container(
padding: EdgeInsets.all(0),
width: 100,
height: 100,
child: CircleAvatar(
radius: 50,
backgroundImage: NetworkImage("imageUrl"),
),
),
Expanded(
child: Container(
padding: EdgeInsets.all(40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
alignment: Alignment.topCenter,
child: Text(
"name",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
),
Container(
alignment: Alignment.bottomLeft,
padding: EdgeInsets.all(15),
child: Text(
"modalityText",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
color: Colors.white,
),
),
),
],
),
),
),
],
),
],
),
);
}

SingleChildScrollView doesn't scroll screen with ListView.builder

I'm trying to get it so that all of the items in ListView.builder can be displayed on the screen and seen by scrolling. However, I think because the ListView.builder is in a stack, it is not allowing the whole screen to scroll. I don't want the ListView.builder to scroll on its own, I want only the whole page to be scrollable. Thanks in advance.
import 'sign_up_page.dart';
import 'package:intl/intl.dart';
import 'settings_page.dart';
import 'new_event_page.dart';
import 'event_settings_page.dart';
class HomeScreen extends StatefulWidget {
static const String id = 'home_screen';
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
#override
Widget build(BuildContext context) {
double width;
double height;
int mediumScreenSize = 800;
int largeScreenSize = 1000;
width = MediaQuery.of(context).size.width;
height = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: Color.fromRGBO(255, 255, 255, 1),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children:[
Container(
child: AspectRatio(
aspectRatio: mediumScreenSize < height ? 0.76 : 0.87,
),
decoration: BoxDecoration(
color: Color(0xff212a3d),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40), bottomRight: Radius.circular(40)
),
),
),
Container(
height: height,
child: Column(
children: [
AspectRatio(
aspectRatio: 10,
),
Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(width/35),
child: Text('Home',
style: TextStyle(
fontFamily: 'Chivo Bold',
fontSize: mediumScreenSize < height ? 22.0 : 21.0,
color: Colors.white,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: width/10),
child: ButtonTheme(
padding: EdgeInsets.all(0),
minWidth: width/10,
child: FlatButton(onPressed: () {
Navigator.pushNamed(context, SettingsPage.id);
},
child: Image.asset('images/gear.png', height: 22),
),
),
),
],
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SizedBox(
height: height/5,
),
Container(
padding: EdgeInsets.only(left: width/7.5),
//TO DO: replace fullName variable when user updates user information
child: Text('Welcome' + UserInformation.userStatus + ',' + '\n' + UserInformation.fullName, style: TextStyle(
fontFamily: 'Poppins SemiBold',
fontWeight: FontWeight.w600,
fontSize: mediumScreenSize < height ? 26.0 : 25.0,
letterSpacing: 0.5,
color: Colors.white,
),
),
),
],
),
AspectRatio(
aspectRatio: height > mediumScreenSize ? 4: 7,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: width/1.2,
child: AspectRatio(
aspectRatio: 6.5,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(28.0),
),
color: Color.fromRGBO(102, 161, 192, 1),
onPressed: () {
EventInformation.eventDate = DateFormat.yMMMMd().format(DateTime.now());
Navigator.pushNamed(context, NewEventPage.id);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(top: width * 0.015),
child: Image.asset(
'images/+.png',
height: width/16,
),
),
Text(
' Add new event',
style: TextStyle(
color: Colors.white,
fontFamily: 'Chivo Regular',
fontSize: mediumScreenSize < height ? 16.0 : 15.0,
),
),
],
),
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(top: width/15, bottom: width/40),
child: Container(
child: Text('My Events:', style: TextStyle(
fontFamily: 'Overpass SemiBold',
fontWeight: FontWeight.w600,
fontSize: mediumScreenSize < height ? 16.0 : 15.0,
letterSpacing: 1.0,
color: Colors.white,
),
),
),
),
],
),
UserInformation.events.length == 0 ? Container (
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
AspectRatio(
aspectRatio: height > mediumScreenSize ? 2.5: 4,
),
Text('No events listed', textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey, fontFamily: 'Chivo Bold', fontSize: mediumScreenSize < height ? 20.0 : 19.0),),
Text('\nAdd a new event by selecting the "+" button above', textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey, fontFamily: 'Chivo Regular'),),
],
),):
Expanded(
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: UserInformation.events.length,
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.only(bottom: width/20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
Navigator.pushNamed(context, EventSettingsPage.id);
},
child: Container(width: width/1.2,
height: width/5.5,
decoration: new BoxDecoration(
color: Color(0xffffffff),
borderRadius: BorderRadius.circular(15),
boxShadow: [BoxShadow(
color: Color(0x15525768),
offset: Offset(-12,15),
blurRadius: 22,
spreadRadius: 0
),BoxShadow(
color: Color(0x0c525768),
offset: Offset(12,-15),
blurRadius: 22,
spreadRadius: 0
) ],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
padding: EdgeInsets.only(left: width/10),
child: Text(UserInformation.events[index],
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color(0xff212a3d),
fontFamily: 'Overpass Bold',
fontSize: mediumScreenSize < height ? 16.0 : 15.0,
),
),
),
Container(
padding: EdgeInsets.only(right: width/15),
child: new Image.asset(
'images/mini_arrow.png',
height: 30.0,
),
),
],
),
),
),
],
),
);
}
),
),
],
),
),
],
),
],
),
),
);
}
}
add this two line in your listview :-ListView.builder( physics: NeverScrollableScrollPhysics(),
child: Scaffold(
backgroundColor: Color.fromRGBO(255, 255, 255, 1),
body: SingleChildScrollView(
physics: ClampingScrollPhysics(),
child: Column(
children: <Widget>[
Stack(
children:[
Container(
height: mediumScreenSize < height ? width/0.8 : width/0.8,
width: double.infinity,
decoration: BoxDecoration(
color: Color(0xff212a3d),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40), bottomRight: Radius.circular(40)
),
),
),
Column(
children: [
Stack(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(top: width/9),
child: Text('Home',
style: TextStyle(
fontFamily: 'Chivo Bold',
fontSize: mediumScreenSize < height ? 22.0 : 21.0,
color: Colors.white,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: width/13),
padding: EdgeInsets.only(right: width/10),
child: ButtonTheme(
padding: EdgeInsets.all(0),
minWidth: width/10,
child: FlatButton(onPressed: () {
Navigator.pushNamed(context, SettingsPage.id);
},
child: Image.asset('images/gear.png', height: 22),
),
),
),
],
),
],
),
SizedBox(
height: width/4,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
padding: EdgeInsets.only(left: width/7.5),
child: Text('Welcome' + UserInformation.userStatus + ',' + '\n' + UserInformation.fullName, style: TextStyle(
fontFamily: 'Poppins SemiBold',
fontWeight: FontWeight.w600,
fontSize: mediumScreenSize < height ? 26.0 : 25.0,
letterSpacing: 0.5,
color: Colors.white,
),
),
),
],
),
SizedBox(
height: width/4.75,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: width/1.2,
child: AspectRatio(
aspectRatio: 6.5,
child: FlatButton(
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(28.0),
),
color: Color.fromRGBO(102, 161, 192, 1),
onPressed: () {
EventInformation.displayEventDate = DateFormat.yMMMMd().format(DateTime.now());
Navigator.pushNamed(context, NewEventPage.id);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(top: width * 0.015),
child: Image.asset(
'images/+.png',
height: width/16,
),
),
Text(
' Add new event',
style: TextStyle(
color: Colors.white,
fontFamily: 'Chivo Regular',
fontSize: mediumScreenSize < height ? 16.0 : 15.0,
),
),
],
),
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(top: width/15),
child: Container(
child: Text('My Events:', style: TextStyle(
fontFamily: 'Overpass SemiBold',
fontWeight: FontWeight.w600,
fontSize: mediumScreenSize < height ? 16.0 : 15.0,
letterSpacing: 1.0,
color: Colors.white,
),
),
),
),
],
),
],
),
Padding(
padding: EdgeInsets.only(top: width/ 0.9),
child: UserInformation.events.length == 0 ? Container (
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
AspectRatio(
aspectRatio: height > mediumScreenSize ? 2.5: 4,
),
Text('No events listed', textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey, fontFamily: 'Chivo Bold', fontSize: mediumScreenSize < height ? 20.0 : 19.0),),
Text('\nAdd a new event by selecting the "+" button above', textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey, fontFamily: 'Chivo Regular'),),
],
),):
ListView.builder(
padding: EdgeInsets.only(top: width/20, bottom: width/20),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: UserInformation.events.length,
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.only(bottom: width/20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
Navigator.pushNamed(context, EventSettingsPage.id);
},
child: Container(width: width/1.2,
height: width/5.5,
decoration: new BoxDecoration(
color: Color(0xffffffff),
borderRadius: BorderRadius.circular(15),
boxShadow: [BoxShadow(
color: Color(0x15525768),
offset: Offset(-12,15),
blurRadius: 22,
spreadRadius: 0
),BoxShadow(
color: Color(0x0c525768),
offset: Offset(12,-15),
blurRadius: 22,
spreadRadius: 0
) ],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
padding: EdgeInsets.only(left: width/10),
child: Text(UserInformation.events[index],
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color(0xff212a3d),
fontFamily: 'Overpass Bold',
fontSize: mediumScreenSize < height ? 16.0 : 15.0,
),
),
),
Container(
padding: EdgeInsets.only(right: width/15),
child: new Image.asset(
'images/mini_arrow.png',
height: 30.0,
),
),
],
),
),
),
],
),
);
}
),
),
],
),
],
),
),
),
This is the way I figured out how to do it without any hardcoded height inputs. The problem was the ListView.builder was in a Container with no specified height.
Inside ListView.builder : use property physics and give NeverScrollableScrollPhysics() as a value ex:
physics: NeverScrollableScrollPhysics(),

SingleChildScrollView not working in Column

I am building an app facing a singleChildScrollView not able to scroll the page the text has been cut from bottom after the contact button i want to scroll the page but but spending so much time can't fix problem.
enter image description here
enter code here
import 'package:flutter/material.dart';
class DetailScreen extends StatefulWidget {
final electricain;
DetailScreen(this.electricain);
#override
_DetailScreenState createState() => _DetailScreenState();
}
class _DetailScreenState extends State<DetailScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height / 3 + 20,
width: MediaQuery.of(context).size.width,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.asset(
'assets/images/detail_bg.jpg',
fit: BoxFit.fill,
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: Colors.purple.withOpacity(0.1),
),
],
),
),
Positioned(
top: 50,
left: 20,
child: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
onPressed: () {
Navigator.pop(context);
},
),
),
Positioned(
top: MediaQuery.of(context).size.height / 3.6 - 40,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
),
),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 130,
),
Text(
'Description',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
SizedBox(
height: 10,
),
Text(
'${widget.electricain['desc']}',
style: TextStyle(
color: Colors.grey,
),
textAlign: TextAlign.justify,
),
SizedBox(
height: 10,
),
Text(
"\n Services List",
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
'${widget.electricain['services']}',
style: TextStyle(
color: Colors.grey,
),
),
SizedBox(height: 30),
MaterialButton(
onPressed: () {},
color: Colors.orange,
child: Text(
"Contact",
style: TextStyle(
color: Colors.white, fontSize: 16.0),
),
),
SizedBox(height: 10),
Text(
'${widget.electricain['services']}',
style: TextStyle(
color: Colors.grey,
),
),
],
),
),
),
),
),
),
Positioned(
top: MediaQuery.of(context).size.height / 3 - 90,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 3 - 20,
height: MediaQuery.of(context).size.height / 6 + 20,
decoration: BoxDecoration(
color: widget.electricain['bgColor'],
borderRadius: BorderRadius.circular(20),
),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Positioned(
top: 10,
right: -25,
child: Image.asset(
widget.electricain['imgUrl'],
scale: 1.7,
),
),
],
),
),
SizedBox(
width: 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.electricain['electricainName'],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
SizedBox(
height: 5,
),
Text(
widget.electricain['shopName'],
style: TextStyle(
fontWeight: FontWeight.w300,
color: Colors.grey,
),
),
SizedBox(
height: 10,
),
Row(
children: <Widget>[
Icon(
Icons.star,
size: 16,
color: Color(0xffFF8573),
),
SizedBox(width: 5),
Text(
widget.electricain['rating'],
style: TextStyle(
color: Color(0xffFF8573),
),
),
SizedBox(
width: 5,
),
Text(
'(${widget.electricain['rateAmount']})',
style: TextStyle(
color: Colors.grey,
),
),
],
)
],
),
],
),
),
),
],
),
),
);
}
}
try this:
LayoutBuilder(builder: (context, constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: constraints.maxWidth, minHeight: constraints.maxHeight),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//your children here
]
),
)
)
);
})
IntrinsicHeight class
A widget that sizes its child to the child's intrinsic height.
This class is useful, for example, when unlimited height is available and you would like a child that would otherwise attempt to expand infinitely to instead size itself to a more reasonable height.