Skip to content

Instantly share code, notes, and snippets.

@plateaukao
plateaukao / image.dart
Created April 13, 2019 05:00
flutter_image_example
import 'dart:io' as Io;
import 'package:image/image.dart';
void main() {
// Read an image from file (webp in this case).
// decodeImage will identify the format of the image and use the appropriate
// decoder.
Image image = decodeImage(new Io.File('test.webp').readAsBytesSync());
// Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
Image thumbnail = copyResize(image, 120);
@plateaukao
plateaukao / download_image.dart
Created April 13, 2019 05:06
download image in flutter
Future<dynamic> downloadImage() async {
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$filename');
if (file.existsSync()) {
print('file already exist');
var image = await file.readAsBytes();
return image;
} else {
print('file not found downloading from server');
@plateaukao
plateaukao / image_remove_backgroun.dart
Created April 13, 2019 05:18
image remove background in flutter
Future<Uint8List> _downloadImage() async {
String dir = (await getApplicationDocumentsDirectory()).path;
File file = new File('$dir/$_filename');
if (file.existsSync()) {
var image = await file.readAsBytes();
return image;
} else {
var response = await http.get(_url,);
var bytes = response.bodyBytes;
@plateaukao
plateaukao / isolate_example.dart
Last active May 28, 2019 07:18
isolate_example
Isolate isolate;
void startRealAsyncTask() async {
// need a ReceivePort to receive messages.
ReceivePort receivePort= ReceivePort();
isolate = await Isolate.spawn(heavyTask, receivePort.sendPort);
receivePort.listen((data) {
stdout.write('RECEIVE: ' + data + ', ');
});
}
static Image processImage(Image srcImage) {
return srcImage.replaceColor(Colors.white, Colors.transparent);
}
Image _getTransparentBackgroundImage(Image srcImage) async {
Image resultImage = await compute(processImage, srcImage);
return resultImae;
}
@plateaukao
plateaukao / calliplus_image_process_flow.puml
Created July 4, 2019 01:35
calliplus image process flow
@startuml
alt case: no local cache
autonumber "<font color=red><b>[0]"
CalliImage -> http: get (image file)
http --> CalliImage: image file with white background
CalliImage -> ImageProcessing: compute(removeWhiteBackground, bytes)
ImageProcessing --> CalliImage: processed image
CalliImage -> CalliImage: save file to local storage
CalliImage -> CalliImage: in build(), Image.memory(processed image)
else case: local cache exists
@plateaukao
plateaukao / oauth1_init.dart
Last active July 23, 2019 14:53
oauth1_init.dart
import 'package:oauth1/oauth1.dart' as oauth1;
const String FLICKR_API_URL_OAUTH_BASE="https://www.flickr.com/services/oauth";
const String FLICKR_API_URL_REQUEST_TOKEN ="$FLICKR_API_URL_OAUTH_BASE/request_token";
const String FLICKR_API_URL_AUTHORIZE="$FLICKR_API_URL_OAUTH_BASE/authorize";
const String FLICKR_API_URL_ACCESS_TOKEN="$FLICKR_API_URL_OAUTH_BASE/access_token";
class FlickrApiClient {
final platform = new oauth1.Platform(
@plateaukao
plateaukao / flickr_launch_url.dart
Last active July 23, 2019 14:45
flickr_launch_url.dart
import 'package:url_launcher/url_launcher.dart';
RaisedButton(
onPressed: () => client.getRequestTokenUrl().then((url){
launch(url);
// other handlings.
}
),
@plateaukao
plateaukao / flickr_request_token.dart
Created July 23, 2019 14:56
flickr_request_token.dart
TextEditingController _textFieldController = TextEditingController();
@override
Widget build(BuildContext context) {
...
...
AlertDialog(
title: Text('Input verification code'),
@plateaukao
plateaukao / flickr_verifier.dart
Created July 25, 2019 15:41
flickr_verifier.dart
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
class _MyHomePageState extends State<MyHomePage> {
FlutterWebviewPlugin _flutterWebviewPlugin;
@override
void initState() {
super.initState();
...
_flutterWebviewPlugin = FlutterWebviewPlugin()..onUrlChanged.listen((url) {