I have enum class and I want to show the enum data to ListView. Can anyone tell how to do that?
enum TableType { circle, square, rectangle }
Possible duplicate of this
You can do
List<String> values = TableType.values.map((e) => e.name).toList();
More about name extension
You could use something like this to be able to use enum values inside your UI:
enum TableType { circle, square, rectangle }
class ExmaplePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView(
children: TableType.values
.map(
(tt) => _Table(tt),
)
.toList(
growable: false,
),
);
}
}
class _Table extends StatelessWidget {
final TableType type;
_Table(this.type);
@override
Widget build(BuildContext context) {
return Text(
type.name,
);
}
}
But it would be great if you could provide more information about problem you are trying to solve or even provide code example that you tried to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With