Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.41 KB | None | 0 0
  1. @JsonSerializable()
  2. class Location {
  3.   int id;
  4.   String name;
  5.   String banglaName;
  6.   int parentId;
  7.   int active;
  8.  
  9.   bool isSelected = false;
  10.  
  11.   Location(
  12.     this.id,
  13.     this.name,
  14.     this.banglaName,
  15.     this.parentId,
  16.     this.active,
  17.   );
  18.  
  19.   factory Location.fromJson(Map<String, dynamic> json) =>
  20.       _$LocationFromJson(json);
  21.  
  22.   Map<String, dynamic> toJson() => _$LocationToJson(this);
  23. }
  24.  
  25. return Flexible(
  26.               child: Container(
  27.                 height: 100.0,
  28.                 child: ListView.builder(
  29.                   scrollDirection: Axis.horizontal,
  30.                   itemBuilder: (context, index) => AreaListItem(
  31.                     area: locationList[index],
  32.                     onAreaClick: (String name, int id, bool shouldChangeItem) {
  33.                       debugPrint('onAreaClick name: $name id: $id');
  34.  
  35.                       if (shouldChangeItem) {
  36.                         setState(() {
  37.                           locationList[index].isSelected = true;
  38.                         });
  39.                       }
  40.                     },
  41.                   ),
  42.                   itemCount: locationList.length,
  43.                   padding: new EdgeInsets.symmetric(vertical: 16.0),
  44.                 ),
  45.               ),
  46.             );
  47.  
  48.  
  49. class AreaListItem extends StatelessWidget {
  50.   final Location area;
  51.   final Function onAreaClick;
  52.  
  53.   AreaListItem({this.area, this.onAreaClick});
  54.  
  55.   @override
  56.   Widget build(BuildContext context) {
  57.     return GestureDetector(
  58.       child: Container(
  59.         margin: EdgeInsets.symmetric(
  60.           horizontal: 8.0,
  61.         ),
  62.         child: Row(children: <Widget>[
  63.           Text(
  64.             area.name,
  65.             textAlign: TextAlign.center,
  66.             style: TextStyle(
  67.               fontWeight: FontWeight.bold,
  68.               color: Colors.blueGrey,
  69.             ),
  70.           ),
  71.         ]),
  72.         decoration: BoxDecoration(
  73.           border: Border.all(width: 2, color: Colors.blueGrey),
  74.           borderRadius: BorderRadius.all(
  75.             Radius.circular(16.0),
  76.           ),
  77.           color: area.isSelected ? Colors.greenAccent : Colors.red,
  78.         ),
  79.       ),
  80.       //onTap: onAreaClick(area.name, area.id),
  81.       onTap: () {
  82.         area.isSelected
  83.             ? onAreaClick(area.name, area.id, false)
  84.             : onAreaClick(area.name, area.id, true);
  85.         //debugPrint('${area.name}');
  86.       },
  87.     );
  88.   }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement