Skip to content

Instantly share code, notes, and snippets.

@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 21:58
Java-to-Dart codelab: Final Bicycle example
class Bicycle {
int cadence;
int _speed;
int gear;
Bicycle(this.cadence, this._speed, this.gear);
int get speed => _speed;
void applyBrake(int decrement) {
@Sfshaza
Sfshaza / main.dart
Last active April 23, 2018 15:14
streams/throw_error
// Copyright (c) 2015, the Dart project authors.
// Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed
// by a BSD-style license that can be found in the LICENSE file.
import 'dart:async';
Future<int> sumStream(Stream<int> stream) async {
var sum = 0;
try {
@Sfshaza
Sfshaza / main.dart
Created April 18, 2018 18:12
Step 6-NEW: Flutter Get Started codelab
// Add a new route to hold the favorites.
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@Sfshaza
Sfshaza / main.dart
Created April 18, 2018 16:52
Step 5-NEW: Getting Started with Flutter Codelab
// Make the heart icons tappable.
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@Sfshaza
Sfshaza / main.dart
Last active April 18, 2018 01:01
Step 4: Flutter's Getting Started Codelab
// Create an infinite scrolling lazily loaded list
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@Sfshaza
Sfshaza / main.dart
Last active March 3, 2018 04:47
Step 7: Flutter Get Started codelab
// Step 7 (Final): Change the app's theme
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@Sfshaza
Sfshaza / main.dart
Last active March 3, 2018 04:45
Step 5: Flutter Get Started codelab
// Step 5: Add a lazily loading infinite scrolling ListView.
// Also, add a heart icon so users can favorite word pairings.
// Save the word pairings in the State class.
// Make the hearts tappable and save the favorites list in the
// State class.
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp());
@Sfshaza
Sfshaza / main.dart
Last active December 21, 2017 22:11
futures/futures-api
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:html';
printDailyNewsDigest() {
var future = gatherNewsReports();
future.then((content) => print(content));
}
@Sfshaza
Sfshaza / main.dart
Last active December 21, 2017 21:20
futures/async-await
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:html';
import 'dart:async';
Future printDailyNewsDigest() async {
String news = await gatherNewsReports();
print(news);
@Sfshaza
Sfshaza / main.dart
Last active April 26, 2017 23:56
Java-to-Dart codelab: Final Rectangle example
import 'dart:math';
class Rectangle {
Point origin;
int width;
int height;
Rectangle({this.origin = const Point(0, 0), this.width = 0, this.height = 0});
@override