| Line 10: |
Line 10: |
| | <br /> | | <br /> |
| | | | |
| − | == Built Value Android Studio Live Templates == | + | ==Built Value Android Studio Live Templates== |
| | + | |
| | + | Inspired in: https://www.youtube.com/watch?v=Jji05a2GV_s |
| | + | |
| | File > Settings > Editor > Live Templates | | File > Settings > Editor > Live Templates |
| | | | |
| − | * Abbreviation blth | + | ===Built Value Header=== |
| − | * Description Built Value Header | + | |
| | + | *Abbreviation blth |
| | + | *Description Built Value Header |
| | <syntaxhighlight lang="dart"> | | <syntaxhighlight lang="dart"> |
| | library $LIBRARY$; | | library $LIBRARY$; |
| Line 23: |
Line 28: |
| | | | |
| | part '$LIBRARY$.g.dart'; | | part '$LIBRARY$.g.dart'; |
| | + | </syntaxhighlight> |
| | + | |
| | + | ===Built Value=== |
| | + | |
| | + | *Abbreviation blt |
| | + | *Description Built Value |
| | + | <syntaxhighlight lang="dart"> |
| | + | abstract class $NAME$ implements Built<$NAME$, $NAME$Builder> { |
| | + | /* fields go here. Examples: |
| | + | @nullable |
| | + | String get country; |
| | + | int get id; |
| | + | */ |
| | + | |
| | + | $NAME$._(); |
| | + | |
| | + | factory $NAME$([updates($NAME$Builder b)]) = _$$$NAME$; |
| | + | } |
| | + | </syntaxhighlight> |
| | + | |
| | + | ===Built Value Serialized=== |
| | + | |
| | + | *Abbreviation: blts |
| | + | *Description: Built Value Serializer |
| | + | *Edited Variables: INAME --> expresion: decapitalize(NAME) Skip if defined = True |
| | + | <syntaxhighlight lang="dart"> |
| | + | abstract class $NAME$ implements Built<$NAME$, $NAME$Builder> { |
| | + | /* fields go here. Examples: |
| | + | @nullable |
| | + | String get country; |
| | + | int get id; |
| | + | */ |
| | + | |
| | + | $NAME$._(); |
| | + | |
| | + | factory $NAME$([updates($NAME$Builder b)]) = _$$$NAME$; |
| | + | |
| | + | String toJson() { |
| | + | return json.encode(serializers.serializeWith($NAME$.serializer, this)); |
| | + | } |
| | + | |
| | + | static $NAME$ fromJson(String jsonString){ |
| | + | return serializers.deserializeWith($NAME$.serializer, json.decode(jsonString)); |
| | + | } |
| | + | |
| | + | static Serializer<$NAME$> get serializer => _$$$INAME$Serializer; |
| | + | } |
| | + | </syntaxhighlight>Requires a serializer, example: models/serializers.dart<syntaxhighlight lang="dart"> |
| | + | library serializers; |
| | + | |
| | + | import 'package:built_value/serializer.dart'; |
| | + | import 'package:actions_app/models/actionsPageModel.dart'; |
| | + | import 'package:built_value/standard_json_plugin.dart'; |
| | + | |
| | + | part 'serializers.g.dart'; |
| | + | |
| | + | @SerializersFor(const [ |
| | + | ActionsListPage, |
| | + | ]) |
| | + | final Serializers serializers = (_$serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); |
| | + | |
| | + | |
| | + | </syntaxhighlight><br /> |
| | + | ===Built Value Enum=== |
| | + | |
| | + | *Abbreviation: bltenum |
| | + | *Description: Built Value EnumClass |
| | + | <syntaxhighlight lang="dart"> |
| | + | class $NAME$ extends EnumClass { |
| | + | /* Fields go here examples: |
| | + | static const $NAME$ uno = _$$uno; |
| | + | */ |
| | + | |
| | + | const $NAME$._(String name) : super(name); |
| | + | static BuiltSet<$NAME$> get values => _$$values; |
| | + | static $NAME$ valueOf(String name) => _$$valueOf(name); |
| | + | } |
| | + | </syntaxhighlight> |
| | + | |
| | + | ===BLoC=== |
| | + | |
| | + | *Abbreviation: bloc |
| | + | *Description: Create a Business Logic Object Component<syntaxhighlight lang="dart"> |
| | + | import 'package:bloc/bloc.dart'; |
| | + | |
| | + | |
| | + | class $BLOC$ extends Bloc<$EVENT$, $STATE$> { //class MyBloc extends Bloc<MyEvent, MyState> |
| | + | @override |
| | + | $STATE$ get initialState => // TODO: implement initialState; |
| | + | |
| | + | @override |
| | + | Stream<$STATE$> mapEventToState($STATE$ currentState, $EVENT$ event) async* { |
| | + | // TODO: Implement mapEventToState |
| | + | } |
| | + | } |
| | </syntaxhighlight> | | </syntaxhighlight> |