Skip to content

Instantly share code, notes, and snippets.

@CoderJava
Created October 3, 2020 12:25
Show Gist options
  • Select an option

  • Save CoderJava/42a49a69bb92f4affa2ee010a7f25f31 to your computer and use it in GitHub Desktop.

Select an option

Save CoderJava/42a49a69bb92f4affa2ee010a7f25f31 to your computer and use it in GitHub Desktop.
Simple choice chip
import 'package:flutter/material.dart';
class ChoiceChipExample extends StatefulWidget {
@override
_ChoiceChipExampleState createState() => _ChoiceChipExampleState();
}
class _ChoiceChipExampleState extends State<ChoiceChipExample> {
final listChoices = <ItemChoice>[
ItemChoice(1, '7 Hari'),
ItemChoice(2, '14 Hari'),
ItemChoice(3, '1 Bulan'),
ItemChoice(4, '3 Bulan'),
];
var idSelected = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Choice Chip'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Terakhir ditambahkan'),
Wrap(
children: listChoices
.map((e) => ChoiceChip(
label: Text(e.label),
selected: idSelected == e.id,
onSelected: (_) => setState(() => idSelected = e.id),
))
.toList(),
spacing: 8,
),
],
),
),
);
}
}
class ItemChoice {
final int id;
final String label;
ItemChoice(this.id, this.label);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment