-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use path library, put more in api library
- Loading branch information
1 parent
a29a889
commit cb57586
Showing
8 changed files
with
59 additions
and
68 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 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,23 @@ | ||
extension IntHelper on int { | ||
static const int max = 9007199254740991; | ||
} | ||
|
||
extension NullableIntHelper on int? { | ||
int? add(int? value) { | ||
if (this == null || value == null) return null; | ||
return this! + value; | ||
} | ||
|
||
int? subtract(int? value) { | ||
if (this == null || value == null) return null; | ||
return this! - value; | ||
} | ||
} | ||
|
||
extension DoubleHelper on double { | ||
double toPrecision(int n) => double.parse(toStringAsFixed(n)); | ||
} | ||
|
||
extension NumHelper on num { | ||
bool inRange(num min, num max) => this >= min && this <= max; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
import 'package:dart_mappable/dart_mappable.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
part 'location.mapper.dart'; | ||
|
||
@MappableClass() | ||
class AssetLocation with AssetLocationMappable { | ||
final String remote; | ||
final String path; | ||
final bool absolute; | ||
|
||
const AssetLocation({ | ||
this.remote = '', | ||
required this.path, | ||
this.absolute = false, | ||
}); | ||
|
||
factory AssetLocation.local(String path, [bool absolute = false]) => | ||
AssetLocation(path: path, absolute: absolute); | ||
AssetLocation(path: path); | ||
|
||
static const empty = AssetLocation(path: ''); | ||
|
||
bool get isEmpty => path.isEmpty; | ||
|
||
bool get isRemote => remote.isNotEmpty; | ||
|
||
String get identifier => | ||
isRemote ? '$pathWithLeadingSlash@$remote' : pathWithLeadingSlash; | ||
String get identifier => isRemote ? '$path@$remote' : path; | ||
|
||
String get fileExtension => p.extension(path); | ||
|
||
String get fileName => p.basename(path); | ||
|
||
String get pathWithLeadingSlash => path.startsWith('/') ? path : '/$path'; | ||
String get fileNameWithoutExtension => p.basenameWithoutExtension(path); | ||
|
||
String get pathWithoutLeadingSlash => | ||
path.startsWith('/') ? path.substring(1) : path; | ||
String get parent => p.dirname(path); | ||
|
||
String get fileExtension => | ||
fileName.contains('.') ? fileName.split('.').last : ''; | ||
bool get absolute => p.isAbsolute(path); | ||
|
||
String get fileName => path.split('/').last; | ||
String get parent { | ||
final lastSlash = path.lastIndexOf('/'); | ||
if (lastSlash < 0) return ''; | ||
return path.substring(0, lastSlash); | ||
AssetLocation buildParentLocation() { | ||
return AssetLocation(path: parent, remote: remote); | ||
} | ||
|
||
bool isSame(AssetLocation other) => | ||
pathWithLeadingSlash == other.pathWithLeadingSlash && | ||
remote == other.remote; | ||
AssetLocation buildChildLocation(String child) { | ||
return AssetLocation(path: p.join(path, child), remote: remote); | ||
} | ||
|
||
AssetLocation buildSiblingLocation(String sibling) { | ||
return AssetLocation(path: p.join(parent, sibling), remote: remote); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,5 @@ | ||
import 'dart:ui'; | ||
|
||
extension NullableIntHelper on int? { | ||
int? add(int? value) { | ||
if (this == null || value == null) return null; | ||
return this! + value; | ||
} | ||
|
||
int? subtract(int? value) { | ||
if (this == null || value == null) return null; | ||
return this! - value; | ||
} | ||
} | ||
|
||
extension DoubleHelper on double { | ||
double toPrecision(int n) => double.parse(toStringAsFixed(n)); | ||
} | ||
|
||
int convertColor(int color, int alpha) => Color(color).withAlpha(alpha).value; | ||
int convertOldColor(int color, int old) => | ||
convertColor(color, Color(old).alpha); |