Skip to content

Instantly share code, notes, and snippets.

@ThrowJojo
Created May 26, 2021 23:00
Show Gist options
  • Save ThrowJojo/6c275bec244d117720564a8ef1a0282d to your computer and use it in GitHub Desktop.
Save ThrowJojo/6c275bec244d117720564a8ef1a0282d to your computer and use it in GitHub Desktop.
Some tasty fruit
import 'package:flutter/material.dart';
enum Fruit {
apple,
orange,
banana,
}
extension FruitExt on Fruit {
Color get color {
switch (this) {
case Fruit.apple:
return Colors.red;
case Fruit.orange:
return Colors.orange;
case Fruit.banana:
return Colors.yellow;
default:
return Colors.red;
}
}
String get name {
switch (this) {
case Fruit.apple:
return "Apple";
case Fruit.orange:
return "Orange";
case Fruit.banana:
return "Banana";
default:
return "Apple";
}
}
}
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: ListView.builder(
itemCount: Fruit.values.length,
itemBuilder: (context, index) {
final fruit = Fruit.values[index];
return ListTile(
title: Text(
fruit.name,
style: TextStyle(color: fruit.color),
),
);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment