Commit 87597012 authored by Dasun Madushanka's avatar Dasun Madushanka

update details category list

parent 34fe4e75
import 'package:flutter/material.dart';
import '../../../constants.dart';
// We need statefull widget because we are gonna change some state on our category
class CategoryList extends StatefulWidget {
@override
_CategoryListState createState() => _CategoryListState();
}
class _CategoryListState extends State<CategoryList> {
// by default first item will be selected
int selectedIndex = 0;
List categories = ['All', 'Tests'];
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: kDefaultPadding / 2),
height: 30,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) => GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(
left: kDefaultPadding,
// At end item it add extra 20 right padding
right: index == categories.length - 1 ? kDefaultPadding : 0,
),
padding: EdgeInsets.symmetric(horizontal: kDefaultPadding),
decoration: BoxDecoration(
color: index == selectedIndex
? Colors.white.withOpacity(0.4)
: Colors.transparent,
borderRadius: BorderRadius.circular(6),
),
child: Text(
categories[index],
style: TextStyle(color: Colors.white),
),
),
),
),
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment