Created
March 1, 2019 15:10
-
-
Save PlugFox/e82d5eb910fbceeafaf2552b3635eeb0 to your computer and use it in GitHub Desktop.
Some BLoC sample (flutter)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:bloc/bloc.dart'; | |
//region СОБЫТИЯ | |
abstract class AppEvent {} | |
class SomeAppEvent extends AppEvent { | |
@override | |
String toString() => 'Некоторое действие над приложением'; | |
} | |
//endregion СОБЫТИЯ | |
//region СОСТОЯНИЯ | |
abstract class AppBS {} | |
class RunningAppBBS extends AppBS { | |
@override | |
String toString() => 'Приложение запущено'; | |
} | |
//endregion СОСТОЯНИЯ | |
// Перечисление режимов запуска приложения | |
enum enumBuildMode { | |
release | |
, profile | |
, debug | |
} | |
//region БЛоК приложения | |
class AppBloc extends Bloc<AppEvent, AppBS> { | |
@override | |
AppBS get initialState => RunningAppBBS(); | |
String get buildModeString => _getCurrentBuildMode().toString().split('.').last; | |
enumBuildMode get buildMode => _getCurrentBuildMode(); | |
// Конструктор | |
AppBloc(); | |
@override | |
Stream<AppBS> mapEventToState(AppBS currentState, AppEvent event) async* { | |
/// TODO: действия над приложением | |
yield RunningAppBBS(); | |
} | |
@override | |
void dispose() { | |
super.dispose(); | |
} | |
// Получить режим запуска приложения | |
enumBuildMode _getCurrentBuildMode() { | |
enumBuildMode result = (() { | |
if (const bool.fromEnvironment('dart.vm.product')) { | |
return enumBuildMode.release; | |
} | |
var result = enumBuildMode.profile; | |
assert(() { | |
result = enumBuildMode.debug; | |
return true; | |
}()); | |
return result; | |
}()); | |
return result; | |
} | |
} | |
//endregion БЛоК приложения |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment