Skip to content

Instantly share code, notes, and snippets.

View noboru-i's full-sized avatar
🏠
Always working from home

Noboru ISHIKURA noboru-i

🏠
Always working from home
View GitHub Profile
@noboru-i
noboru-i / main.dart
Created March 9, 2024 05:48
My understanding of ProviderScope was wrong.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(ProviderScope(child: const MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@noboru-i
noboru-i / main.dart
Last active August 30, 2023 03:49
Call async function from non-async function
void main() {
print('main: before someFutureFunc');
someFutureFunc();
print('main: after someFutureFunc');
}
Future<void> someFutureFunc() async {
print('someFutureFunc: before wait');
await Future.delayed(const Duration(seconds: 3));
print('someFutureFunc: after wait');
@noboru-i
noboru-i / main.dart
Created August 18, 2023 04:14
mellow-spray-5912
void main() {
List<HitProduct> hitProducs = [];
hitProducs.add(HitProduct("test"));
hitProducs.add(HitProduct("test2"));
final test = hitProducs.map((hitProduct) => OtherClass(hitProduct: hitProduct)).toList();
print('test is $test');
}
@noboru-i
noboru-i / main.dart
Last active May 19, 2023 03:37
bustling-marble-3699
import 'dart:async';
Future<void> main() async {
final controller = StreamController<int>();
startSender(controller);
await for (int n in controller.stream) {
print('consume $n');
}
@noboru-i
noboru-i / main.dart
Last active May 19, 2023 00:51
Listの結合について確認
import 'dart:math';
void main() {
final List<int> a = [1, 2];
final List<int> b = [3, 4];
List<int> newList1 = a;
newList1 += b;
print('newList1 $newList1'); // -> newList1 [1, 2, 3, 4]
@noboru-i
noboru-i / main.dart
Last active February 11, 2023 04:50
Dart: typedef and extension
typedef Id = String;
extension on Id {
String get firstChar => substring(0, 1);
}
typedef IdList = List<Id>;
extension on IdList {
String get firstItem => this[0];
@noboru-i
noboru-i / main.dart
Last active September 8, 2022 03:32
Check term
void main() {
_test1();
_test2();
_test3();
_test4();
// check `assert` works
assert(false);
}
@noboru-i
noboru-i / main.dart
Last active September 7, 2022 07:48
Check `await for` + stream works
import 'dart:async';
void main() {
final controller = StreamController<String>();
_handle1(controller.stream);
// _handle2(controller.stream);
controller.sink.add('message 1');
controller.sink.add('message 2');
@noboru-i
noboru-i / main.dart
Last active May 26, 2022 01:35
Flutter CircularProgressIndicator
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
@noboru-i
noboru-i / main.dart
Last active February 12, 2022 07:57
FutureProvider sample (Riverpod)
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {