-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
183 additions
and
116 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:cabin_booking/model/cabin_elements/piano.dart'; | ||
|
||
abstract class _JsonFields { | ||
static const pianos = 'p'; | ||
static const lecterns = 'l'; | ||
static const chairs = 'c'; | ||
static const tables = 't'; | ||
} | ||
|
||
class CabinElements { | ||
late List<Piano> pianos; | ||
int lecterns; | ||
int chairs; | ||
int tables; | ||
|
||
CabinElements({ | ||
List<Piano>? pianos, | ||
this.lecterns = 0, | ||
this.chairs = 0, | ||
this.tables = 0, | ||
}) { | ||
this.pianos = pianos ?? <Piano>[]; | ||
} | ||
|
||
CabinElements.from(Map<String, dynamic> other) | ||
: pianos = (other[_JsonFields.pianos] as List<dynamic>) | ||
.map((piano) => Piano.from(piano)) | ||
.toList(), | ||
lecterns = other[_JsonFields.lecterns] as int, | ||
chairs = other[_JsonFields.chairs] as int, | ||
tables = other[_JsonFields.tables] as int; | ||
|
||
Map<String, dynamic> toJson() => { | ||
_JsonFields.pianos: pianos.map((piano) => piano.toJson()).toList(), | ||
_JsonFields.lecterns: lecterns, | ||
_JsonFields.chairs: chairs, | ||
_JsonFields.tables: tables, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
abstract class _JsonFields { | ||
static const brand = 'b'; | ||
static const model = 'm'; | ||
static const isElectronic = 'ie'; | ||
} | ||
|
||
class Piano { | ||
String? brand; | ||
String? model; | ||
bool isElectronic; | ||
|
||
Piano({ | ||
this.brand, | ||
this.model, | ||
this.isElectronic = false, | ||
}); | ||
|
||
Piano.from(Map<String, dynamic> other) | ||
: brand = other[_JsonFields.brand] as String?, | ||
model = other[_JsonFields.model] as String?, | ||
isElectronic = other[_JsonFields.isElectronic] as bool; | ||
|
||
Map<String, dynamic> toJson() => { | ||
_JsonFields.brand: brand, | ||
_JsonFields.model: model, | ||
_JsonFields.isElectronic: isElectronic, | ||
}; | ||
} |
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
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
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
Oops, something went wrong.