-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Added the ability to link with Form.
- Loading branch information
Showing
4 changed files
with
95 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
part of masamune; | ||
|
||
/// Extension methods for [FormMediaValue]. | ||
/// | ||
/// [FormMediaValue]の拡張メソッドです。 | ||
extension FormMediaValueExtensions on FormMediaValue { | ||
/// Convert to [ModelImageUri]. | ||
/// | ||
/// If [path] is empty, null is returned. | ||
/// | ||
/// Returns an error if the original [FormMediaType] is not [FormMediaType.image]. | ||
/// | ||
/// [ModelImageUri]に変換します。 | ||
/// | ||
/// [path]が空の場合はnullを返します。 | ||
/// | ||
/// 元の[FormMediaType]が[FormMediaType.image]でない場合はエラーを返します。 | ||
ModelImageUri? toModelImageUri() { | ||
if (path.isEmpty) { | ||
return null; | ||
} | ||
final uri = Uri.tryParse(path!); | ||
if (uri == null) { | ||
return null; | ||
} | ||
if (type != FormMediaType.image) { | ||
throw Exception("The original FormMediaType is not FormMediaType.image"); | ||
} | ||
return ModelImageUri(uri); | ||
} | ||
|
||
/// Convert to [ModelVideoUri]. | ||
/// | ||
/// If [path] is empty, null is returned. | ||
/// | ||
/// Returns an error if the original [FormMediaType] is not [FormMediaType.video]. | ||
/// | ||
/// [ModelVideoUri]に変換します。 | ||
/// | ||
/// [path]が空の場合はnullを返します。 | ||
/// | ||
/// 元の[FormMediaType]が[FormMediaType.video]でない場合はエラーを返します。 | ||
ModelVideoUri? toModelVideoUri() { | ||
if (path.isEmpty) { | ||
return null; | ||
} | ||
final uri = Uri.tryParse(path!); | ||
if (uri == null) { | ||
return null; | ||
} | ||
if (type != FormMediaType.video) { | ||
throw Exception("The original FormMediaType is not FormMediaType.video"); | ||
} | ||
return ModelVideoUri(uri); | ||
} | ||
} |
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