This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 + ', '); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:url_launcher/url_launcher.dart'; | |
| RaisedButton( | |
| onPressed: () => client.getRequestTokenUrl().then((url){ | |
| launch(url); | |
| // other handlings. | |
| } | |
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TextEditingController _textFieldController = TextEditingController(); | |
| @override | |
| Widget build(BuildContext context) { | |
| ... | |
| ... | |
| AlertDialog( | |
| title: Text('Input verification code'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |