Skip to content

Instantly share code, notes, and snippets.

View legalcodes's full-sized avatar

Jon Tippens legalcodes

  • San Francisco, California
View GitHub Profile
@legalcodes
legalcodes / mock_result.dart
Created April 23, 2019 20:17
Mock _result function
void _result(bool success, [List<String> messages]) {
final joinedMessages = messages?.map((m) => m.toString())?.join(',') ?? '';
print('success: $success, "messages": $joinedMessages');
}
@legalcodes
legalcodes / main.dart
Last active January 26, 2023 08:32
Vanilla Owl
// Copyright 2019 the Dart project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
import 'package:flutter_web/material.dart';
import 'package:flutter_web_test/flutter_web_test.dart';
import 'package:flutter_web_ui/ui.dart' as ui;
const owl_url = 'https://raw.githubusercontent.com/flutter/website/master/src/images/owl.jpg';
@legalcodes
legalcodes / main.dart
Last active February 5, 2021 17:24 — forked from datafoya/main.dart
Image class
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() async {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: MyApp(),
),
@legalcodes
legalcodes / shoppingListTest.dart
Created February 3, 2020 19:03
Testing Shopping List change
import 'package:flutter/material.dart';
class Product {
const Product({this.name});
final String name;
}
typedef void CartChangedCallback(Product product, bool inCart);
class ShoppingListItem extends StatelessWidget {
@legalcodes
legalcodes / main.dart
Last active January 22, 2020 14:06 — forked from datafoya/main.dart
Create a Column
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
children: [
BlueBox(),
@legalcodes
legalcodes / main.dart
Last active November 27, 2019 18:07
handle_errors_example
void printOrderMessage () async {
try {
var order = await fetchUserOrder();
print('Awaiting user order...');
print(order);
} catch (err) {
print('Caught error: $err');
}
}
@legalcodes
legalcodes / main.dart
Last active November 27, 2019 17:21
Why Async Matters
// This example shows how *not* to write asynchronous Dart code.
String createOrderMessage () {
var order = fetchUserOrder();
return 'Your order is: $order';
}
Future<String> fetchUserOrder() {
// Imagine that this function is more complex and slow
return Future.delayed(Duration(seconds: 4), () => 'Large Latte');
@legalcodes
legalcodes / hint.txt
Last active November 25, 2019 23:45
Practice Using async and await
Did you remember to add the async keyword to the reportUserRole function?
Did you remember to use the await keyword before invoking fetchRole?
Remember: reportUserRole needs to return a future!
@legalcodes
legalcodes / main.dart
Last active November 25, 2019 23:42
Putting It All Together (More practice with async and await)
// Part 1
addHello(){}
// Part 2
//You can call the provided async function fetchUsername to return the username
greetUser(){}
// Part 3
//You can call the provided async function logoutUser to logout the user
sayGoodbye(){}