Skip to content

Instantly share code, notes, and snippets.

View szepeshazi's full-sized avatar

András Szepesházi szepeshazi

View GitHub Profile
@szepeshazi
szepeshazi / test_utils.dart
Last active September 29, 2022 14:44
Convenience class extensions for finding certain widgets during tests in the Widget hierarchy
import 'package:flutter_test/flutter_test.dart';
typedef FinderSelector = Finder Function(Finder);
FinderSelector firstChild = (Finder finder) => finder.first;
FinderSelector lastChild = (Finder finder) => finder.last;
FinderSelector childAt(int index) => (Finder finder) => finder.at(index);
@szepeshazi
szepeshazi / main.dart
Last active January 3, 2023 15:06
Transitional state notifier full example
import 'dart:math' show Random;
import 'package:riverpod/riverpod.dart';
/// Function signature to compute a new state value for [TransitionalStateNotifier]
typedef StateComputation<T> = Future<T> Function();
/// A [StateNotifier] that safely handles transitions between states
/// Especially useful when state computation is a costly async operation,
/// and there may be more frequent requests to update the state than
/// the previous states
@szepeshazi
szepeshazi / example.dart
Last active September 13, 2022 18:20
Transitional State Notifier
class UiState {
final int originalValue;
final int? computedValue;
UiState({required this.originalValue, this.computedValue});
UiState.empty()
: originalValue = 0,
computedValue = null;
@szepeshazi
szepeshazi / main.dart
Last active September 14, 2022 08:48
Riverpod example #2
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counter = StateProvider<int>((ref) => 0);
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
@szepeshazi
szepeshazi / main.dart
Last active September 14, 2022 08:46
Riverpod example #1
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counter = StateProvider<int>((ref) => 0);
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
@szepeshazi
szepeshazi / main.dart
Last active August 23, 2022 15:26
Flutter riverpod concurrency example
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'dart:async' show Timer;
import 'dart:math' show Random;
class ExpensiveNotifier extends StateNotifier<int> {
final rnd = Random();
ExpensiveNotifier() : super(0);
Future<void> update(int updateCount) async {
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counter = StateProvider<int>((_) => 0);
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
@szepeshazi
szepeshazi / main.dart
Last active October 24, 2020 18:56
Multi-level declarative navigation
// Copyright (c) 2019, 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 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@szepeshazi
szepeshazi / main.dart
Last active October 24, 2020 19:00
Nested declarative navigator
// Copyright (c) 2019, 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 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@szepeshazi
szepeshazi / custom_config.lua
Created November 22, 2019 12:50
Cmder custom prompt
local function verbatim(s)
s = string.gsub(s, "%%", "%%%%")
return s
end
local function set_custom_prompt()
-- get_cwd() is differently encoded than the clink.prompt.value, so everything other than
-- pure ASCII will get garbled. So try to parse the current directory from the original prompt
-- and only if that doesn't work, use get_cwd() directly.
-- The matching relies on the default prompt which ends in X:\PATH\PATH>