-
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 GradientSwatch and GradOf
- Loading branch information
Showing
15 changed files
with
187 additions
and
45 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 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,7 +1,7 @@ | ||
/// Gradients | ||
/// | ||
/// Suitable classes for working with Flutter's Gradient Apis. | ||
library gradients; | ||
|
||
export 'src/gradient.dart'; | ||
export 'src/gradient_immu.dart'; | ||
export 'src/gradient_immut.dart'; | ||
export 'src/gradient_swatch.dart'; | ||
export 'src/material/grad_of.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 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,16 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:eo_color/src/palette.dart'; | ||
|
||
import 'gradient.dart'; | ||
import 'swatch_base.dart'; | ||
|
||
/// Convenience [Gradient] that retrieves an immutable list of colors. | ||
abstract class GradientImmut extends SwatchBase implements Gradient { | ||
/// [palettes] is a source of colors to be transformed into an immutable list. | ||
const GradientImmut(Iterable<Palette> palettes) : super(palettes); | ||
|
||
/// An **immutable list** of position-dependent colors — a color gradient. | ||
@override | ||
List<Color> get colors => List.unmodifiable(super.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,20 @@ | ||
import 'dart:ui'; | ||
|
||
import 'gradient.dart'; | ||
import 'swatch.dart'; | ||
|
||
/// A [Gradient] from a [Swatch] instance. | ||
abstract class GradientSwatch implements Gradient { | ||
/// A color gradient from a color [Swatch]. | ||
/// | ||
/// [growable] wheather or not to create a list that can grow (expand). | ||
const GradientSwatch(Swatch swatch, {bool growable = false}) | ||
: _swatch = swatch, | ||
_growable = growable; | ||
|
||
final Swatch _swatch; | ||
final bool _growable; | ||
|
||
@override | ||
List<Color> get colors => List.of(_swatch.colors, growable: _growable); | ||
} |
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,23 @@ | ||
import 'dart:ui'; | ||
|
||
import '../../gradient.dart'; | ||
import 'blue_greys.dart'; | ||
|
||
/// A gradient of ten shades of blue-grey. | ||
/// | ||
/// See also: [BlueGreys]. | ||
class BlueGreyGrad extends Gradient { | ||
/// Ten shades of blue-grey; the higher the index, the darker the color. | ||
/// | ||
/// Creates a growable list when [growable] is true; otherwise, it returns a | ||
/// fixed-length list. | ||
/// | ||
/// See also: [BlueGreys]. | ||
const BlueGreyGrad({bool growable = false}) : _growable = growable; | ||
|
||
static const _src = BlueGreys(); | ||
final bool _growable; | ||
|
||
@override | ||
List<Color> get colors => List.of(_src.colors, growable: _growable); | ||
} |
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,26 @@ | ||
import '../../swatches.dart'; | ||
import '../gradient_swatch.dart'; | ||
|
||
/// The gradient of the shades of a Material Design color. | ||
/// | ||
/// It produces a list of colors of fixed or growable length, ordered by the | ||
/// darkness of the colors: the higher the index, the darker the color. | ||
class GradOf extends GradientSwatch { | ||
/// A gradient of ten shades of blue-grey. | ||
/// | ||
/// See also: [BlueGreys]. | ||
const GradOf.blueGrey({bool growable = false}) | ||
: super(const BlueGreys(), growable: growable); | ||
|
||
/// A gradient of ten shades of brown. | ||
/// | ||
/// See also: [Browns]. | ||
const GradOf.brown({bool growable = false}) | ||
: super(const Browns(), growable: growable); | ||
|
||
/// A gradient of ten shades of grey. | ||
/// | ||
/// See also: [Greys]. | ||
const GradOf.grey({bool growable = false}) | ||
: super(const Greys(), growable: growable); | ||
} |
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
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,58 @@ | ||
import 'package:eo_color/src/material/blue_grey/blue_greys.dart'; | ||
import 'package:eo_color/src/material/brown/browns.dart'; | ||
import 'package:eo_color/src/material/grad_of.dart'; | ||
import 'package:eo_color/src/material/grey/greys.dart'; | ||
import 'package:eo_color/src/material/transparent.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('GradOf', () { | ||
final aColor = const Transparent().color; | ||
group('blueGrey:', () { | ||
final blueGreyGrad = const GradOf.blueGrey().colors; | ||
test('gradient', () { | ||
expect(blueGreyGrad, List.of(const BlueGreys().colors)); | ||
}); | ||
test('fixed-length list', () { | ||
/// Should not support adding colors to the list. | ||
expect(() => blueGreyGrad.add(aColor), throwsUnsupportedError); | ||
}); | ||
test('growable list', () { | ||
final growable = const GradOf.blueGrey(growable: true).colors; | ||
final prevLength = growable.length; | ||
growable.add(aColor); | ||
expect(growable.length, prevLength + 1); | ||
}); | ||
}); | ||
group('grey:', () { | ||
final greyGrad = const GradOf.grey().colors; | ||
test('gradient', () { | ||
expect(greyGrad, List.of(const Greys().colors)); | ||
}); | ||
test('fixed-length list', () { | ||
expect(() => greyGrad.add(aColor), throwsUnsupportedError); | ||
}); | ||
test('growable list', () { | ||
final growable = const GradOf.grey(growable: true).colors; | ||
final prevLength = growable.length; | ||
growable.add(aColor); | ||
expect(growable.length, prevLength + 1); | ||
}); | ||
}); | ||
group('brown:', () { | ||
final brownGrad = const GradOf.brown().colors; | ||
test('gradient', () { | ||
expect(brownGrad, List.of(const Browns().colors)); | ||
}); | ||
test('fixed-length list', () { | ||
expect(() => brownGrad.add(aColor), throwsUnsupportedError); | ||
}); | ||
test('growable list', () { | ||
final growable = const GradOf.brown(growable: true).colors; | ||
final prevLength = growable.length; | ||
growable.add(aColor); | ||
expect(growable.length, prevLength + 1); | ||
}); | ||
}); | ||
}); | ||
} |