my screen is not getting scrollable. I am using background picture and i want it to be scrollable as well because when i used single child scrollable widget as a parent of container after background picture, it worked by back ground image didn't scrolled.
Stack(children: [
const BackgroundPicture(),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 30,
vertical: 50,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset(
'assets/Frame.png',
),
const SizedBox(
height: 60,
),
const SizedBox(
width: 400,
child: Text(
'Where would you like to start',
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 40,
color: Colors.black,
fontWeight: FontWeight.w100),
),
),
const SizedBox(
height: 50,
),
Center(
child: Container(
height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width * 0.8,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color(0xffF3F2F2),
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.08),
blurRadius: 20,
spreadRadius: 5,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
),
],
),
)
]);
You can just wrap your Stack in a SingleChindScrollView Widget, this widgets allows the scroll.
SingleChildScrollView(
child: Stack(
children: [
const BackgroundPicture(),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 30,
vertical: 200,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset(
'assets/Frame.png',
),
const SizedBox(
height: 60,
),
const SizedBox(
width: 400,
child: Text(
'Where would you like to start',
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 40,
color: Colors.black,
fontWeight: FontWeight.w100),
),
),
const SizedBox(
height: 50,
),
Center(
child: Container(
height: MediaQuery.of(context).size.height * 0.6,
width: MediaQuery.of(context).size.width * 0.8,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: const Color(0xffF3F2F2),
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.08),
blurRadius: 20,
spreadRadius: 5,
offset: Offset(0, 3), // changes position of shadow
),
],
),
),
),
],
),
)
],
),
);
Related
I am using the following code in my Flutter application:
Row(
children: [ _loading ? CircularProgressIndicator():
//if(Text(data_snap['icon_spec'].toString()) == "abc"){
new Container(
width: SizeConfig.safeBlockHorizontal * 24,
alignment: Alignment.centerLeft,
child: Text(
'Test: ',
style: new TextStyle(
fontSize: SizeConfig.blockSizeHorizontal * 4, color: Colors.grey[750],
fontWeight: FontWeight.bold),
)),
new Container(
width: SizeConfig.safeBlockHorizontal * 10,
alignment: Alignment.centerLeft,
child: new IconTheme(
data: new IconThemeData(
color: Colors.yellow),
child: new Icon(Icons.trending_neutral_rounded),
),
),
new Container(
width: SizeConfig.safeBlockHorizontal * 16,
alignment: Alignment.centerLeft,
child: Text(
'Text: ',
style: new TextStyle(
fontSize: SizeConfig.blockSizeHorizontal * 4, color: Colors.grey[750],
fontWeight: FontWeight.bold),
)),
new Container(
width: SizeConfig.safeBlockHorizontal * 21,
child: Text(data_snap['abc'].toStringAsFixed(2)),
),
],
),
Depending on the "icon_spec" from Firebasedata I would like to change the Icon and its color. For example: if "icon_spec = abc", the Icon should be a yellow trending_neutral_rounded. When "icon_spec = def", the Icon should be a red trending_down_rounded.
I tried it with the commented line in the code above but it doesn't work inside this children.
How can I change the Icon and its color depending on the value from Firebase?
Container(
width: SizeConfig.safeBlockHorizontal * 10,
alignment: Alignment.centerLeft,
child: IconTheme(
data:data_snap['icon_spec'].toString() == "abc" ?
IconThemeData(
color: Colors.yellow),
child: Icon(Icons.trending_neutral_rounded),
):data_snap['icon_spec'].toString() == "def" ? IconThemeData(
color: Colors.yellow),
child: Icon(Icons.trending_neutral_rounded),
):IconThemeData(),
),
can't able to scroll how to set height of gridView Builder according to Random list items we are getting?
i want my GridView to be scrolled by SingleChildScrollView as i want to set my gridView to non Scrollable!! and set GridView's height according to the items.length(mealItem.length // given in code)
SingleChildScrollView(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 14),
decoration: BoxDecoration(border: Border.all()),
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SizedBox(height: 10),
Container(
padding: EdgeInsets.only(left: 14, right: 14),
child: Text(
"منتجات الالبان",
style: TextStyle(color: Colors.black, fontSize: 18),
),
),
SizedBox(height: 10),
// filter button
Container(
height: 45,
width: 351,
padding: EdgeInsets.only(left: 14, right: 14),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7),
color: Colors.black),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Image.asset("assets/filter.png",
height: 17, width: 16, color: Colors.white),
Text("تصنيف", style: TextStyle(color: Colors.white))
],
),
),
// over
SizedBox(height: 10),
Container(
padding: EdgeInsets.only(right: 12),
child: Text(
"الالبان",
style: TextStyle(fontSize: 16),
),
),
SizedBox(height: 10),
// meal Item of particular category
Container(
height: MediaQuery.of(context).size.height,
child: GridView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 4.5,
crossAxisSpacing: 18,
mainAxisSpacing: 24,
),
itemBuilder: (context, index) {
return Container(
decoration: BoxDecoration(border: Border.all()),
child: Card(
elevation: 4,
),
);
},
itemCount: mealList.length,
))
],
),
),
),
I had a problem with my project, i'm trying make container with box shadow on bottom. below that container i want make to new container but they are some separate space between container, i think its because box shadow. so the question is how to make they connect ith no space but the shadow still visible.
pic
here my code :
return Scaffold(
body: SafeArea(
child: Container(
child: ListView(
physics: BouncingScrollPhysics(),
children: <Widget>[
Container(
child: Padding(
padding: const EdgeInsets.all(0.0),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.zero,
topRight: Radius.zero,
),
child: Container(
height: 70.0,
margin: const EdgeInsets.only(
bottom: 6.0), //Same as `blurRadius` i guess
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(5.5),
bottomRight: Radius.circular(5.5),
topLeft: Radius.zero,
topRight: Radius.zero,
),
color: kDarkGreenColor,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 6.0,
),
],
),
child: ListView.builder(
padding: EdgeInsets.only(left: 10, right: 5),
itemCount: planticos.length,
physics: BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.only(right: 15, bottom: 6),
height: 40,
width: 70,
decoration: BoxDecoration(
color: kMainColor.withOpacity(0),
image: DecorationImage(
image: AssetImage(planticos[index].image),
),
),
);
}),
),
),
),
),
Container(
margin: EdgeInsets.only(top: 0),
height: 200,
color: kMainColor,
),
],
),
),
),
);
}
use stack.
2nd Container will be visible over 1st Container.
for example...
Stack(
children: <Widget>[
Container(
height: 400,
decoration: BoxDecoration(
color: Colors.green,
),
),
Container(
height: 200,
decoration: BoxDecoration(
color: Colors.green,
boxShadow: [
BoxShadow(
color: Colors.red,
offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 6.0,
),
],
),
),
],
),
You should use the stack widget, see this example:
Stack(
children:[
Container() //which you wanna be under the shadow.
Container() //which you wanna make it's shadow visible.
]
)
Tip: Use Positioned() under the stack to specify the position of containers.
I just started learning Dart and Flutter development and have been playing with BoxShadow.
As you can see in the image below, the shadow for the Bar, Boo and Faz cards are cutoff while that for the text box shows up.
How do I ensure the shadows for the cards show up correctly?
Here's my code:
import 'package:flutter/material.dart';
import 'package:reminder_app/constants.dart';
class Body extends StatelessWidget {
Widget _buildBanner(size) {
return Container(
height: size.height * 0.7,
decoration: BoxDecoration(
color: kPrimaryColor,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(36),
bottomRight: Radius.circular(36),
),
),
);
}
Widget _buildCard(text) {
return Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.teal[200],
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
offset: Offset(10, 10),
blurRadius: 25,
color: Colors.black.withOpacity(
0.75,
),
),
],
),
child: Text(text),
);
}
Widget _buildCardGrid() {
return Expanded(
child: GridView.count(
primary: false,
padding: EdgeInsets.symmetric(
vertical: kDefaultPadding * 1.5,
),
crossAxisSpacing: 20,
mainAxisSpacing: 20,
crossAxisCount: 2,
children: <Widget>[
_buildCard("Foo"),
_buildCard("Bar"),
_buildCard("Baz"),
_buildCard("Boo"),
_buildCard("Far"),
_buildCard("Faz"),
],
),
);
}
Widget _buildInputBox() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
offset: Offset(10, 10),
blurRadius: 25,
color: Colors.black.withOpacity(
0.75,
),
),
],
),
height: 55,
child: TextField(
decoration: InputDecoration(
hintText: "Text Here",
hintStyle: TextStyle(
color: kPrimaryColor.withOpacity(
0.5,
),
),
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
),
),
);
}
Widget _buildInteractionContainers(size) {
return Positioned(
child: Container(
margin: EdgeInsets.symmetric(
horizontal: kDefaultPadding * 2,
),
width: size.width,
child: Column(
children: [
_buildInputBox(),
_buildCardGrid(),
],
),
),
);
}
Widget _buildBody(size) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: size.height * 0.7,
child: Stack(
children: <Widget>[
_buildBanner(size),
_buildInteractionContainers(size),
],
),
),
],
),
);
}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return _buildBody(size);
}
}
Bar, Boo and Faz's shadows are cutoff while the shadow for the text box shows up
Edit [Answer]: I was able to fix this by adding clipBehavior: Clip.none to GridView to prevent shadow clipping.
Please try this code, To How to prevent box-shadow from being cut off?
If the box-shadow is muted, make sure that
overflow: visible
Is set to all div tags that contain your element.
I hope this information will be useful to you.
Thank you.
Hi I have a stream builder that lists containers with a button to count down and when the counter hits zero I wanted to hide that single container from the list I can’t figure out how to, if anyone does please help
bool visibility = true;
Widget _dataList() {
if (data != null) {
return StreamBuilder(
stream: data,
builder: (context, snapshot) {
return ListView.builder(
itemCount: snapshot.data.documents.length,
padding: EdgeInsets.all(5.0),
itemBuilder: (context, i) {
return visibility == true
? new Container(
child: Padding(
padding: EdgeInsets.only(top: 5, right: 5, left: 5),
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 9,
color:
Theme.of(context).cardColor.withOpacity(.95),
shadowColor:
Theme.of(context).accentColor.withOpacity(.5),
child: Container(
padding: EdgeInsets.only(
bottom: 10, right: 10, left: 10, top: 15),
height: 210,
decoration: BoxDecoration(
color: Color(0xFF0B0F1B),
borderRadius: BorderRadius.circular(20),
border: Border.all(
width: 1,
color: Colors.grey.withOpacity(0.5))),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
'Number Of Participants :-' +
snapshot.data.documents[i]
.data['numberOfParticipants'],
style: TextStyle(
color: Colors.white, fontSize: 15),
),
),
Padding(
padding: const EdgeInsets.only(top: 7.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 40,
),
Material(
borderRadius:
BorderRadius.circular(20),
elevation: 26,
color: Color(0xFF0B0F1B),
child: Container(
height: 30,
width: 120,
decoration: BoxDecoration(
color: Color(0xFF0B0F1B),
borderRadius:
BorderRadius.circular(20),
border: Border.all(
width: 1,
color: Colors.grey
.withOpacity(0.5))),
child: InkWell(
splashColor: Colors.redAccent,
borderRadius:
BorderRadius.circular(20),
child: Center(
child: Text(
'View',
style: TextStyle(
color: Color(0xFFC77AF3),
fontSize: 18),
)),
onTap: () {
int currentval = int.parse(
snapshot.data.documents[i]
.data[
'numberOfParticipants']);
setState(
() {
currentval--;
snapshot.data.documents[i]
.data[
'numberOfParticipants'] =
currentval.toString();
if (currentval == 0) {
visibility = false;
}
},
);
},
),
),
),
SizedBox(
width: 85,
),
Material(
borderRadius:
BorderRadius.circular(20),
elevation: 26,
color: Color(0xFF0B0F1B),
child: Container(
height: 30,
width: 120,
decoration: BoxDecoration(
color: Color(0xFF0B0F1B),
borderRadius:
BorderRadius.circular(20),
border: Border.all(
width: 1,
color: Colors.grey
.withOpacity(0.5))),
child: InkWell(
splashColor: Colors.greenAccent,
borderRadius:
BorderRadius.circular(20),
child: Center(
child: Text(
'Join',
style: TextStyle(
color: Colors.greenAccent,
fontSize: 18),
)),
onTap: () {
setState(
() {},
);
},
),
),
),
],
),
),
],
),
),
),
),
)
: new Container();
},
);
});
} else {
return Center(child: Text('Nothing yet'));
}
}
this is my code i tried to accomplish the visibility by an empty container because i don't want it to hold a place but the problem is it hides all other containers with it the whole list goes invisible
You can use Opacity with an opacity: of 0.0 to draw make an element hidden but still occupy space.
To make it not occupy space, replace it with an empty Container().
EDIT: To wrap it in an Opacity object, do the following:
new Opacity(opacity: 0.0, child: new Padding(
padding: const EdgeInsets.only(
left: 16.0,
),
child: new Icon(pencil, color: CupertinoColors.activeBlue),
))
Google Developers quick tutorial on Opacity: https://youtu.be/9hltevOHQBw
you can also try
Visibility(
visible: false,
child: child
)
);