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 / flutter_overlay.dart
Last active March 6, 2021 07:44
Flutter Overlay
import 'package:flutter/material.dart';
/// How to use:
/// final WOverlay _overlay = WOverlay();
/// @override
/// Widget build(BuildContext context) {
/// return CompositedTransformTarget(
/// link: _overlay.layerLink,
/// child: child,
/// );
@nhancv
nhancv / flutter_search_highlight.md
Created December 25, 2020 11:36
Flutter Search widget & highlight text in search

Widget

// list
return ListView.separated(
                    physics: const AlwaysScrollableScrollPhysics(),
                    itemCount: friends.length,
                    itemBuilder: (BuildContext context, int index) {
                      final Friend item = friends[index];
                      return _buildItem(context, index, item, provider);
                    },
@nhancv
nhancv / flutter_sqflite.md
Last active February 3, 2021 12:23
flutter sqflite: Persist data with SQLite

pubspec.yaml

sqflite: ^1.3.2+1

lib/services/local/migrate/migrate.dart

import 'package:sqflite/sqflite.dart';

abstract class Migrate {
@nhancv
nhancv / flutter_ripple_animation.dart
Created December 17, 2020 08:50
Flutter ripple animation in-case scanning
import 'dart:math' as math show sin, pi, sqrt;
import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
class CirclePainter extends CustomPainter {
CirclePainter(
this._animation, {
@required this.color,
}) : super(repaint: _animation);
@nhancv
nhancv / flutter_route_reset.md
Last active December 30, 2020 06:59
Flutter route reset to login

Reset route to login page in-case logout or unauthorizes

context.navigator()?.pushNamedAndRemoveUntil('/', (_) => false);

Pop to home (in case do some stuffs with long flow, then back to home)

  • Ex: Home -> Page 1 -> Page 2 -> Home
@nhancv
nhancv / flutter_ripple_effect_button.md
Last active January 5, 2021 16:46
Deal with flutter ripple effect
  • Use Inkwell if subview does not have background color
InkWell(
  child: Container(height: 30),
  onTap: () {},
),
  • Inkwell does not work if Container has color like this
@nhancv
nhancv / install_ubuntu_server_nodejs_mongodb.md
Last active October 30, 2021 12:29
Install ubuntu server nodejs mongodb

Ubuntu 18.04

Install Git

sudo apt install git -y

Install NodeJs

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
@nhancv
nhancv / flutter_date_utils.dart
Last active December 30, 2020 06:58
Flutter date time utils
// import 'package:intl/intl.dart';
// const String dateString = '10/12/2020';
// final DateTime dateTimeObj = DateFormat('dd/MM/yyyy').parse(dateString);
// print('dateTimeObj $dateTimeObj');
//
// final String dateTimeFormatString = DateFormat('yyyy-MM-dd').format(dateTimeObj);
// print('dateTimeFormatString $dateTimeFormatString');
// Today 11:08 PM
// => 'Today ${DateFormat('h:mm a').format(toDay)}'
@nhancv
nhancv / flutter_custom_splash_background.md
Last active December 30, 2020 07:00
Flutter custom splash screen background

Android

  • Add launch_bg.png and launch_image.png to
+ android/app/src/main/res/drawable-mdpi
+ android/app/src/main/res/drawable-xhdpi
+ android/app/src/main/res/drawable-xxhdpi
@nhancv
nhancv / open_urls_chrome.md
Created December 4, 2020 11:56
Open multi url in Chrome macOS

Create new shell script file

nano chrome.sh

## content
urls="
https://google.com
https://stackoverflow.com
"