flutter_direct_select
flutter_direct_select copied to clipboard
Range error
When the data of list is dynamically updating, if (previous list length)<(updated list length). The widget throws a range error
Hello, please add a simple sample to reproduce the error.
Thanks
On Tue, May 5, 2020, 8:36 AM akhilpune [email protected] wrote:
When the data of list is dynamically updating, if (previous list length)<(updated list length). The widget throws a range error
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_direct_select/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFL3UFTE4AP5NRUVF7X4XDRQAI7XANCNFSM4MZSSMPQ .
I am also getting a range error...
Here is a sample code.
return StreamBuilder<QuerySnapshot>( stream: _firestore .collection("users") .doc(firebaseUser.uid) .collection('location') .snapshots(), builder: (context, snapshot) { snapshot.data.docs.forEach((result) { docID.add(result.reference.id); print(result.data()); }); List<Location> locationData = []; for (var cards in snapshot.data.docs) { Location location = new Location( name: cards.data()['name'], lat: cards.data()['lat'], lng: cards.data()['lng']); locationData.add(location); } List<Widget> _buildItems() { return locationData .map((item) => MySelectionItem( title: item.name, )) .toList(); }
` return DirectSelect(
itemExtent: 35.0,
selectedIndex: selectedIndex,
backgroundColor: Colors.red,
child: MySelectionItem(
isForList: false,
title: locationData[selectedIndex].toString(),
),
onSelectedItemChanged: (index) {
selectedIndex = index;
},
mode: DirectSelectMode.tap,
items: _buildItems());
});
} }`
`class MySelectionItem extends StatelessWidget { final String title; final bool isForList;
const MySelectionItem({Key key, this.title, this.isForList = true}) : super(key: key);
@override Widget build(BuildContext context) { return SizedBox( height: 60.0, child: isForList ? Padding( child: _buildItem(context), padding: EdgeInsets.all(10.0), ) : Card( margin: EdgeInsets.symmetric(horizontal: 10.0), child: Stack( children: <Widget>[ _buildItem(context), Align( alignment: Alignment.centerRight, child: Icon(Icons.arrow_drop_down), ) ], ), ), ); }`
_buildItem(BuildContext context) { return Container( width: MediaQuery.of(context).size.width, alignment: Alignment.center, child: Text(title), ); } }
Thanks in advanced
Try recreating the issue in a smaller example, don't include another package/library.
On Wed, Feb 10, 2021 at 11:09 AM Kyle Fuhri [email protected] wrote:
I am also getting a range error...
Here is a sample code.
`return StreamBuilder( stream: _firestore .collection("users") .doc(firebaseUser.uid) .collection('location') .snapshots(), builder: (context, snapshot) { snapshot.data.docs.forEach((result) { docID.add(result.reference.id); print(result.data()); }); List locationData = []; for (var cards in snapshot.data.docs) { Location location = new Location( name: cards.data()['name'], lat: cards.data()['lat'], lng: cards.data()['lng']); locationData.add(location); } List _buildItems() { return locationData .map((item) => MySelectionItem( title: item.name, )) .toList(); }
return DirectSelect( itemExtent: 35.0, selectedIndex: selectedIndex, backgroundColor: Colors.red, child: MySelectionItem( isForList: false, title: locationData[selectedIndex].toString(), ), onSelectedItemChanged: (index) { selectedIndex = index; }, mode: DirectSelectMode.tap, items: _buildItems()); });
} }
class MySelectionItem extends StatelessWidget { final String title; final bool isForList;
const MySelectionItem({Key key, this.title, this.isForList = true}) : super(key: key);
@override https://github.com/override Widget build(BuildContext context) { return SizedBox( height: 60.0, child: isForList ? Padding( child: _buildItem(context), padding: EdgeInsets.all(10.0), ) : Card( margin: EdgeInsets.symmetric(horizontal: 10.0), child: Stack( children: [ _buildItem(context), Align( alignment: Alignment.centerRight, child: Icon(Icons.arrow_drop_down), ) ], ), ), ); }
_buildItem(BuildContext context) { return Container( width: MediaQuery.of(context).size.width, alignment: Alignment.center, child: Text(title), ); } }`
Thanks in advanced
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/diegoveloper/flutter_direct_select/issues/9#issuecomment-776820397, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFL3UE7UWUQFS3ZGJQFCB3S6KVSNANCNFSM4MZSSMPQ .