Skip to content

Instantly share code, notes, and snippets.

View huynguyennovem's full-sized avatar
:shipit:
Build new things

Nguyen Quang Huy huynguyennovem

:shipit:
Build new things
View GitHub Profile
@huynguyennovem
huynguyennovem / EachDirectoryPath.md
Created September 9, 2021 09:18 — forked from granoeste/EachDirectoryPath.md
[Android] How to get the each directory path.

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

How to handle Delete permission in MediaStore for multiple items

  • For multiples items, there is a little change for Android R and above by create a Delete request for multiple uris:

MediaStore.createDeleteRequest(getApplication().contentResolver, uris)

// In ViewModel class
@huynguyennovem
huynguyennovem / voiceover_on_submit.dart
Created March 8, 2022 12:05
VoiceOver only works if TextFormField validator value changed
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
// Auto-enable accessibility for our Blind and Low Vision customers (see
// https://docs.flutter.dev/development/accessibility-and-localization/accessibility#screen-readers).
RendererBinding.instance!.setSemanticsEnabled(true);
@huynguyennovem
huynguyennovem / scrollbar_listview.dart
Created March 8, 2022 12:13
Scrollbar with ListView shows 2 scrollbars
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
@huynguyennovem
huynguyennovem / textfield_border_distorted.dart
Created March 8, 2022 12:29
Border of a textfield is distorted upon focus
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
@huynguyennovem
huynguyennovem / indexedstack_loss_focus.dart
Created March 8, 2022 13:10
IndexedStack lose focused when switching between index
import 'dart:ui' show window;
import 'package:flutter/material.dart';
void main() {
runApp(BugReport());
}
class BugReport extends StatefulWidget {
@override
@huynguyennovem
huynguyennovem / animatedtheme_exception.dart
Created March 8, 2022 13:41
AnimatedTheme throws exceptions when switching
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() {
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
runApp(MyApp());
}
@huynguyennovem
huynguyennovem / flutter_search_delegate_sample.dart
Created November 3, 2022 13:29
Flutter Search Delegate implementation sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
@huynguyennovem
huynguyennovem / clickable_text.dart
Created November 15, 2022 15:34
A common class ClickableText using in Flutter
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class ClickableText extends StatelessWidget {
final String? text;
final TextStyle? textStyle;
final Function? onTapAction;
const ClickableText({
Key? key,
@huynguyennovem
huynguyennovem / popup_menu_icon.dart
Created November 17, 2022 13:06
Flutter popup menu snippet code with icon leading and hand mouse cursor when hovering.
ListTile(
trailing: PopupMenuButton<String>(
icon: const Icon(Icons.filter_alt),
padding: EdgeInsets.zero,
onSelected: (value) {},
itemBuilder: (context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
enabled: false,
child: ListTile(
leading: Icon(Icons.filter_list_alt),