Skip to content

Instantly share code, notes, and snippets.

View LeBaleiro's full-sized avatar

Leticia Baleiro LeBaleiro

View GitHub Profile
@LeBaleiro
LeBaleiro / 1.open_closed_principle.MD
Last active September 3, 2023 22:04
Open Closed Principle

This is an example of the open closed principle. The first file (2.non_ocp.dart) shows an example not using the principle and the second (3.using_ocp.dart) shows a refactor of it using the principle.

import 'package:flutter_test/flutter_test.dart';
void main() {
test('should edit the original map as default', () {
final mockMap = {"item1": "value1"};
expect(mockMap, {"item1": "value1"});
removeFirstItemFromOriginalMap(mockMap);
expect(mockMap, {});
});
test('should create a new reference and shouldn\'t edit the original map',
@LeBaleiro
LeBaleiro / !clean_code.md
Last active October 13, 2022 16:03
Clean Code - Dart Examples
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@LeBaleiro
LeBaleiro / dartlists.md
Last active October 12, 2022 20:16
Dart Lists

For the Dart language when we pass a List to a function as a parameter we pass its reference by default, which means we are passing and editing the original list.

This may cause confusion because it doesn't follow the same pattern in all languages, the Solitity language is an example of how this could be the oposite as default.

In the first test of the following example we can see how this happens and in the second test we see how to avoid it by simply calling .toList() at the end of the original List, creating a new reference by doing this.

To open this example on dartpad, follow dartpad link

The same applies to Maps, here are the examples: dartpad link

@LeBaleiro
LeBaleiro / web3.md
Last active June 7, 2022 22:26
Web3 + Flutter
@LeBaleiro
LeBaleiro / flutterweb.md
Last active October 23, 2022 13:13
Flutter Web
@LeBaleiro
LeBaleiro / custom_either.dart
Created November 29, 2021 20:10
Custom Either
import 'failure.dart';
class NoParams {
const NoParams._();
}
const noParams = NoParams._();
class NoResponse {
const NoResponse._();
@LeBaleiro
LeBaleiro / questions_marks.dart
Created September 28, 2021 16:44
Questions Marks
// Have the function QuestionsMarks(str) take the str string parameter, which will contain single digit numbers, letters, and question marks, and check if there are exactly 3 question marks between every pair of two numbers that add up to 10. If so, then your program should return the string true, otherwise it should return the string false. If there aren't any two numbers that add up to 10 in the string, then your program should return false as well.
// For example: if str is "arrb6???4xxbl5???eee5" then your program should return true because there are exactly 3 question marks between 6 and 4, and 3 question marks between 5 and 5 at the end of the string.
// Examples
// Input: "aa6?9"
// Output: false
// Input: "acc?7??sss?3rr1??????5"
// Output: true
// Input: "bbb???2sa??aa?8"