Skip to content

Instantly share code, notes, and snippets.

View riscait's full-sized avatar

Ryunosuke Muramatsu riscait

View GitHub Profile
@riscait
riscait / main.dart
Created August 9, 2024 07:06
Record.wait vs Future.wait
void main() async {
// can catch exeptions.
wait();
// cannot catch exeptions.
record();
}
Future<bool> someFuture() async {
Future.delayed(const Duration(seconds: 1));
return true;
@riscait
riscait / favorite_button.dart
Last active July 31, 2024 08:14
FavoriteButton with Animations
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
@riscait
riscait / main.dart
Last active September 28, 2023 06:33
Collection for vs. map
void main() {
final stopwatch = Stopwatch();
() {
stopwatch.start();
final sut = List.generate(100000, (index) => index * index);
[for (final s in sut) s.toString()];
stopwatch.stop();
print('for time: ${stopwatch.elapsedMilliseconds} ms');
}();
import 'package:authenticator/authenticator.dart';
import 'package:awaitable_button/awaitable_button.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:gap/gap.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:themes/themes.dart';
import '../../../router/router.dart';
import '../../../util/providers/providers.dart';
// Definition
@Riverpod(keepAlive: true)
_RefreshToken refreshToken(RefreshTokenRef ref) => _RefreshToken(ref);
class _RefreshToken {
const _RefreshToken(this.ref);
final Ref ref;
Future<RefreshTokenResponse> call({
@riscait
riscait / main.dart
Created June 28, 2022 04:30
unawaited vs ignore
import 'dart:async';
Future<void> throwForIgnore() async {
throw Exception('for ignore'); // <- be ignored
}
Future<void> throwForUnawaited() async {
throw Exception('for unawaited');
}
@riscait
riscait / main.dart
Created June 20, 2022 03:13
Type check with Extended class
class BaseClass {}
class ExtendedClass extends BaseClass {}
class OtherClass {}
void main() {
final baseClass = BaseClass();
final extendedClass = ExtendedClass();
@riscait
riscait / main.dart
Last active May 26, 2022 01:02
Flutter precacheImage example with Flutter Hooks
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
@riscait
riscait / main.dart
Created May 25, 2022 20:17
Flutter precacheImage example
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
@riscait
riscait / main.dart
Created April 9, 2022 21:29
Use "getter" or "late final" or "object injection" ?
import 'package:riverpod/riverpod.dart';
final stateProvider = StateProvider((_) => 1);
final getterClassProvider = Provider((ref) => GetterClass(ref.read));
class GetterClass {
GetterClass(this._read) {
print('Construct GetterClass');
}
final Reader _read;