Flutter check if value exists in json show/hide container - flutter

I'm new to flutter, I wanna show container if a specific value exists in Kinds model, the model contains stores, groceries and markets I don't know how to do it exactly please help me with my code
the controller returns the json is kindController.kindDataList
so if market exist in the json then show
child: HomeFlatBtn(image: 'market', height: 150, currentTab: 1,),
Container(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: Dimensions.PADDING_SIZE_SMALL),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Column(children: [
Padding(
padding: EdgeInsets.symmetric(vertical: Dimensions
.PADDING_SIZE_SMALL,
horizontal: Dimensions.PADDING_SIZE_SMALL),
child: HomeFlatBtn(
image: 'market', height: 150, currentTab: 1,),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: Dimensions
.PADDING_SIZE_SMALL),
child: HomeFlatBtn(
image: 'grocery', height: 150, currentTab: 1,),
),
]
),
),
Expanded(child: HomeFlatBtn(image: 'food',
height: 0,
currentTab: 1),
),
],
),
),
),
),

You can use Visibility widget for this.
Just wrap Container with Visibility. Like this:
Visibility(
visible: true, //set this to either true or false
child: Container(
//the contents of Container
),
),
//visible decides whether your Container will be visible or not.

Related

I made customize horizontal stepper in flutter and it's not scrolled till the end

Does anyone know how to make my stepper scrollable in vertically, it actually could scroll but it doesn't scrolling till the end of the page length
The stepper:
MainScaffold(
title: appBarTitle,
body: Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
width: width,
child: Column(
children: <Widget>[
const SizedBox(
height: 8,
),
Row(
children: _lineViews(),
),
const SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: _titleViews(),
),
const SizedBox(
height: 20,
),
Expanded(
child: ListView(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: stepPanels())
],
),
),
const SizedBox(
height: 20,
),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: _buttonControls(currentStep, context),
);
I put the stepper's content inside expanded listview, and I already add shrinkwrap & physics into it, when I call this customizable widget on another class, it can't be scrolled till the end of the page
Steps(
content: Obx(
() {
if (controller.loading.value) {
return const LoadingProgressIndicator();
} else {
return SizedBox(
height: MediaQuery.of(context).size.height,
child: ListView(
physics: const ClampingScrollPhysics(),
children: [
controller.loading.value
? const LoadingProgressIndicator()
: _doctorProfile(),
const SizedBox(height: 10.0),
const ClinicTypeToggle(),
const SizedBox(height: 100.0),
],
),
);
}
},
),
),
that is the content that I want to scroll

Flutter UI design using stack and column: How Can i achieve this look?

I am using Flutter 2.8, as many package dont yet have support for latest flutter version.
I am using stack instead of appBar. and I want to get the look as of below picture.
I dont want to use stack in the whole page, i think it will cause performance issues. Also, If i use stack only in lieu of appBar, I can copy paste this code to make that home button on top-left corner, for another app.
here is my full code of this page:
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return SafeArea(
child : Scaffold(
//todo: 1. copy code from getx4 cool ui app
//todo: 1. make it as he made it
body: Column(
children: [
Expanded(
flex: 1,
child: Container(
color: Color(0xFFc5e5f3),
child: Stack(
children: [
Positioned(
top: 10,
left: 5,
child: IconButton(
onPressed: () {},
icon: Icon(Icons.home),
)),
],
),
),
),
Expanded(
flex: 10,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
children: [
Expanded(child: Text('ShopX', style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold) ,)),
Padding(
padding: const EdgeInsets.only(right: 8) ,
child: Icon(Icons.format_list_bulleted ),
),
Icon(Icons.grid_view_outlined ),
],
),
),
),
],
),
),
);
}
}
You need to use Align widget with a property like alignment: FractionalOffset.topCenter . Please see the sample code below:
Stack(
fit: StackFit.expand,
children: <Widget>[
Column(
children: [
Container(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
color: Colors.black,
child: Image(image: AssetImage('assets/image.png'), width: MediaQuery.of(context).size.width, height: 50,)),
Expanded(
flex: 1,
child: Align(
alignment: FractionalOffset.topCenter,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: Padding(
padding: const EdgeInsets.fromLTRB(35, 12, 0, 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Image(image: AssetImage('assets/image.png'), width: 120, alignment: Alignment.bottomLeft,),
Image(image: AssetImage('assets/image.png'), width: 100, alignment: Alignment.bottomLeft,),
Image(image: AssetImage('assets/image.png'), width: 100, height: 40, alignment: Alignment.bottomLeft,),
],
),
),),),
),
],
),
],
),
This sample code adds images 4 images on top center of the screen.
1 image on the top of the screen
3 images below the top image
Moreover, you can directly put your Stack widget into the body of Scaffold.
Use crossAxisAlignment: CrossAxisAlignment.start, on Row. Default is center.
Expanded(
flex: 10,
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start, //this
children: [
Expanded(
child: Text(
'ShopX',
style:
TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
)),

Flutter design with timeline

I'm trying to make this drawing but I'm struggling.
I don't understand how to make the white block of information dynamic. That is to say that it automatically adapts to the size in height of the elements it contains.
I am for the moment obliged to give a defined height (here 200), I would like the size to be automatic. Moreover if I do not give a defined size my gray line on the left side disappears.
The design :
ListTile(
title : Column(
children: [
Container(
width: double.infinity,
child: Row(
children: [
Container(
width: 50,
alignment: Alignment.center,
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
border: Border.all(
width: 5,
color: Colors.blue,
style: BorderStyle.solid
)
),
),
),
Text('9:00 am - 9:15 am')
],
)
),
Container(
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width : 50,
alignment: Alignment.center,
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
color: Colors.grey,
width: 3,
height : 200 // if I remove the size it desappear
),
],
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.symmetric(vertical :10),
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 10),
color: Colors.white,
child: Column(
children: [
Text('Titre'),
Text('Info 1'),
Text('Info 2')
],
),
),
)
],
),
),
)
],
),
),
You can try this package for timelines https://pub.dev/packages/timeline_tile.
This package also automatically Sizes your widget height and width.
And for Automatically Sizing your widgets next time, You could use Expanded widget at most places in your code.
Note: An Expanded widget must be a descendant of a Row, Column, or Flex, So Use it carefully.
I think it's much easier with this package, timelines.
TimelineTileBuilder.connected(
connectionDirection: ConnectionDirection.before,
itemCount: processes.length,
contentsBuilder: (_, index) {
//your Container/Card Content
},
indicatorBuilder: (_, index) {
if (processes[index].isCompleted) {
return DotIndicator(
color: Color(0xff66c97f),
child: Icon(
Icons.check,
color: Colors.white,
size: 12.0,
),
);
} else {
return OutlinedDotIndicator(
borderWidth: 2.5,
);
}
},
connectorBuilder: (_, index, ___) => SolidLineConnector(
color: processes[index].isCompleted ? Color(0xff66c97f) : null,
),
),
),

