How to show circularprogressindicator along with bottomsheet in flutter? - flutter

i am using bottomsheet in my code and due to that it is not showing my circularprogressindicator when isLoading is true but else part of ternary operator is working perfectly. Is there anyother way to do that. Or where i am doing wrong in the code?
(isLoading==true) ? Center(
child: Container(
height: 24,
width: 24,
child: CircularProgressIndicator(
backgroundColor: CommonColors.primaryColor,
strokeWidth: 1,
),
),
)
:
Column(
children: <Widget>[
Expanded(
child: ListView.separated(
itemCount: clist.cartlist.length,
itemBuilder: (BuildContext context, int index) {
return _buildCartProduct(index);
},
separatorBuilder: (context, index) {
return Divider(
color: Colors.grey[300],
);
},
),
),
SizedBox(
height: 80,
)
],
),
bottomSheet: isLoading?Container():Container(
height: 80.0,
color: CommonColors.secondaryBackgroundColor,
child: Column(crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(margin: EdgeInsets.symmetric(horizontal: 16),child:
Text('Total: \$${clist.getSubTotal()}',
style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),)),
Expanded(
child: FlatButton(onPressed: (){},
color: CommonColors.primaryColor,
child: Row(mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'PLACE',
style: TextStyle(
color: CommonColors.secondaryBackgroundColor,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
),

in this part you're showing an empty container if loading
bottomSheet: isLoading?Container():Container(
so change it to be your CircularProgressIndicator
bottomSheet: isLoading ? CircularProgressIndicator():Container(

Related

How to fill a second container color?

I have this design:
And I want that the bottom of the container also have a pink color, something like this:
This is my code:
LayoutBuilder(
builder: (context, constraints) {
return Scaffold(
backgroundColor: Color(0xffF6F6F6),
body: TextSelectionTheme(
data: TextSelectionTheme.of(context).copyWith(
selectionColor: Color(0xffD7D7D7),
cursorColor: Color(0xff3B3B3B),
selectionHandleColor: Color(0xffD7D7D7),
),
child: Center(
child: Container(
height: double.maxFinite,
width: double.maxFinite,
decoration: BoxDecoration(
color: Color(0xffF6F6F6),
borderRadius: BorderRadius.all(
Radius.circular(0.0),
),
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: TextSpan(
style: GoogleFonts.questrial(),
children: [
WidgetSpan(
child: Icon(FontAwesomeIcons.checkDouble,
size: 40,
color: Color(0xffD7D7D7)),
),
],
),
),
RichText(
text: TextSpan(
style: GoogleFonts.questrial(),
children: [
WidgetSpan(
child: GestureDetector(
onTap: () {
showDialog(
context: context,
barrierColor: Colors.transparent,
builder: (ctx) => HomePagePomodoroTimer());
},
child: Icon(FontAwesomeIcons.squareXmark,
size: 40,
color: Color(0xff3B3B3B),),
),
),
],
),
),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Container(
decoration: BoxDecoration(
color: Color(0xffF4CFDD),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(50, 30, 50, 0),
child: Column(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"We send you an Email",
style: TextStyle(
fontSize: 20,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff3B3B3B),
),
),
],
),
SizedBox(height: 50,),
const Center(
child: Text(
"Please, check your Email inbox to log in and start using Pomoworko",
style: TextStyle(
fontSize: 20,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
color: Color(0xff3B3B3B),
),
),
),
Divider(color: Color(0xff3B3B3B)),
SizedBox(height: 40,),
const SizedBox(height: 360,
child: RiveAnimation.asset('letter_and_knife.riv',
fit: BoxFit.cover
),),
],
),
),
),
),
],
)
],
),
),
),
),
),
);
}
)
If I add this piece of code to the pink container:
Center(
child: Container(
height: double.maxFinite,
decoration: BoxDecoration(
color: Color(0xffF4CFDD), //pink color
),
I got this:
How to solve this issue?
It is possible to add a second container at the same time or not?
Thank you in advance
The problem is that you are using height: double.maxFinite with returns constant value of 1.7976931348623157e+308, in that case you want the size of your current widget parent context simple use MediaQuery.of(context).size.height
the code should look like this:
Center(
child: Container(
height: MediaQuery.of(context).size.height,
decoration: const BoxDecoration(
color: Color(0xffF4CFDD),
),
Consider giving the two children equal height or height you would want them to have from the constraints using SizedBox or Container like below.
LayoutBuilder(
builder: (context, constraints) {
return Column(
children: [
Container(
height: constraints.maxHeight/2, width: double.infinity, color: Colors.red,
),
Container(
height: constraints.maxHeight/2, width: double.infinity, color: Colors.red,
),
]
);
});
This way now you can move the children you want inside those containers.
Note: SingleChildScrollView does not work with infinite constraints children like Column on infinite height, consider sizing them or setting MainAxisSize.min or Flexible instead of constraints.

How to use Wrap widget inside column widget in flutter

I want to display items in a row using wrap widget, my code stack look like this
column>padding>wrap
and its output is this
i want them i row like in this tutorial
here is the code:
customExpansionTile(context, "Token Distribution Time", true,
Icon(Icons.info_rounded, color: HexColor("#5344ed")), <Widget>[
SizedBox10(),
Container(
// padding: EdgeInsets.only(right: 70),
child: Row(
children: [
Expanded(
child: SizedBox(
child: ListTile(
//font change
title: ListView.builder(
itemCount: checkBoxListTileModel.length,
itemBuilder: (BuildContext context, int index) {
return new Card(
child: new Container(
padding: new EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
new CheckboxListTile(
controlAffinity:
ListTileControlAffinity.leading,
activeColor: HexColor("#5344ed"),
dense: true,
//font change
title: new Text(
checkBoxListTileModel[index].title,
value: checkBoxListTileModel[index]
.isCheck,
secondary: Padding(
padding: EdgeInsets.only(left: 1),
child: Container(
child:
checkBoxListTileModel[index].isCheck ==true?
Container(
child: TextButton(
onPressed: () {
_getSelectedRowInfo(
checkBoxListTileModel[index].title);
},
child: Center(
child: Text(
"Pick time",),
),
)
: null),
),
onChanged: (bool? val) {
itemChange1(val!, index);
}),
Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 160, 0),
//here i am using wrap widget
child: Wrap(
children:[
Container(
child:checkBoxListTileModel[index]
.isCheck? Tags(
itemCount: _timingTagsList.length, // required
itemBuilder: (int index){
final item = _timingTagsList[index];
return ItemTags(
key: Key(index.toString()),
color:HexColor("#5344ed"),
index: index, // required
title: _timingTagsList[0],
textStyle: TextStyle( fontSize: 14, ),
combine: ItemTagsCombine.withTextBefore,
removeButton: ItemTagsRemoveButton(
onRemoved: (){
setState(() {
_timingTagsList.removeAt(index);
});
return true;
},
),
onPressed: (item) => print(item),
onLongPressed: (item) => print(item),
);
},):Padding(
padding: const EdgeInsets.only(left: 70),
child:
Row(crossAxisAlignment: CrossAxisAlignment.center, children: []))
),
]),
)]),
),
);
}),
))),
SizedBox(
width: 10,
),
],
))
User direction in Horizontal
Wrap(
direction:Axis.horizontal,
children:[
//.....
]
)
Try below code hope its helpful to you refer Wrap widget here
Wrap(
// direction: Axis.vertical,
children: <Widget>[
Container(
color: Colors.blue,
width: 100,
height: 100,
child: Center(
child: Text(
"W1",
textScaleFactor: 2.5,
),
),
),
Container(
color: Colors.red,
width: 100,
height: 100,
child: Center(
child: Text(
"W2",
textScaleFactor: 2.5,
),
),
),
Container(
color: Colors.teal,
width: 100,
height: 100,
child: Center(
child: Text(
"W3",
textScaleFactor: 2.5,
),
),
),
Container(
color: Colors.indigo,
width: 100,
height: 100,
child: Center(
child: Text(
"W4",
textScaleFactor: 2.5,
),
),
),
Container(
color: Colors.orange,
width: 100,
height: 100,
child: Center(
child: Text(
"W5",
textScaleFactor: 2.5,
),
),
),
],
)
Your result screen horizontal Axis direction ->
Your Screen vertical Axis Direction->

Error:RenderBox was not laid out: NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

i am having problem using SingleChildScrollView in this way, i dont no what is wrong, i keep getting this error.
If add the SingleChildScrollView the page will be blank(will not show all the widget)but if i remove the SingleChildScrollView, the page will show.
RenderBox was not laid out: RenderPadding#583c0 relayoutBoundary=up1
NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart': Failed assertion: line 1929
pos 12: 'hasSize
The relevant error-causing widget was Scaffold
Scaffold:file:///Users/mac/Documents/Uneleap-Platform-master/lib/screens/Pages/forum/forum.dart:25:12
here is the code
SafeArea(
minimum: EdgeInsets.only(left: 25.0, right: 20.0, top: 10.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
WidgetForum(
details: 'The Get Is Not Geting together ?',
name: 'Nina Simon',
url: 'assets/dashboard_pic.png',
),
SizedBox(
height: 5,
),
WidgetForum(
details:
'''Notes is designed for whatever’s on your mind.\nJot down your thoughts. Download Notes.\nThere is something wonderful in writing. \nThe Get Is Not Getting Together?''',
name: 'James Nugar',
url: 'assets/dashboard_pic.png',
),
Text(
'Topics',
style: TextStyle(
fontSize: 35,
),
),
Expanded(
child: ListView.separated(
scrollDirection: Axis.horizontal,
separatorBuilder: (_, inedex) => SizedBox(
width: 20,
),
itemCount: topics.length,
itemBuilder: (context, index) {
return Container(
height: 50,
width: 100,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(15),
image: DecorationImage(
image: AssetImage('assets/saved_2.png'),
fit: BoxFit.fill,
),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(
topics[index].schoolNmae!,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
)
],
),
);
}),
),
WidgetForum(
details:
'''Notes is designed for whatever’s on your mind.\nJot down your thoughts. Download Notes.\nThere is something wonderful in writing. \nThe Get Is Not Getting Together?''',
name: 'Sam Ajayi',
url: 'assets/dashboard_pic.png',
),
],
),
),
),
// bottomSheet:
floatingActionButton: FloatingActionButton(
onPressed: () {
Scaffold.of(context).showBottomSheet<void>((BuildContext context) {
return Container(
height: 250,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 50,
horizontal: 15.0,
),
child: Column(
children: [
Row(
children: [
Icon(
CustomIcons.answers_forum,
color: Colors.grey,
),
SizedBox(
width: 10,
),
Text(
'Post',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
Padding(
padding: const EdgeInsets.only(right: 120.0),
child: Divider(
thickness: 2,
color: Colors.white,
),
),
Row(
children: [
Icon(
CustomIcons.create_forum,
color: Colors.grey,
),
SizedBox(
width: 10,
),
Text(
'Create Forum',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
Align(
alignment: Alignment.bottomRight,
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
height: 70,
width: 70,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
),
child: Center(
child: Icon(Icons.add),
),
),
),
)
],
),
),
);
});
},
child: Icon(Icons.add),
),
);
}
}
class WidgetForum extends StatefulWidget {
final String? name;
final String? details;
final String? url;
WidgetForum(
{Key? key, required this.name, required this.details, required this.url})
: super(key: key);
#override
_WidgetForumState createState() => _WidgetForumState();
}
class _WidgetForumState extends State<WidgetForum> {
#override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
height: 50,
width: 50,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.url!),
fit: BoxFit.fill,
),
),
),
SizedBox(
width: 5,
),
Text(
widget.name!,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
)
],
),
PopupMenuButton(
color: Colors.black,
offset: Offset(0, 40),
itemBuilder: (_) => <PopupMenuItem<String>>[
new PopupMenuItem<String>(
child: Center(
child: Text(
'Fellow',
style: TextStyle(
color: Colors.white,
),
),
),
),
new PopupMenuItem<String>(
child: Center(
child: Text(
'Block',
style: TextStyle(
color: Colors.white,
),
),
),
),
new PopupMenuItem<String>(
child: Center(
child: Text(
'Report',
style: TextStyle(
color: Colors.white,
),
),
),
),
],
child: Container(
height: 20,
width: 20,
child: SvgPicture.asset('assets/library_pre.svg'),
),
),
],
),
SizedBox(height: 18),
Text(
widget.details!,
style: TextStyle(fontSize: 15),
),
SizedBox(height: 18),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
CustomIcons.icons8_up_2_11,
color: Colors.red,
),
Text('36'),
Icon(
CustomIcons.icons8_down,
color: Colors.grey,
),
Icon(
CustomIcons.answers_forum,
color: Colors.grey,
),
Text('3')
],
),
Text('Sep 2, 2020')
],
),
Divider(
thickness: 1,
)
],
);
}
}
You cannot use Expanded in Column if it has a parent SingleChildScrollView because When you use column it tries to be in screen height and when use expanded inside, The column will allocate remaining space to the child of the expanded widget, Now if you use SingleChildScrollView It will try to expand(by direction, vertically in your case) as long as possible but as you're using the Expanded which tries to take remaining space, So it goes infinite thus throws that error,
So Either remove SingleChildScrollView and use Column and expanded or remove the Expanded and Use SingleChildScrollView also make sure ShrinkWrap in ListView to true.
Column(
children: [
Text(
'Hello, World!',
style: Theme.of(context).textTheme.headline4,
),
Container(
height: 50,
width: 200,
color: Colors.amber,
child: const Text('Random widget'),
),
Expanded(
child: ListView.separated(
shrinkWrap: true,
itemCount: 20,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (context, int index) {
return ListTile(
title: Text('Item at $index'),
);
},
),
)
],
);
Or to Scroll all the widgets You can do using SingleChildScrollView
Remove the Expanded widget here.
SingleChildScrollView(
child: Column(
children: [
Text(
'Hello, World!',
style: Theme.of(context).textTheme.headline4,
),
Container(
height: 50,
width: 200,
color: Colors.amber,
child: const Text('Random widget'),
),
ListView.separated(
shrinkWrap: true,
itemCount: 20,
separatorBuilder: (_, __) => const Divider(),
itemBuilder: (context, int index) {
return ListTile(
title: Text('Item at $index'),
);
},
),
],
),
);
Wrap it in a Container and add a height to it.
Fixed it for me.
I solved the issue by enclosing the Column widget in a Container widget that has a set width and height
You cannot use Expanded in Column if it has a parent SingleChildScrollView because When you use column it tries to be in screen height and when use expanded inside, The column will allocate remaining space to the child of the expanded widget, Now if you use SingleChildScrollView It will try to expand(by direction, vertically in your case) as long as possible but as you're using the Expanded which tries to take remaining space, So it goes infinite thus throws that error,
So Either remove SingleChildScrollView and use Column and expanded or remove the Expanded and Use SingleChildScrollView also make sure ShrinkWrap in ListView to true.
I have found the same problem. but in my case I was trying to provide row of widgets
for trailing property of the listTile class .and I solve it by wrapping the row with container and set its width.
In one case, I got the same error.
When I scrolled to top of the log message, I found out the issue in below widget.I have wrapped the Row with IntrinsicHeight widget.
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: []));
On removing IntrinsicHeight widget, it solved.

