Skip to content

Instantly share code, notes, and snippets.

@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);
});
}
final ScrollController scrollController = ScrollController();
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
scrollController.animateTo(60.0 * 70,
curve: Curves.linear, duration: Duration(milliseconds: 500));
});
}
class ListItem {
final GlobalKey itemKey = GlobalKey();
final int index;
ListItem({
this.index,
});
}
@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,
});
}
enum CarBrand {
Volvo,
Mercedes,
BMW,
Tesla,
Ford,
VW,
}
Car myCar = Car(
id: 1,
name: "THE BUG",
brand: CarBrand.VW,
);
bool isGood(Car car) {
return car.brand == CarBrand.Tesla || car.name == "THE BUG";
}
[
{
"id": 1,
"name": "THE BUG",
"brand": "VW",
},
{
"id": 2,
"name": "A car",
"brand": "BMW",
class Car {
final int id;
final String name;
final CarBrand brand;
Car({
this.id,
this.name,
this.brand,
});
// Place fonts/icomoon.ttf in your fonts/ directory and
// add the following to your pubspec.yaml
// flutter:
// fonts:
// - family: icomoon
// fonts:
// - asset: fonts/icomoon.ttf
import 'package:flutter/widgets.dart';
class Icomoon {
{
"quizId": 1,
"data": [
{
"questionId": 1,
"title": "Best programming language",
"body": "",
"correctAnswer": "1",
"answers": [
{