Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Diefferson Santos diefferson

🎯
Focusing
View GitHub Profile
View cnpj.dart
class CNPJ {
// Formatar número de CNPJ
static String? format(String? cnpj) {
if (cnpj == null) return null;
// Obter somente os números do CNPJ
final numbers = cnpj.replaceAll(RegExp(r'[^0-9]'), '');
// Testar se o CNPJ possui 14 dígitos
if (numbers.length != 14) return cnpj;
View finance_utils.dart
import 'dart:math';
class FinanceUtils {
FinanceUtils._();
///Calcula o pagamento periódico de um investimento anual,
///com base em pagamentos periódicos e constantes
///e em uma taxa de juros constante.
static double calcPmt({
required double amount,
@diefferson
diefferson / genericSort.kt
Created Mar 11, 2022
Generic sort by field
View genericSort.kt
package br.com.juno.domain.utils
data class Item (val id:Int, val name: String)
enum class ItemSortBy {
ID,
NAME
}
fun List<Item>.sortByField(field: ItemSortBy): List<Item> {
View mvvmp_example.dart
import 'package:base/base.dart';
import 'package:flutter/material.dart';
class MyScreen extends StatefulWidget {
@override
_MyScreenState createState() => _MyScreenState();
}
class _MyScreenState extends BaseState<MyScreen, MyPresenter>
with MyScreenActions {
View base_state.dart
class BaseState {
BaseState._();
factory BaseState.success(dynamic data) = SuccessState;
factory BaseState.error(NoodleException error) = ErrorState;
factory BaseState.loading() = LoadingState;
factory BaseState.done() = DoneState;
}
@diefferson
diefferson / disposable.dart
Created Jun 8, 2021
Stark Disposable Interface
View disposable.dart
import 'package:stark/stark.dart';
class LoginViewModel implements Disposable {
@override
dispose(){
//this method is called when the LoginViewModel is diposed, use to dispose your RX Subjects or Streams
}
}
View home.dart
import 'package:flutter/material.dart';
import 'package:stark/stark.dart';
class _MyHomePageState extends State<MyHomePage> with StarkComponent {
late ViewModel _viewModel;
@override
void initState() {
super.initState();
_viewModel = get<ViewModel>();
View get_injections.dart
import 'package:stark/stark.dart';
// get simple injection
final MyUseCase useCase = Stark.get();
final useCase = Stark.get<MyUseCase>();
// get named injection
final api = Stark.get<Api>(named: "DEFAULT");
// get injection passing params
View app.dart
import 'package:flutter/material.dart';
import 'package:stark/stark.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
void initStark() {
Stark.init(
[
View module_params.dart
import 'package:stark/stark.dart';
final myModule = {
singleWithParams((i,p) => Api(p["token"])),
factoryWithParams((i,p) => MyPresenter(p["view"])),
};