I have a ListView inside a Column:
SizedBox(width: 100, height: 100, child: ListView.builder(
shrinkWrap: true,
itemCount: _listHours.length,
itemBuilder: (context, index) {
return ListTile(
title: Center(child: Text(_listHours[index].toString())),
selected: index == _selectedIndexHours,
dense: true,
selectedTileColor: Colors.indigo.withOpacity(0.6),
onTap: () {
setState(() {
_selectedIndexHours = _listHours[index];
});
},
);
}
),),
When an item is selected, the selection itself is visible by scrolling the entire length of the screen.
You are having a problem similar to this one where the ListTile's decoration renders outside the ListView. There is no solution for this yet but you can implement some workarounds. In this section of code, I set on "null" the ListTile's "onTap" parameter and wrapped it with a GestureDetector widget. Like this:
SizedBox(width: 100, height: 100, child: ListView.builder(
shrinkWrap: true,
itemCount: _listHours.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
_selectedIndexHours = _listHours[index];
});
}
child: ListTile(
title: Center(child: Text(_listHours[index].toString())),
selected: index == _selectedIndexHours,
dense: true,
selectedTileColor: Colors.indigo.withOpacity(0.6),
onTap: null
)
);
}
),
),
I hope this works for you.
Related
I am working in a project,It has a zoom widget.
I show the lot of sentences inside the listview builder along with pageview builder.
I want to pinch zoom to increase the text size.
If i zoom the listview with using two fingers,I will need to increase my text size,
and also decrese my text size,I applied some codes my app,it should be a low response in my listview builder
The code is here
InteractiveViewer(
transformationController: _transformationController,
child: GestureDetector(
onScaleStart: (ScaleStartDetails scaleStartDetails) {
_baseFontScale = _fontScale;
},
onScaleUpdate:
(ScaleUpdateDetails scaleUpdateDetails) {
setState(
() {
_fontScale =
(_baseFontScale * scaleUpdateDetails.scale)
.clamp(0.5, 5);
fontSized = _fontScale * _baseFontSize;
},
);
},
child: PageView.builder(
controller: page,
itemCount:91,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, key) {
return ListView.builder(
itemCount: verse.length,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return InkWell(
onTap: () {
toggleSelection();
setState(() {
highlightIndex.remove(index);
showMenu = false;
});
},
onLongPress: () {
print(highlightIndex);
setState(() {
highlightIndex.add(index);
});
},
child: AbsorbPointer(
child: Container(
padding: EdgeInsets.all(
ComponentSize.paddingall),
color: highlightIndex.contains(index)
? Colors.grey
: _appcolor,
child: SizedBox(
child: ListTile(
minLeadingWidth: 15,
leading: Text(
(index + 1).toString(),
style:
TextStyle(color: _fontcolor),
),
title: SelectableText(
"$item"
style: TextStyle(
color: _fontcolor,
height: 1.4,
fontSize: fontSized,
fontFamily:
language ,
),
),
),
),
);
},
);
},
when I tap containter and update selectedIndex equal current index, but it not will update.
class HomeController extends GetxController {
final RxList<PurineTypeModel> dataSource = RxList();
final selectedIndex = 0.obs;
}
Obx(() {
return ListView.builder(
cacheExtent: 30,
scrollDirection: Axis.horizontal,
itemBuilder: (c, index) {
print("refresh?? $index");
return GestureDetector(child: Container(
width: 100,
color: controller.selectedIndex.value == index ? Colors.red : Colors.green,
child: Text(
controller.selectedIndex.string),
), onTap: () {
controller.selectedIndex.value = 1;
},);
},
itemCount: controller.dataSource.length);
})
onTap: () {
controller.selectedIndex.value = index;
},);
setup index element not 1
the controller is initialized how?
You need to wrap the GestureDetector also in an Obx, so like this:
Obx(() {
return ListView.builder(
cacheExtent: 30,
scrollDirection: Axis.horizontal,
itemBuilder: (c, index) {
print("refresh?? $index");
return Obx(() =>
GestureDetector(child: Container(
width: 100,
color: controller.selectedIndex.value == index ? Colors
.red : Colors.green,
child: Text(
controller.selectedIndex.string),
), onTap: () {
controller.selectedIndex.value = 1;
},));
},
itemCount: controller.dataSource.length);
})
Because the outer Obx only observes controller.dataSource.length
I have wrapped ListView.builder inside Visible widget, and the button for its visible property is in a ListTile widget with variable _currencyVisible.
The widget Visible works 2 times i.e. false/hidden(default), then changes to visible when clicked, and again hides on the second click, but it doesn't work after that. Printing on console _currencyVisible shows correct data.
Here's my code:
menuItems(BuildContext context) {
bool _currencyVisible = false;
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return ListView(
children: [
ListTile(
title: FutureBuilder<dynamic>(
future: getUserCurrencySymbol(),
builder:(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
return Text("Currency " + snapshot.data.toString());
}),
trailing: IconButton(
icon: Icon(Icons.refresh),
onPressed: () { setState(() { _currencyVisible = !_currencyVisible; }); },
),
),
Visibility(
visible: _currencyVisible,
child: ListView.builder(
shrinkWrap: true,
itemCount:
currency.allCurrenciesList.length,
itemBuilder: (context, index) {
for (Currency c in currency.allCurrenciesList) {
currency.allCurrenciesList.removeAt(0);
return Card(
child: ListTile(
title: Text(c.country),
subtitle: Text(c.shortCurrency),
trailing: Text(c.symbol),
onTap: () {
saveUserCurrency(c.country, context);
},
),
);
}
return Text("Not Null");
},
),
),
],
);
},
);
}
You are removing all of the data from your currency list. The widget is showing correctly, but there is no data to display.
Remove this line
currency.allCurrenciesList.removeAt(0);
Don't loop through the currencies in itemBuilder. Use index instead.
Visibility(
visible: _currencyVisible,
child: ListView.builder(
shrinkWrap: true,
itemCount: currency.allCurrenciesList.length,
itemBuilder: (context, index) {
final c = currency.allCurrenciesList[index];
return Card(
child: ListTile(
title: Text(.country),
subtitle: Text(c.shortCurrency),
trailing: Text(c.symbol),
onTap: () {
saveUserCurrency(c.country, context);
},
);
}
return Text("Not Null");
),
),
I have an ExpansionPanelList inside a ListView and I'm unable to get it to scroll when trying in the middle of the screen, though it will work on the edges. I've attached the code below. I'm guessing its the ExpansionPanelList that isn't letting me scroll but I'm not sure why because the items are inside a ListView as well.
I've taken a video of the issue https://drive.google.com/file/d/19zM7cfjshcN8OfEbRhvxIgmUp8sq1TP6/view?usp=sharing
_bodyBuilder() {
return
ListView(
shrinkWrap: true,
padding: EdgeInsets.all(15.0),
children: <Widget>[
ExpansionPanelList.radio(
initialOpenPanelValue: 2,
children: dateList.map<ExpansionPanelRadio>((DateTime date) {
return ExpansionPanelRadio(
canTapOnHeader: true,
value: date.day,
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(DateFormat('dd/MM/yyyy').format(date)),
);
},
body: Container(
//child: ListView.separated(
child: ListView.builder(
shrinkWrap: true,
itemCount: cleanRecords
.where((Log) =>
DateTime.parse(DateFormat('yyyy-MM-dd')
.format(Log.time.toDateTime()))
.toString() ==
date.toString())
.toList()
.length,
itemBuilder: (context, index) {
final records = cleanRecords
.where((Log) =>
DateTime.parse(DateFormat('yyyy-MM-dd')
.format(Log.time.toDateTime()))
.toString() ==
date.toString())
.toList();
final schedule = records[index];
return ListTile(
title: Text(DateFormat('hh:mm').format(schedule.time.toDateTime())),
subtitle: Text(schedule.notes),
onTap: () => _updateRecord(schedule.parentID, schedule.id),
);
},
// separatorBuilder: (context, index) {
// return Divider();
// },
),
),
);
}).toList(),
)
],
);// ListTiles++
}
I have 2 CupertinoPicker inside BottomSheet, the data comes from Firestore when I am changing selected Item in governorate it updates the List data of locations in the another cupertinopicker
Here picture you will see 4 Cupertino picker in Row but the forth Picker doesn't update unless I close the bottom sheet and open it again so how to Update/Refresh CupertinoPicker List Data while onSelectedItemChanged() called
here is some Code
Expanded(
child: StreamBuilder(
stream: _fireStore.collection('Locations').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Container();
}
return CupertinoPicker(
squeeze: 1.5,
diameterRatio: 1,
useMagnifier: true,
looping: true,
scrollController: _controllerPicker,
itemExtent: 33.0,
backgroundColor: Colors.white,
onSelectedItemChanged: (int index) => setState(() {
_pickerKey.currentState.build(context);
_getChosenGovLocation(snapshot
.data.documents[index].documentID);
}),
children: new List<Widget>.generate(
snapshot.data.documents.length, (int index) {
return new Center(
child: new Text(
'${snapshot.data.documents[index]['countryEN']}',
style: TextStyle(fontSize: 16),
),
);
}));
}),
),
Expanded(
child: CupertinoPicker.builder(
key: _pickerKey,
squeeze: 1.5,
diameterRatio: 1,
useMagnifier: true,
scrollController: new FixedExtentScrollController(
initialItem: 0,
),
itemExtent: 33.0,
backgroundColor: Colors.white,
onSelectedItemChanged: (int index) {
setState(() {
sortLocation = _sortBranches[index]['branchEN'];
});
print(sortLocation);
},
childCount: _sortBranches.length,
itemBuilder: (context, index) {
return new Center(
child: new Text(
'${_sortBranches[index]['branchEN']}',
style: TextStyle(fontSize: 16),
),
);
}),
),
and here is the Method that called while the selecte item changing
_getChosenGovLocation(id) {
_sortBranches.clear();
_fireStore.collection('Locations').document(id).snapshots().forEach((doc) {
setState(() {
_sortBranches = doc.data['branches'].toList();
print(_sortBranches.length);
});
});
print('list Called');
}
I've Fixed it out just used StatefullBuilder it fixed the problem