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 22, 2024 14:47
testing localizations
// 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.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
// General idea is the localizations in the model are referred to as
@fredgrott
fredgrott / snippet.dart
Created April 22, 2024 14:44
localization wo contex
AppLocalizations.of(appRouterContext).localizationKey;
import 'package:better_localization_steps/src/app_globals.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'sample_feature/sample_item_details_view.dart';
import 'sample_feature/sample_item_list_view.dart';
import 'settings/settings_controller.dart';
import 'settings/settings_view.dart';
@fredgrott
fredgrott / app_globals.dart
Created April 22, 2024 14:39
app globals
// 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.
import 'package:flutter/material.dart';
// So this is how we will get the context to use in any models as
// the scaffoldMessengerKey will be supplied to the MaterialApp
// and then the appRouterContext will be the context referred to
// in the AppLocalisations.of().localizationKey call in the model
@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");
}