Skip to content

Instantly share code, notes, and snippets.

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

Roi Peker roipeker

🏠
Working from home
View GitHub Profile
@roipeker
roipeker / main.dart
Created May 1, 2020 04:40
Dart's factory singleton
void main(List<String> arguments) {
var a1 = Storage();
var a2 = Storage();
print(a1.hashCode);
print(a2.hashCode);
print(a1==a2);
}
class Storage {
static final Storage _singleton = Storage._internal();
@roipeker
roipeker / main.dart
Created May 7, 2020 08:02
Quick currency formatter implementation test
import 'dart:math';
import 'package:intl/intl.dart';
void main(List<String> arguments) {
// Intl.defaultLocale = 'es_AR';
Intl.defaultLocale = 'en_US';
// Should be calculated only on locale change to modify the separators.
// -- start static implementation.
var base = NumberFormat.currency(decimalDigits: 1, symbol: '');
@roipeker
roipeker / main.dart
Last active May 23, 2020 03:53
Dart's variable hashCode to compare instances.
Future<void> main(List<String> arguments) async {
var a = Contacto('Mati');
var b = Contacto('Mati');
print('Contact son iguales? ${a == b}'); // false
var a2 = const Contacto('Mati');
var b2 = const Contacto('Mati');
print('const Contact son iguales? ${a2 == b2}'); // true
var a3 = Contacto2('Mati');
@roipeker
roipeker / main.dart
Last active June 8, 2020 14:04
TextController money format util.
// roipeker©2020
// demo codepen : https://codepen.io/roipeker/pen/oNbXRQz
// demo web : https://dev.roipeker.website/flutter_demos/textcontroller_currency/
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'text_controller_format.dart';
void main() {
@roipeker
roipeker / common_dropdown.dart
Last active June 18, 2020 15:52
A StatefulBuilder with a persistent value in State + some basic dropdown demo.
// roipeker 2020
// sample using ValueBuilder. Generic Dropdown wrapper with basic styling.
import 'package:flutter/material.dart';
import 'valuebuilder.dart';
class CommonDropDown<T> extends StatelessWidget {
final double height;
final List<T> listData;
@roipeker
roipeker / main.dart
Last active August 4, 2021 12:52
SliderText in the widget tree, shaders masks.
// roipeker 2020.
// Challenge from
// https://www.youtube.com/watch?v=HjJHO0NXI10&feature=share
//
// Demo screencast (macOS):
// https://giphy.com/gifs/WoG8316gEYY2EC1KRA
// Key code to use a shader mask in the widget tree:
import 'dart:convert';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
class PostController extends GetxController {
final _postList = <PostModel>[].obs;
List<PostModel> get postList => _postList.value;
final _isLoading = false.obs;
bool get isLoading => _isLoading.value;
@roipeker
roipeker / getx_todo_list.dart
Created August 27, 2020 02:56
Sample GetX todo list.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class SampleTodoDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
home: TodoPage(),
);
}
@roipeker
roipeker / get_utils.dart
Created August 27, 2020 13:09
Base UI utils for GetX (wip)
class AppGetUtils {
static bool isPreloading = false;
static Future<void> hidePreloader() async {
if (!isPreloading) return;
isPreloading = false;
if (!Get.isSnackbarOpen) {
Get.close(1);
}
}
@roipeker
roipeker / main.dart
Created August 27, 2020 13:28
GetX minimal sample bottom navbar.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class SampleBottomNavDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
themeMode: ThemeMode.dark,
debugShowCheckedModeBanner: false,
theme: ThemeData.light(),