Skip to content

Instantly share code, notes, and snippets.

View nhancv's full-sized avatar
🏠
Working from home

Nhan Cao nhancv

🏠
Working from home
View GitHub Profile
@nhancv
nhancv / w_behind_keyboard.dart
Last active March 17, 2021 00:07
Flutter hide widget when keyboard opened
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
nhancv / w_circle_crop.dart
Last active August 28, 2023 13:10
Flutter crop circles, background image, draggable, transparent hole
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
nhancv / w_draggable.dart
Created January 14, 2021 17:11
Flutter draggable widget
/// Draggable widget
class _WDraggable extends StatefulWidget {
const _WDraggable({Key key, this.child, this.valueChanged}) : super(key: key);
final Widget child;
final ValueChanged<Offset> valueChanged;
@override
_WDraggableState createState() => _WDraggableState();
}
@nhancv
nhancv / flutter_own_toast.dart
Last active January 12, 2021 12:39
Flutter create your own toast view
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
nhancv / flutter_custom_texteditingcontroller.dart
Last active January 7, 2021 11:19
Custom TextEditingController to style multi color icon font
class AppTextEditingController extends TextEditingController {
@override
TextSpan buildTextSpan({TextStyle style, bool withComposing}) {
final TextSpan textSpan =
super.buildTextSpan(style: style, withComposing: withComposing);
if (text != null) {
return _buildEmojiTextSpan(text);
}
return textSpan;
@nhancv
nhancv / flutter_insert_text.dart
Last active January 15, 2021 05:12
Flutter Insert text to TextField
// 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
nhancv / flutter_bottom_action_sheet.dart
Last active January 5, 2021 16:59
Flutter custom bottom action sheet
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(
@nhancv
nhancv / flutter_divider_line.dart
Created January 5, 2021 16:14
Flutter divider line
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
nhancv / flutter_emotion_text.dart
Last active January 6, 2021 23:51
Flutter custom chat emoji text (custom icon text font)
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;
@nhancv
nhancv / ios-version.sh
Created January 4, 2021 05:11
Update info.plist version
#!/usr/bin/env bash -e
_INFOPLIST_DIR="ios/Runner/Info.plist"
_PACKAGE_VERSION=$(cat pubspec.yaml | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[: ']//g'')
# Set BUILD_NUMBER to the value 1 only if it is unset.
: ${BUILD_NUMBER=$(expr $(git log -1 --pretty=format:%ct) / 3600)}
# Update plist with new values