import 'package:flutter/material.dart'; class DateSelector extends StatefulWidget { @override _DateSelectorState createState() => _DateSelectorState(); } class _DateSelectorState extends State { final List months = [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre" ]; var _selectedIndex = 0; void _updateSelectedItem(int index) { setState(() { _selectedIndex = index; }); } @override Widget build(BuildContext context) { return SliverToBoxAdapter( child: SizedBox( height: 32, child: ListView( scrollDirection: Axis.horizontal, children: _buildSelector(), ), ), ); } List _buildSelector() { return months .asMap() .map( (key, value) => MapEntry( key, chipForRow( label: value, isSelected: key == _selectedIndex, currentPosition: key, ), ), ) .values .toList(); } Widget chipForRow({String label, bool isSelected, int currentPosition}) { if (isSelected) { return SizedBox( height: 28, child: TextButton( onPressed: () { _updateSelectedItem(currentPosition); }, child: Text( label, style: TextStyle( fontSize: 14, color: Colors.white, ), ), style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Color(0xFFFF567E)), shape: MaterialStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.all( Radius.circular(4), ), ), ), ), ), ); } else { return SizedBox( height: 28, child: TextButton( onPressed: () { _updateSelectedItem(currentPosition); }, child: Text( label, style: TextStyle( fontSize: 14, color: Color(0xFF8F8F8F), ), ), ), ); } } }