How to make fixed button flutter?

I have a problem with fixed button inside scroll view , I made a column with SingleChildScrollView and two button, but the problem is that the screen do not scroll. I tried the bottom Navigation bar but it has the same problem. How I can fix this?
my code :
Column(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
ListView.builder(
shrinkWrap: true,
itemCount: 200,
itemBuilder: (context, index) {
return Text("200");
},
),
ListView.builder(
shrinkWrap: true,
itemCount: 20,
itemBuilder: (context, index) {
return Text("bargougui");
},
),
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
width: 150,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.grey[300],
),
onPressed: () {},
child: Text(
'Contacter',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.black,
fontStyle: FontStyle.italic,
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
width: 150,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.yellow,
),
onPressed: () {},
child: Text(
'Acheter',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.black,
fontStyle: FontStyle.italic,
),
),
),
),
),
),
],
),
],
),
screen I want to make like this
any help will be appreciated ^^
Use Stack widget,
Stack(
children:[
SingleChildScrollView(),
Positioned(
bottom:0,
left:15,
right:15,
child:Row(children :[Button1(),Button2()],
,)
]
Try tweaking the numbers to fit your case.

using onTap (Inkwell) to open/preview a Card

Im trying to use onTap in Inkwell to open/preview an existing Card but unsure how to do this, for now I just have it printing 'hello'
body: Container(
color: Colors.indigo,
child: Column(
children: <Widget>[
Flexible(
child: FirebaseAnimatedList(
query: databaseReference,
itemBuilder: (
_, DataSnapshot snapshot,
Animation<double> animation, int index) {
return Card(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: InkWell(
child: ListTile(
title: Text(
boardMessages[index].subject,
style: TextStyle(fontWeight: FontWeight.bold
),),
),
onTap: (){
print('hello');
},
),
),
);
},
),
),
],
),
EDIT: I know how to do it using Full Screen Page thanks to the docs provided, how would I do this with a Dialog? Much appreciated
Over your onTap drawer item do this:
onTap: () {
Navigator.pop(context);
_showDialog(text: 'Index $index');
}
And use the following code to show a Dialog with the necessary text:
void _showDialog({#required String text}) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
elevation: 0,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
child: IntrinsicWidth(
child: IntrinsicHeight(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10,
),
Text(
"Custom Alert Dialog",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 18,
),
),
SizedBox(
height: 20,
),
Text(
text,
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16,
),
),
SizedBox(
height: 20,
),
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("OK"),
),
),
],
),
),
),
),
);
},
);
If fully customizable with any needs you'd had.