Skip to content

Instantly share code, notes, and snippets.

Working from home

Nhan Cao nhancv

Working from home
View GitHub Profile
nhancv / painter.dart
Last active Jan 28, 2021
Flutter custom painter: rounded rect and arrow
View painter.dart
class _MenuBoxBackground extends CustomPainter {
void paint(Canvas canvas, Size size) {
final Paint paint = Paint()
..color = Colors.white
..strokeWidth = 1.W = PaintingStyle.fill;
final double triangleH = 10.H;
final double triangleW = 25.0.W;
final double width = size.width;
nhancv / w_behind_keyboard.dart
Last active Jan 15, 2021
Flutter hide widget when keyboard opened
View w_behind_keyboard.dart
import 'package:flutter/material.dart';
import 'package:nft/utils/app_route.dart';
class WBehindKeyboard extends StatefulWidget {
const WBehindKeyboard(
{Key key,
@required this.child,
this.reversed = false,
this.keepView = true})
: super(key: key);
nhancv / w_circle_crop.dart
Last active Jan 14, 2021
Flutter crop circles, background image, draggable, transparent hole
View w_circle_crop.dart
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:nft/services/safety/base_stateful.dart';
import 'package:nft/widgets/p_appbar_transparency.dart';
import 'package:path_provider/path_provider.dart';
nhancv / w_draggable.dart
Created Jan 14, 2021
Flutter draggable widget
View w_draggable.dart
/// Draggable widget
class _WDraggable extends StatefulWidget {
const _WDraggable({Key key, this.child, this.valueChanged}) : super(key: key);
final Widget child;
final ValueChanged<Offset> valueChanged;
_WDraggableState createState() => _WDraggableState();
nhancv / flutter_own_toast.dart
Last active Jan 12, 2021
Flutter create your own toast view
View flutter_own_toast.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:nft/services/app/dynamic_size.dart';
import 'package:nft/services/safety/base_stateful.dart';
import 'package:nft/utils/app_extension.dart';
import 'package:simple_animations/simple_animations.dart';
/// OToast.I.showCustomToast(context, 'hello');
class OToast with DynamicSize {
nhancv / flutter_custom_texteditingcontroller.dart
Last active Jan 7, 2021
Custom TextEditingController to style multi color icon font
View flutter_custom_texteditingcontroller.dart
class AppTextEditingController extends TextEditingController {
TextSpan buildTextSpan({TextStyle style, bool withComposing}) {
final TextSpan textSpan =
super.buildTextSpan(style: style, withComposing: withComposing);
if (text != null) {
return _buildEmojiTextSpan(text);
return textSpan;
nhancv / flutter_insert_text.dart
Last active Jan 15, 2021
Flutter Insert text to TextField
View flutter_insert_text.dart
// Insert text to TextField
void insertText(String insert, TextEditingController controller) {
final int cursorPos = controller.selection.base.offset;
controller.value = controller.value.copyWith(
text: controller.text.replaceRange(max(cursorPos, 0), max(cursorPos, 0), insert),
selection: TextSelection.fromPosition(TextPosition(offset: max(cursorPos, 0) + insert.length))
nhancv / flutter_bottom_action_sheet.dart
Last active Jan 5, 2021
Flutter custom bottom action sheet
View flutter_bottom_action_sheet.dart
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:nft/utils/app_extension.dart';
import 'package:nft/utils/app_style.dart';
// showCupertinoModalPopup<void>(
// context: context,
// builder: (BuildContext context) {
// return WBottomActionSheet(
View flutter_divider_line.dart
import 'package:flutter/material.dart';
class WDividerLine extends StatelessWidget {
const WDividerLine({Key key, this.width, this.height, this.color})
: super(key: key);
final double width;
final double height;
final Color color;
nhancv / flutter_emotion_text.dart
Last active Jan 6, 2021
Flutter custom chat emoji text (custom icon text font)
View flutter_emotion_text.dart
import 'package:nft/services/safety/base_stateful.dart';
import 'package:flutter/material.dart';
/// Use
/// const WChatText(text: 'hello:heart.86ac068::smile.48f82f2::fire.9f77c64:'),
class WChatText extends StatefulWidget {
const WChatText({Key key, @required this.text}) : super(key: key);
final String text;