Skip to content

Instantly share code, notes, and snippets.

View pratikbutani's full-sized avatar
🎯
Exploring things

Pratik Butani pratikbutani

🎯
Exploring things
View GitHub Profile
@pratikbutani
pratikbutani / country-flag.json
Created October 9, 2020 10:05
A JSON for Country List with Flag Image
[
{
"flag": "https://twemoji.maxcdn.com/2/svg/1f1e6-1f1e8.svg",
"country": "Ascension Island",
"code": "ac"
},
{
"flag": "https://twemoji.maxcdn.com/2/svg/1f1e6-1f1e9.svg",
"country": "Andorra",
"code": "ad"
@pratikbutani
pratikbutani / PathUtils.java
Created September 9, 2019 05:53
Get Path from URI or URI from Path Utils.
public class PathUtils {
/**
* To get URI from Path
*
* @param context context
* @param file file
* @return Uri
*/
public static Uri getUriFromPath(Context context, File file) {
String filePath = file.getAbsolutePath();
@pratikbutani
pratikbutani / EndlessRecyclerOnScrollListener.java
Last active December 15, 2023 13:05
Endless RecyclerView OnScrollListener for pagination
public abstract class EndlessRecyclerViewScrollListener extends RecyclerView.OnScrollListener {
// The minimum amount of items to have below your current scroll position
// before loading more.
private int visibleThreshold = 5;
// The current offset index of data you have loaded
private int currentPage = 0;
// The total number of items in the dataset after the last load
private int previousTotalItemCount = 0;
@pratikbutani
pratikbutani / index.html
Last active March 7, 2023 17:56
Dart with HTML & CSS
<html>
<head>
<meta charset="UTF-8">
<title>Dart + HTML + CSS Example</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Click the button to change the color of the text!</h1>
<br><br>
<button id="colorButton">Change color</button>
@pratikbutani
pratikbutani / dart_isolation.dart
Created March 2, 2023 07:32
Dart Isolation Sample
import 'dart:isolate';
void main() async {
final receivePort = ReceivePort();
final isolate = await Isolate.spawn(doHeavyWork, receivePort.sendPort);
receivePort.listen((data) => print('Result: $data'));
}
void doHeavyWork(SendPort sendPort) {
// Perform some CPU-intensive work here
@pratikbutani
pratikbutani / TimePickerUniversal.java
Last active December 29, 2022 14:07
Android Universal TimePicker to set time with/without AM/PM.
/**
* Main file for Time Picker.
*/
public class TimePickerUniversal implements View.OnFocusChangeListener, TimePickerDialog.OnTimeSetListener, View.OnClickListener {
private EditText mEditText;
private Calendar mCalendar;
private SimpleDateFormat mFormat;
private boolean withAMPM;
@pratikbutani
pratikbutani / main.dart
Last active October 16, 2022 14:01
Change color of border & IconData in TextInput
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@pratikbutani
pratikbutani / main.dart
Last active October 16, 2022 13:51
StatefulBuilder Use case with AlertDialog
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@pratikbutani
pratikbutani / main.dart
Created October 13, 2022 13:07
BottomSheet with TextInputBox & Keyboard
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
@pratikbutani
pratikbutani / main.dart
Last active October 1, 2022 14:59
Round Container With Image in Flutter
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override