freedomlayer / built_union.dart Goto Github PK
View Code? Open in Web Editor NEWDart Union class (sum type)
License: BSD 3-Clause "New" or "Revised" License
Dart Union class (sum type)
License: BSD 3-Clause "New" or "Revised" License
Hi,
Is it possible to deserialize an object using attribte?
Suppose I have classes:
class Type1 {
string name;
string value;
string type;
BuiltList<Type1> types1;
}
class Type2 {
string name;
string value;
string type;
BuiltList<Type2> types2;
}
and I need to deserialize based on the attribute called "type". if type == "type1"
, the deserialized object must be of type Type1
, if type == "type2"
, the deserialized object must be of type Type2
.
Thanks
It is just blank there.
First of all great package!
If you use something like pedantic in your flutter/dart project you can receive linter warnings and errors to help improve productivity.
// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new
This can be...
specifiedType: const FullType(List, const [const FullType(Post)]))
changed to this...
specifiedType: const FullType(List, [FullType(Post)]))
If i don't use a serializer i get this warning for my HomeViewState union
The declaration '_$homeViewStateSerializer' isn't referenced.
Try removing the declaration of '_$homeViewStateSerializer'.
which comes from the serializer
Serializer<HomeViewState> _$homeViewStateSerializer =
new _$HomeViewStateSerializer();
Hello,
When I try to upgrade the packages, I get this error:
Because built_union_generator 0.1.3 depends on built_collection >=2.0.0 <5.0.0 and no versions of built_union_generator match >0.1.3 <0.2.0, built_union_generator ^0.1.3 requires built_collection >=2.0.0 <5.0.0.
Can we do upgrade built_collection, built_value and analyzer, please?
Hi,
I'd like to match my camel case attributes in Flutter with snake case attributes from the backend. this is done using wirename in BuiltValue.
For example, I have a field in Flutter called aInt
but the backend sends it as a_int
.
I have not found any way to do this in this lib, any help would be appreciated.
thanks.
Hi, I was trying to run the example given in the package. But when I run the code generator I get the following exception.
[SEVERE] built_union_generator:built_value on lib/models/union.dart:
An error `FormatterException` occurred while formatting the generated source for
`package:basicappl/models/union.dart`
which was output to
`lib/models/union.built_union.g.part`.
This may indicate an issue in the generator, the input source code, or in the
source formatter.
Could not format because the source could not be parsed:
line 20, column 28: Expected to find ')'.
╷
20 │ _$SimpleUnion.string(String* string): _type = _$SimpleUnionType.string, assert(string != null, '_$SimpleUnion constructor argument string can not be null!'), _values = [string];
│ ^
╵
line 24, column 25: Expected to find ')'.
╷
24 │ @required T Function(int*) integer,
│ ^
╵
line 101, column 66: Expected an identifier.
╷
101 │ serializers.serialize(integer, specifiedType: const FullType(int*))
│ ^
╵
line 108, column 142: Expected an identifier.
╷
108 │ serializers.serialize(tupleInt, specifiedType: const FullType(int*)),serializers.serialize(tupleString, specifiedType: const FullType(String*))
│ ^
╵
line 19, column 24: Expected to find ')'.
╷
19 │ _$SimpleUnion.tuple(int* tupleInt,String* tupleString): _type = _$SimpleUnionType.tuple, assert(tupleInt != null, '_$SimpleUnion constructor argument tupleInt can not be null!'), assert(tupleString != null, '_$SimpleUnion constructor argument tupleString can not be null!'), _values = [tupleInt,tupleString];
│ ^
╵
line 132, column 106: Expected an identifier.
╷
132 │ result = SimpleUnion.integer(serializers.deserialize(iterator.current, specifiedType: const FullType(int*)));
│ ^
╵
line 25, column 25: Expected to find ')'.
╷
25 │ @required T Function(int*,String*) tuple,
│ ^
╵
line 142, column 68: Expected an identifier.
╷
142 │ serializers.deserialize(tupleInt,specifiedType: const FullType(int*)),
│ ^
╵
line 26, column 28: Expected to find ')'.
╷
26 │ @required T Function(String*) string,
│ ^
╵
line 148, column 108: Expected an identifier.
╷
148 │ result = SimpleUnion.string(serializers.deserialize(iterator.current, specifiedType: const FullType(String*)));
│ ^
╵
This is the exact code in my model file
import 'package:built_union/built_union.dart';
import 'package:built_value/serializer.dart';
part 'union.g.dart';
@BuiltUnion()
class SimpleUnion extends _$SimpleUnion {
static Serializer<SimpleUnion> get serializer => _$simpleUnionSerializer;
SimpleUnion.empty() : super.empty();
SimpleUnion.integer(int integer) : super.integer(integer);
SimpleUnion.tuple(int tupleInt, String tupleString)
: super.tuple(tupleInt, tupleString);
SimpleUnion.string(String string) : super.string(string);
SimpleUnion.builtList(BuiltList<int> builtList) : super.builtList(builtList);
}
And these are dependencies I am using -
dependencies:
meta: ^1.2.3
built_union: ^0.1.3
dev_dependencies:
built_union_generator: ^0.1.3
build_runner: 1.10.1
built_value_generator: 7.1.0
Could you please let me know, what is causing this issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.