Skip to content

Instantly share code, notes, and snippets.

@chunhunghan
chunhunghan / CustomInputBorder.dart
Last active March 8, 2023 01:05
flutter CustomInputBorder
//Based on Flutter 3.7.6 Dart SDK 2.19.3
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
//https://medium.com/flutter-community/export-your-widget-to-image-with-flutter-dc7ecfa6bafb
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
Future<ui.Image> load(String asset) async {
ByteData data = await rootBundle.load(asset);
ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List());
ui.FrameInfo fi = await codec.getNextFrame();
return fi.image;
}
@chunhunghan
chunhunghan / main.dart
Created July 11, 2019 09:11
Parse text which contains http or https string inside
var urlPattern = r"(https?|http)://([-A-Z0-9.]+)(/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#/%=~_|!:‌​,.;]*)?";
RegExp exp = new RegExp(urlPattern, caseSensitive: false);
String str = "Parse https://www.google.com/abc中文 http://www.umc.com/ my string";
Iterable<Match> matches = exp.allMatches(str);
for (Match m in matches) {
String match = m.group(0);
print(match);
}
import 'package:flutter/material.dart';
import 'dart:math' as math;
import 'package:flutter/rendering.dart';
//Transform的变换是应用在绘制阶段,而并不是应用在布局(layout)阶段,
// 所以无论对子widget应用何种变化,其占用空间的大小和在屏幕上的位置都是固定不变的,
// 因为这些是在布局阶段就确定的。
main() {
debugPaintSizeEnabled = true;
/*
After the 25.1.0 support library was introduced, now is possible to read exif data from URI contents (content:// or file://) through an InputStream.
Example: First add this line to your gradle file:
compile 'com.android.support:exifinterface:25.1.0'
*/
Uri uri; // the URI you've received from the other app
InputStream in;
import 'dart:io' show Platform;
if (Platform.isAndroid) {
// Android-specific code
} else if (Platform.isIOS) {
// iOS-specific code
}
/*
Other options include:
@chunhunghan
chunhunghan / main.dart
Last active August 3, 2022 06:36
Flutter : Round corner container and backdrop Filter effect and https://github.com/SnakeyHips/recipeapp/blob/master/lib/pages/home_page.dart
Widget frostedEdged(Widget child) {
return ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: child));
}
@chunhunghan
chunhunghan / main.dart
Last active June 28, 2019 03:29
Flutter : WebSocket connect with headers https://qiita.com/n-luan/items/e81870598e7598ee415b
channel = new IOWebSocketChannel.connect(socketUrl, headers: {
"UID": auth.uid,
"ACCESS_TOKEN": auth.accessToken,
"CLIENT_ID": auth.clientId
});
channel.sink.add(json.encode({
"command": "subscribe",
"identifier": "{\"channel\":\"RoomChannel\"}"
}));
var ws = new WebSocketServer({
verifyClient: function (info, cb) {
var token = info.req.headers.token
if (!token)
cb(false, 401, 'Unauthorized')
else {
jwt.verify(token, 'secret-key', function (err, decoded) {
if (err) {
cb(false, 401, 'Unauthorized')
} else {