title: how to set width of container based on text length in flutter
body: <p>I have created list of cateogories using list listview.builder</p>
  <p>here I want to highlight selected category by underlining category text with container and I want to apply width based on text length...same way like we do underline for text,</p>
  <p>I know they are inbuilt some packages but I don't want to use it as I want to implement my logic.</p>
  <p>here is my code</p>
  <p>I have set comment where I want to dynamic width</p>
  <pre><code>
  class CatogoryList extends StatefulWidget {
  
  
    @override
    State&lt;CatogoryList&gt; createState() =&gt; _CatogoryListState();
  }
  
  class _CatogoryListState extends State&lt;CatogoryList&gt; {
    List&lt;String&gt; categories=['HandBag','Jwellery','FootWear','Dresses','Pens','Jeans','Trousers'];
    int selectedindex=2;
    @override
    Widget build(BuildContext context) {
      return SizedBox(
        height: 30,
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
            itemCount: categories.length,
            itemBuilder: (context,index){
          return buildCategory(index);
  
        }),
      );
    }
  
    Widget buildCategory(int index)
    {
      return GestureDetector(
        onTap: (){
          setState(() {
            selectedindex=index;
          });
        },
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 8.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
            Text(categories[index],style: TextStyle(fontSize: 20,color: selectedindex==index?Colors.blue:Colors.grey),),
            if(selectedindex==index)
              Container(
  // here I want to set widget of container based on text length
              height: 3,width: 30,color: Colors.blue,),
  
          ],),
        ),
      );
    }
  }
  
  </code></pre>