Skip to content

Instantly share code, notes, and snippets.

@matsuhiro
matsuhiro / main.dart
Last active January 9, 2022 13:07
FittedBox and Text
import 'dart:ui';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
import sketch from "sketch";
// const Style = require("sketch/dom").Style;
// const SharedStyle = require("sketch/dom").SharedStyle;
// const Flow = require("sketch/dom").Flow;
// const Rectangle = require("sketch/dom").Rectangle;
// const SmartLayout = require("sketch").SmartLayout;
// const Group = require("sketch/dom").Group;
// const Artboard = require("sketch/dom").Artboard;
// const Shape = require("sketch/dom").Shape;
/***
* Excerpted from "Functional Programming in Java",
* published by The Pragmatic Bookshelf.
* Copyrights apply to this code. It may not be used to create training material,
* courses, books, articles, and the like. Contact us if you are in doubt.
* We make no guarantees that this code is fit for any purpose.
* Visit http://www.pragmaticprogrammer.com/titles/vsjava8 for more book information.
***/
package fpij;
void main() {
try {
throw 1;
} catch (e) {
print('What is thrown: $e');
}
printDivider();
try {
@matsuhiro
matsuhiro / gist:1ccbc9a6a5527b2c490ed31b79ffd1eb
Created December 2, 2019 04:16
flutter_dev_channel_native_call
E/flutter (21138): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
E/flutter (21138): If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.
E/flutter (21138): If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.
E/flutter (21138): #0 defaultBinaryMessenger.<anonymous closure> (package:flutter/src/services/binary_messenger.dart:73:7)
E/flutter (21138): #1 defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:86:4)
E/flutter (21138): #2 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62)
E/flutter (21138): #3 MethodChannel.invokeMethod
typedef Compare = int Function(Object a, Object b);
class SortedCollection {
Compare compare;
SortedCollection(this.compare);
}
// Initial, broken implementation.
int sort(Object a, Object b) => 0;
Future<int> sumStream(Stream<int> stream) async {
var sum = 0;
await for (var value in stream) {
print("sum = $sum");
sum += value;
}
return sum;
}
Stream<int> countStream(int to) async* {
void main() {
try {
throw Exception();
} on Exception {
// A specific exception
print('Exception exception');
} catch (e) {
// No specified type, handles all
print('Something really unknown: $e');
}
void main() {
var names = <String>{};
print(names);
Set<String> set = {};
print(set);
Map<String, String> map = {};
print(map);
var set_or_map = {};
print(set_or_map is Set);
void main() {
var constantList = const [1, 2, 3];
// constantList[1] = 1; // Uncommenting this causes an error.
var list = [1, 2, 3];
var list2 = [0, ...list, ...list];
print(list2);
var promoActive = false;
var nav = [