Refresh ListView.builder On Button Click in Flutter

I am using the below code, where I have a ListView that had a switch.
I want to implement something like when I click on the RaisedButton - it will reload the ListView and all the values of switch.value should be changed to either true or false.
The user can either change the value of the switch from items in the ListView or from the button click.
I do not have an idea on how I should change the value or all the switches in the ListView.
return Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 2,
height: 100,
padding: EdgeInsets.all(20),
child: RaisedButton(
onPressed: () {
},
child: Text(
BTN_START_TRIP,
style: new TextStyle(
fontSize: 20.0,
),
),
textColor: buttonFontColor,
color: buttonColor,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(15.0))
),
),
Expanded(
child: ListView.builder(
padding: EdgeInsets.all(3.0),
// Let the ListView know how many items it needs to build.
itemCount: snapshot.data.results.length,
// Provide a builder function. This is where the magic happens.
// Convert each item into a widget based on the type of item it is.
itemBuilder: (context, index){
return Container(
height: 120,
child: Card(
elevation: 10,
child: InkWell(
splashColor: Colors.blue.withAlpha(30),
onTap: () {
print(snapshot.data.results[index].original_title);
},
child: Container(
height: 120,
child: Row(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(20, 0, 5, 0),
width: MediaQuery.of(context).size.width -90,
child: Align(
alignment: Alignment.topLeft,
child: Text(snapshot.data.results[index].original_title,
textAlign: TextAlign.left,
style: TextStyle(fontSize: defaultTitleFontsize, color: defaultFontColor),
maxLines: 5),
),
),
Container(
padding: EdgeInsets.fromLTRB(20, 0, 5, 0),
child: Align(
alignment: Alignment.topLeft,
child: Text(snapshot.data.results[index].original_language,textAlign: TextAlign.left,style: TextStyle(fontSize: defaultsubTitleFontsize, color: defaultFontColor)),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
child: Switch(
value: false,
onChanged: (value){
setState(() {
print(value);
});
}
),
),
],
),
]
),
),
),
),
);
},
),
)
],
);
You'll need to have a variable to decide if the switch should be on or off. And during a certain event (click of button e.g) set the variable to appropriate value & re-trigger the build (re-painting of the UI) by calling setState. You'll need to have the above logic part of a stateful widget to accomplish that.

infinity height in the listview of the flutter

Hi friends i am new to the flutter development here i am using the list view please find this image
Where i am want to remove the white space above and below the image make it stretch on this white spaces i am tried to sized box but its given error that double.infinity cant be used please find the below code please help me out friends
new SliverList(
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
return new GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new News_Details(
postid: latest_news_list[index]['id'],
)));
},
child: new Card(
elevation: 4.0,
margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0),
child: new Row(
children: <Widget>[
**new Container(
child: new Image.network(
latest_news_list[index]['image'],
width: 150.0,
fit: BoxFit.cover,
),
),**
new Flexible(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
child: new Text(latest_news_list[index]['title']),
margin: EdgeInsets.only(left: 10.0, top: 10.0),
),
new Container(
child: new Divider(
color: secondarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0),
),
new Container(
child: new Text(
latest_news_list[index]['content'],
softWrap: true,
maxLines: 4,
),
margin: EdgeInsets.only(
left: 10.0, top: 5.0, bottom: 5.0),
),
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Container(
child: new Text('VSB News'),
margin:
EdgeInsets.only(left: 10.0, top: 10.0,bottom: 10.0),
),
new Container(
child: new Text(
latest_news_list[index]['post_dt']),
margin:
EdgeInsets.only(left: 10.0, top: 10.0,right: 10.0,bottom: 10.0),
),
],
)
],
),
)
],
),
),
);
},
childCount: latest_news_list == null ? 0 : latest_news_list.length,
),
),
You can edit the line
fit: BoxFit.cover
to
fit: BoxFit.fitHeight
inside you container that grabs image from network.
I think you are trying to put a list inside another list, so the error shows
you can put the list (nested list which is inside the list) in a container and specify a height :
ListView _buildMainView(){
return new ListView(
children: <Widget>[
new Text("Main List"),
new Container(
height: 100.0,
child: new ListView(
children: <Widget>[
new Text("Nested List")
],
),
)
],
);
)
If you have a ListView with vertical scroll direction, and want it to have a infinity height, maybe you don't need a ListView.
You can use a regular Column.