Skip to content

Instantly share code, notes, and snippets.

View RedBrogdon's full-sized avatar
💭
Flutterin'.

Andrew Brogdon RedBrogdon

💭
Flutterin'.
View GitHub Profile
@RedBrogdon
RedBrogdon / introrx.md
Last active February 8, 2018 00:47 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@RedBrogdon
RedBrogdon / json_article_1.dart
Created August 1, 2018 17:10
Testing out syntax highlighting for Medium articles.
import 'dart:async';
import 'package:http/http.dart' as http;
final response = await http.get(myEndpointUrl);
if (response.statusCode == 200) {
// use the data in response.body
} else {
// handle a failed request
}
final myObject = serializers.deserializeWith(
SimpleObject.serializer, json.decode(aJsonString));
final myObject = SimpleObject.fromJson(json.decode(aJsonString));
import 'dart:convert';
try {
final parsed = json.decode(aJsonStr);
} on FormatException catch (e) {
print("That string didn't look like Json.");
} on NoSuchMethodError catch (e) {
print('That string was null!');
}
final dynamicListOfInts = json.decode(aJsonArrayOfInts);
// Create a strongly typed list with references to the data that are casted
// immediately. This is probably the better approach for data model classes.
final strongListOfInts = List<int>.from(dynamicListOfInts);
// Or create a strongly typed list with references that will be lazy-casted
// when used.
final anotherStrongListOfInts = List<int>.from(dynamicListOfInts);
{
"aString": "Blah, blah, blah.",
"anInt": 1,
"aDouble": 1.0,
"aListOfStrings": ["one", "two", "three"],
"aListOfInts": [1, 2, 3],
"aListOfDoubles": [1.0, 2.0, 3.0]
}
class SimpleObject {
const SimpleObject({
this.aString,
this.anInt,
this.aDouble,
this.aListOfStrings,
this.aListOfInts,
this.aListOfDoubles,
});
return SimpleObject(
aString: json['aString'] ?? "",
anInt: json['anInt'] ?? 0,
aDouble: json['aDouble'] ?? 1.0,
aListOfStrings: List.from(json['aListOfStrings'] ?? []),
aListOfInts: List.from(json['aListOfInts'] ?? []),
aListOfDoubles: List.from(json['aListOfDoubles'] ?? []),
);
class SimpleObject {
SimpleObject({
this.aString,
this.anInt,
this.aDouble,
this.aListOfStrings,
this.aListOfInts,
this.aListOfDoubles,
});