Skip to content

Instantly share code, notes, and snippets.

View miquelbeltran's full-sized avatar

Miguel Beltran miquelbeltran

View GitHub Profile
@miquelbeltran
miquelbeltran / main.dart
Created March 3, 2021 17:02 — forked from kwalrath/main.dart
Java-to-Dart codelab: CircleMock example
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == 'circle') return Circle(2);
if (type == 'square') return Square(2);
throw 'Can\'t create $type.';
}
num get area;
}
@miquelbeltran
miquelbeltran / main.dart
Last active March 3, 2021 16:24 — forked from Sfshaza/main.dart
Java-to-Dart codelab: Basic bicycle example
class Bicycle {
late int cadence;
late int speed;
late int gear;
Bicycle(this.cadence, this.speed, this.gear);
@override
String toString() => 'Bicycle: $speed mph';
}
@miquelbeltran
miquelbeltran / templates.dart
Created July 3, 2020 08:44
Dart Live Templates for built_value
/// built_value template
/// variables:
/// CLASS_NAME
abstract class $CLASS_NAME$ implements Built<$CLASS_NAME$, $CLASS_NAME$Builder> {
factory $CLASS_NAME$([void Function($CLASS_NAME$Builder) updates]) = _$$$CLASS_NAME$;
$CLASS_NAME$._();
}
@miquelbeltran
miquelbeltran / color_gradient_grid.dart
Created March 9, 2020 20:25
Generate a color gradient grid in Flutter
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
Did you try to use stream.first?
Did you try returning "Top User is: $name"?
Did you try to use future.asStream()?
Check the classes Stream and Future for the method specifications.
Did you add the onError to the listen() method?
@miquelbeltran
miquelbeltran / hint.txt
Last active November 22, 2019 15:48
Exercise: Listening to events
Did you remember to call listen() on the stream?
Did you call to processValue inside listen()?
Use the methods `map`, `any` and `where` to solve the exercise.
Use map to create a String with the user.name and the user.age
main() {
var numbersByTwo = [1, -2, 3, 42].map((number) => number * 2);
print('Numbers: $numbersByTwo.');
}