-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create Gradient and GradientImmu
Closes #83
- Loading branch information
Showing
9 changed files
with
109 additions
and
1 deletion.
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 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,7 @@ | ||
/// Gradients | ||
/// | ||
/// Suitable classes for working with Flutter's Gradient Apis. | ||
library gradients; | ||
|
||
export 'src/gradient.dart'; | ||
export 'src/gradient_immu.dart'; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'dart:ui'; | ||
|
||
import 'swatch.dart'; | ||
|
||
/// Represents a color gradient. | ||
/// | ||
/// A Color Gradient specifies a range of position-dependent colors, usually | ||
/// used to fill a region. For example, many window managers allow the screen | ||
/// background to be specified as a gradient. The colors produced by a gradient | ||
/// vary continuously with position, producing smooth color transitions. | ||
/// | ||
/// See also: | ||
/// - [color-gradient](https://en.wikipedia.org/wiki/Color_gradient) | ||
abstract class Gradient implements Swatch { | ||
/// A list of position-dependent colors — a color gradient. | ||
@override | ||
List<Color> get colors; | ||
} |
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,22 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:eo_color/src/palette.dart'; | ||
|
||
import 'gradient.dart'; | ||
import 'swatch_base.dart'; | ||
|
||
/// Convenience [Gradient]. | ||
/// | ||
/// It retrieves an immutable list of colors. | ||
abstract class GradientImmu extends SwatchBase implements Gradient { | ||
/// [palettes] is the iterable of colors to be turned into an immutable list. | ||
const GradientImmu(Iterable<Palette> palettes) : super(palettes); | ||
|
||
/// An **immutable list** of position-dependent colors — a color gradient. | ||
@override | ||
List<Color> get colors => List.unmodifiable(super.colors); | ||
|
||
/// Forwards to [colors]. | ||
@override | ||
List<Color> call() => colors; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:eo_color/eo_color.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
const aGrey = [Grey()]; | ||
const manyGreys = [ | ||
Grey.light(), | ||
Grey.bitLighter(), | ||
Grey(), | ||
Grey.bitDarker(), | ||
Grey.dark(), | ||
]; | ||
|
||
class GradTest extends GradientImmu { | ||
const GradTest.empty() : super(const []); | ||
const GradTest.single() : super(aGrey); | ||
const GradTest.many() : super(manyGreys); | ||
} | ||
|
||
void main() { | ||
group('GradientImmu class', () { | ||
test('empty', () { | ||
const emptyList = GradTest.empty(); | ||
expect(emptyList.colors.isEmpty, true); | ||
}); | ||
test('single', () { | ||
const singleElem = GradTest.single(); | ||
expect(singleElem.colors.length, 1); | ||
expect(singleElem().first, aGrey.first.color); | ||
}); | ||
test('many', () { | ||
const manyElems = GradTest.many(); | ||
expect(manyElems.colors.length, manyGreys.length); | ||
expect(manyElems.colors, manyGreys.map((p) => p.color).toList()); | ||
}); | ||
test('immutability', () { | ||
final emptyImmuList = const GradTest.empty().colors; | ||
expect( | ||
() => emptyImmuList.add(const Transparent().color), | ||
throwsUnsupportedError, | ||
); | ||
final singleElemImmuList = const GradTest.single().colors; | ||
expect( | ||
() => singleElemImmuList.add(const Transparent().color), | ||
throwsUnsupportedError, | ||
); | ||
final manyElemsImmuList = const GradTest.many().colors; | ||
expect( | ||
() => manyElemsImmuList.add(const Transparent().color), | ||
throwsUnsupportedError, | ||
); | ||
}); | ||
}); | ||
} |