Changes

Jump to navigation Jump to search
2,215 bytes added ,  15:44, 28 October 2019
m
Line 11: Line 11:     
==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
   −
=== Built Value Header ===
+
===Built Value Header===
    
*Abbreviation blth
 
*Abbreviation blth
Line 27: Line 30:  
</syntaxhighlight>
 
</syntaxhighlight>
   −
=== Built Value ===
+
===Built Value===
   −
* Abbreviation blt
+
*Abbreviation blt
* Description Built Value
+
*Description Built Value
 
<syntaxhighlight lang="dart">
 
<syntaxhighlight lang="dart">
 
abstract class $NAME$ implements Built<$NAME$, $NAME$Builder> {
 
abstract class $NAME$ implements Built<$NAME$, $NAME$Builder> {
   // fields go here
+
   /* fields go here. Examples:
 +
  @nullable
 +
  String get country;
 +
  int get id;
 +
  */
 
    
 
    
 
   $NAME$._();
 
   $NAME$._();
 
    
 
    
 
   factory $NAME$([updates($NAME$Builder b)]) = _$$$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>

Navigation menu