Skip to content

Instantly share code, notes, and snippets.

[
{
"id": 1,
"name": "THE BUG",
"brand": "VW",
},
{
"id": 2,
"name": "A car",
"brand": "BMW",
Car myCar = Car(
id: 1,
name: "THE BUG",
brand: CarBrand.VW,
);
bool isGood(Car car) {
return car.brand == CarBrand.Tesla || car.name == "THE BUG";
}
enum CarBrand {
Volvo,
Mercedes,
BMW,
Tesla,
Ford,
VW,
}
@lukeurban
lukeurban / car.dart
Last active September 4, 2020 18:18
DoYouEvenFlutter? [EP.2] API Enum Mapping
class Car {
final int id;
final String name;
final CarBrand brand;
Car({
this.id,
this.name,
this.brand,
});
}
class ListItem {
final GlobalKey itemKey = GlobalKey();
final int index;
ListItem({
this.index,
});
}
final ScrollController scrollController = ScrollController();
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
scrollController.animateTo(60.0 * 70,
curve: Curves.linear, duration: Duration(milliseconds: 500));
});
}
@lukeurban
lukeurban / scroll_to_element.dart
Last active August 29, 2020 16:20
DoYouEvenFlutter
List<ListItem> list;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
ListItem item = list.elementAt(70);
Scrollable.ensureVisible(item.itemKey.currentContext);
});
}