Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @JsonSerializable()
- class Location {
- int id;
- String name;
- String banglaName;
- int parentId;
- int active;
- bool isSelected = false;
- Location(
- this.id,
- this.name,
- this.banglaName,
- this.parentId,
- this.active,
- );
- factory Location.fromJson(Map<String, dynamic> json) =>
- _$LocationFromJson(json);
- Map<String, dynamic> toJson() => _$LocationToJson(this);
- }
- return Flexible(
- child: Container(
- height: 100.0,
- child: ListView.builder(
- scrollDirection: Axis.horizontal,
- itemBuilder: (context, index) => AreaListItem(
- area: locationList[index],
- onAreaClick: (String name, int id, bool shouldChangeItem) {
- debugPrint('onAreaClick name: $name id: $id');
- if (shouldChangeItem) {
- setState(() {
- locationList[index].isSelected = true;
- });
- }
- },
- ),
- itemCount: locationList.length,
- padding: new EdgeInsets.symmetric(vertical: 16.0),
- ),
- ),
- );
- class AreaListItem extends StatelessWidget {
- final Location area;
- final Function onAreaClick;
- AreaListItem({this.area, this.onAreaClick});
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- child: Container(
- margin: EdgeInsets.symmetric(
- horizontal: 8.0,
- ),
- child: Row(children: <Widget>[
- Text(
- area.name,
- textAlign: TextAlign.center,
- style: TextStyle(
- fontWeight: FontWeight.bold,
- color: Colors.blueGrey,
- ),
- ),
- ]),
- decoration: BoxDecoration(
- border: Border.all(width: 2, color: Colors.blueGrey),
- borderRadius: BorderRadius.all(
- Radius.circular(16.0),
- ),
- color: area.isSelected ? Colors.greenAccent : Colors.red,
- ),
- ),
- //onTap: onAreaClick(area.name, area.id),
- onTap: () {
- area.isSelected
- ? onAreaClick(area.name, area.id, false)
- : onAreaClick(area.name, area.id, true);
- //debugPrint('${area.name}');
- },
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement