Skip to content

Instantly share code, notes, and snippets.

View AlexKenbo's full-sized avatar
🎯
We will write a chat app =)

ALEKSANDR VASILEV AlexKenbo

🎯
We will write a chat app =)
View GitHub Profile
@AlexKenbo
AlexKenbo / snippets_1.dart
Created June 21, 2019 10:00
[Dart snippets]
//Разложить отсортированные дни по неделям
Map<int,List> _createDaysByWeeks(DateTime from, DateTime to) {
/*
vacations/$ID/daysByWeeks/$weekNum/[$weekDay..]
vacations/$ID/vacationDays/$ID_DAY:true если в этом дне что-то запланированно
{
'$weekNum': ['$weekDay1','$weekDay2'],
};
*/
@AlexKenbo
AlexKenbo / factory-method-pattern.dart
Created November 1, 2019 15:37
Класс Shape создает новые объекты своего типа с заданными параметрами
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == 'circle') return Circle(3);
if (type == 'square') return Square(2);
// To trigger exception, don't implement a check for 'triangle'.
throw 'Can\'t create $type.';
}
num get area;
@AlexKenbo
AlexKenbo / functional.dart
Created November 2, 2019 05:48
Functional programming in dart
String scream(int length) => "A${'a' * length}h!";
main() {
final values = [1, 2, 3, 5, 10, 50];
//Normal not functional:
print('Normal, not functional: ');
for (var length in values) {
print(scream(length));
}
@AlexKenbo
AlexKenbo / main.dart
Created January 30, 2020 06:33
Присвоение значений закрытым переменным класса в конструкторе
class Student{
var _id;
var _name;
Student({this._id, this._name}); // error - имена параметров не могут начинаться с _
void set id(int id) => _id = id;
void set name(String name) => _name = name;
}
@AlexKenbo
AlexKenbo / main.dart
Last active January 30, 2020 08:40
Singleton (design pattern). Что такое _приватный конструктор?
void main() {
Map<String,dynamic> bob = {
'name': 'Bob',
};
Map<String,dynamic> bobLike = {
'name': 'Bob',
};
if(bob == bobLike) {
@AlexKenbo
AlexKenbo / main.dart
Created January 31, 2020 16:15
Flutter design patterns - singleton
import 'package:flutter/material.dart';
abstract class ExampleStateBase {
@protected
String initialText;
@protected
String stateText;
String get currentText => stateText;
void setStateText(String text) {
@AlexKenbo
AlexKenbo / main.dart
Created February 8, 2020 09:49
When to use keys, part 1 - stataless
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(new MaterialApp(home: PositionedTiles()));
}
@AlexKenbo
AlexKenbo / main.dart
Created February 8, 2020 13:43
When to use keys, part 2 - statefull
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(new MaterialApp(home: PositionedTiles()));
}
@AlexKenbo
AlexKenbo / main.dart
Created February 8, 2020 17:59
When to use keys, part 2 - statefull no key
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(new MaterialApp(home: PositionedTiles()));
}
class PositionedTiles extends StatefulWidget {
@AlexKenbo
AlexKenbo / main.dart
Created February 9, 2020 15:10
flutter keys part 4
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(new MaterialApp(home: PositionedTiles()));
}