Skip to content

Instantly share code, notes, and snippets.

View fredgrott's full-sized avatar
👾
focusing on flutter cross platform mobile dev

Fred Grott fredgrott

👾
focusing on flutter cross platform mobile dev
View GitHub Profile
@fredgrott
fredgrott / localization_test.dart
Created April 18, 2024 16:45
localization testing
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:localization_wo_context/generated/l10n.dart';
import 'package:localization_wo_context/generated/l10n.dart';
import 'package:localization_wo_context/generated/l10n.dart';
late final appNavKey;
void main() {
@fredgrott
fredgrott / app_globals.dart
Created April 18, 2024 16:39
app globals
import 'package:flutter/material.dart';
final navigatorKey = GlobalKey<NavigatorState>();
// navigatorKey is parameter which goes in the MaterialApp
// navigagtorKey parameter slot. Then we can do
@fredgrott
fredgrott / dynamic_casting_data.dart
Created April 10, 2024 19:21
json dynamic casting
class Container extends Coding {
List<String> things;
@override
Map<String, cast.Cast<dynamic>> get castMap => {
"things": cast.List(cast.String)
};
@override
@fredgrott
fredgrott / data.dart
Created April 10, 2024 19:18
data class with json supporting lists
class Team extends Coding {
List<Person> members;
Person manager;
@override
void decode(KeyedArchive object) {
super.decode(object); // must call super
members = object.decodeObjects("members", () => Person());
@fredgrott
fredgrott / sample.dart
Created April 10, 2024 19:16
json examples
// decode
final json = json.decode(...);
final archive = KeyedArchive.unarchive(json);
final person = Person()..decode(archive);
//encode
final person = Person()..name = "Bob";
final archive = KeyedArchive.archive(person);
final json = json.encode(archive);
@fredgrott
fredgrott / data.dart
Created April 10, 2024 19:12
data class using json helper
class Person extends Coding {
String name;
@override
void decode(KeyedArchive object) {
// must call super
super.decode(object);
name = object.decode("name");
}
@fredgrott
fredgrott / resolver.dart
Created April 10, 2024 19:07
resolver json
// Copyright 2024 Fredrick Allan Hrott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from original by codable BSD 2 clause
// license 2019.
import 'package:json_helpers/json_helpers/keyed_archive.dart';
class ReferenceResolver {
@fredgrott
fredgrott / list.dart
Created April 10, 2024 19:05
list json
// Copyright 2024 Fredrick Allan Hrott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from original by codable BSD 2 clause
// license 2019.
import 'dart:collection';
import 'package:json_helpers/json_helpers/codable.dart';
@fredgrott
fredgrott / codable.dart
Created April 10, 2024 19:03
codable json
// Copyright 2024 Fredrick Allan Hrott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from original by codable BSD 2 clause
// license 2019.
import 'package:json_helpers/json_helpers/resolver.dart';
abstract class Referencable {
@fredgrott
fredgrott / cast.dart
Created April 10, 2024 19:01
cast json
// Copyright 2024 Fredrick Allan Hrott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from original by codable BSD 2 clause
// license 2019.
import 'dart:async' as async;
import 'dart:core' as core;
import 'dart:core' hide Map, String, int;