Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f187cd4
update CHANGELOG.md
mzdm Feb 13, 2021
52576e2
add package to package list in the base README.md
mzdm Feb 13, 2021
b8d221c
migrate lib
mzdm Feb 13, 2021
b5d8bd4
migrate example
mzdm Feb 13, 2021
5bfa13c
add an argument for running integration tests
mzdm Feb 13, 2021
930a4d8
correct sorting
mzdm Feb 13, 2021
5d8c667
migrate lib
mzdm Feb 14, 2021
e4df198
migrate lib tests
mzdm Feb 14, 2021
86277a0
update CHANGELOG.md
mzdm Feb 14, 2021
5c54b9f
migrate app example
mzdm Feb 14, 2021
20e26a3
[pointer_interceptor] Revert "correct sorting"
mzdm Feb 14, 2021
b397fae
[pointer_interceptor] Revert "add an argument for running integration…
mzdm Feb 14, 2021
b7a73e2
[pointer_interceptor] Revert "migrate example"
mzdm Feb 14, 2021
36460a3
[pointer_interceptor] Revert "migrate lib"
mzdm Feb 14, 2021
46ce68e
[pointer_interceptor] Revert "add package to package list in the base…
mzdm Feb 14, 2021
9f0a365
[pointer_interceptor] Revert "update CHANGELOG.md"
mzdm Feb 14, 2021
e6ea988
some reviews fixes
mzdm Feb 16, 2021
bbb0547
review: make histogram non-nullable
mzdm Feb 16, 2021
00306fb
Revert "review: make histogram non-nullable"
mzdm Feb 16, 2021
d05a75c
remove null type references from the docs
mzdm Feb 16, 2021
8495164
review: an attempt to make PaletteColor non-nullable
mzdm Feb 17, 2021
c6c1891
review: #289 landed
mzdm Feb 18, 2021
0d9a578
review: an attempt to make PaletteColor non-nullable - tests
mzdm Feb 18, 2021
1c3ed84
review: #289 landed - change version in CHANGELOG.md
mzdm Feb 18, 2021
44cdf50
review: an attempt to make PaletteColor non-nullable - formatting
mzdm Feb 18, 2021
154115f
Merge remote-tracking branch 'upstream/master' into nnbd-palette-gen
mzdm Feb 18, 2021
419e6f7
bump SDK constraint
mzdm Feb 24, 2021
84ebdd8
formatting
mzdm Feb 24, 2021
83c569c
review: change docs
mzdm Feb 24, 2021
df2c2c0
review: Revert breaking changes
mzdm Feb 26, 2021
9d242dc
review: make PaletteColor map non-nullable
mzdm Feb 26, 2021
0855080
review: minor doc change
mzdm Feb 26, 2021
72def04
Revert "review: minor doc change"
mzdm Feb 26, 2021
97b91ed
bump ver to stable null safety
mzdm Mar 5, 2021
b42f619
review: histogram non-nullable
mzdm Mar 5, 2021
50a4b30
review: fixes
mzdm Mar 5, 2021
3e6578f
review: update pubspec.yaml example
mzdm Mar 8, 2021
c50376e
review: address comments
mzdm Mar 8, 2021
4af0d6b
formatting
mzdm Mar 8, 2021
d5e675e
revert changes to dominant color
mzdm Mar 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/palette_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0

* Migrated to null safety.

## 0.2.4+1

* Removed a `dart:async` import that isn't required for \>=Dart 2.1.
Expand Down
93 changes: 52 additions & 41 deletions packages/palette_generator/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ class MyApp extends StatelessWidget {
class ImageColors extends StatefulWidget {
/// Creates the home page.
const ImageColors({
Key key,
Key? key,
this.title,
this.image,
required this.image,
this.imageSize,
}) : super(key: key);

/// The title that is shown at the top of the page.
final String title;
final String? title;

/// This is the image provider that is used to load the colors from.
final ImageProvider image;

/// The dimensions of the image.
final Size imageSize;
final Size? imageSize;

@override
_ImageColorsState createState() {
Expand All @@ -63,22 +63,24 @@ class ImageColors extends StatefulWidget {
}

class _ImageColorsState extends State<ImageColors> {
Rect region;
Rect dragRegion;
Offset startDrag;
Offset currentDrag;
PaletteGenerator paletteGenerator;
Rect? region;
Rect? dragRegion;
Offset? startDrag;
Offset? currentDrag;
PaletteGenerator? paletteGenerator;

final GlobalKey imageKey = GlobalKey();

@override
void initState() {
super.initState();
region = Offset.zero & widget.imageSize;
if (widget.imageSize != null) {
region = Offset.zero & widget.imageSize!;
}
_updatePaletteGenerator(region);
}

Future<void> _updatePaletteGenerator(Rect newRegion) async {
Future<void> _updatePaletteGenerator(Rect? newRegion) async {
paletteGenerator = await PaletteGenerator.fromImageProvider(
widget.image,
size: widget.imageSize,
Expand All @@ -90,20 +92,21 @@ class _ImageColorsState extends State<ImageColors> {

// Called when the user starts to drag
void _onPanDown(DragDownDetails details) {
final RenderBox box = imageKey.currentContext.findRenderObject();
final RenderBox box =
imageKey.currentContext!.findRenderObject() as RenderBox;
final Offset localPosition = box.globalToLocal(details.globalPosition);
setState(() {
startDrag = localPosition;
currentDrag = startDrag;
dragRegion = Rect.fromPoints(startDrag, currentDrag);
currentDrag = localPosition;
dragRegion = Rect.fromPoints(localPosition, localPosition);
});
}

// Called as the user drags: just updates the region, not the colors.
void _onPanUpdate(DragUpdateDetails details) {
setState(() {
currentDrag += details.delta;
dragRegion = Rect.fromPoints(startDrag, currentDrag);
currentDrag = currentDrag! + details.delta;
dragRegion = Rect.fromPoints(startDrag!, currentDrag!);
});
}

Expand All @@ -118,11 +121,16 @@ class _ImageColorsState extends State<ImageColors> {

// Called when the drag ends. Sets the region, and updates the colors.
Future<void> _onPanEnd(DragEndDetails details) async {
Rect newRegion =
(Offset.zero & imageKey.currentContext.size).intersect(dragRegion);
if (newRegion.size.width < 4 && newRegion.size.width < 4) {
newRegion = Offset.zero & imageKey.currentContext.size;
final Size? imageSize = imageKey.currentContext?.size;
Rect? newRegion;

if (imageSize != null) {
newRegion = (Offset.zero & imageSize).intersect(dragRegion!);
if (newRegion.size.width < 4 && newRegion.size.width < 4) {
newRegion = Offset.zero & imageSize;
}
}

await _updatePaletteGenerator(newRegion);
setState(() {
region = newRegion;
Expand All @@ -136,7 +144,7 @@ class _ImageColorsState extends State<ImageColors> {
return Scaffold(
backgroundColor: _kBackgroundColor,
appBar: AppBar(
title: Text(widget.title),
title: Text(widget.title ?? ''),
),
body: Column(
mainAxisSize: MainAxisSize.max,
Expand All @@ -155,8 +163,8 @@ class _ImageColorsState extends State<ImageColors> {
Image(
key: imageKey,
image: widget.image,
width: widget.imageSize.width,
height: widget.imageSize.height,
width: widget.imageSize?.width,
height: widget.imageSize?.height,
),
// This is the selection rectangle.
Positioned.fromRect(
Expand Down Expand Up @@ -189,19 +197,20 @@ class PaletteSwatches extends StatelessWidget {
///
/// The [generator] is optional. If it is null, then the display will
/// just be an empty container.
const PaletteSwatches({Key key, this.generator}) : super(key: key);
const PaletteSwatches({Key? key, this.generator}) : super(key: key);

/// The [PaletteGenerator] that contains all of the swatches that we're going
/// to display.
final PaletteGenerator generator;
final PaletteGenerator? generator;

@override
Widget build(BuildContext context) {
final List<Widget> swatches = <Widget>[];
if (generator == null || generator.colors.isEmpty) {
final PaletteGenerator? paletteGen = generator;
if (paletteGen == null || paletteGen.colors.isEmpty) {
return Container();
}
for (Color color in generator.colors) {
for (Color color in paletteGen.colors) {
swatches.add(PaletteSwatch(color: color));
}
return Column(
Expand All @@ -213,17 +222,18 @@ class PaletteSwatches extends StatelessWidget {
children: swatches,
),
Container(height: 30.0),
PaletteSwatch(label: 'Dominant', color: generator.dominantColor?.color),
PaletteSwatch(
label: 'Light Vibrant', color: generator.lightVibrantColor?.color),
PaletteSwatch(label: 'Vibrant', color: generator.vibrantColor?.color),
label: 'Dominant', color: paletteGen.dominantColor?.color),
PaletteSwatch(
label: 'Light Vibrant', color: paletteGen.lightVibrantColor?.color),
PaletteSwatch(label: 'Vibrant', color: paletteGen.vibrantColor?.color),
PaletteSwatch(
label: 'Dark Vibrant', color: generator.darkVibrantColor?.color),
label: 'Dark Vibrant', color: paletteGen.darkVibrantColor?.color),
PaletteSwatch(
label: 'Light Muted', color: generator.lightMutedColor?.color),
PaletteSwatch(label: 'Muted', color: generator.mutedColor?.color),
label: 'Light Muted', color: paletteGen.lightMutedColor?.color),
PaletteSwatch(label: 'Muted', color: paletteGen.mutedColor?.color),
PaletteSwatch(
label: 'Dark Muted', color: generator.darkMutedColor?.color),
label: 'Dark Muted', color: paletteGen.darkMutedColor?.color),
],
);
}
Expand All @@ -234,19 +244,20 @@ class PaletteSwatches extends StatelessWidget {
class PaletteSwatch extends StatelessWidget {
/// Creates a PaletteSwatch.
///
/// If the [color] argument is omitted, then the swatch will show a
/// placeholder instead, to indicate that there is no color.
/// If the [paletteColor] has property `isTargetColorFound` as `false`,
/// then the swatch will show a placeholder instead, to indicate
/// that there is no color.
const PaletteSwatch({
Key key,
Key? key,
this.color,
this.label,
}) : super(key: key);

/// The color of the swatch. May be null.
final Color color;
/// The color of the swatch.
final Color? color;

/// The optional label to display next to the swatch.
final String label;
final String? label;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -292,7 +303,7 @@ class PaletteSwatch extends StatelessWidget {
children: <Widget>[
swatch,
Container(width: 5.0),
Text(label),
Text(label!),
],
),
);
Expand Down
13 changes: 5 additions & 8 deletions packages/palette_generator/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: image_colors
description: A simple example of how to use the PaletteGenerator to load the palette from an image file.

publish_to: none
version: 0.1.0

publish_to: none
environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
cupertino_icons: ^0.1.2
flutter:
sdk: flutter
palette_generator:
path: ..
path: ../

dev_dependencies:
flutter_test:
Expand All @@ -19,7 +19,4 @@ dev_dependencies:
flutter:
uses-material-design: true
assets:
- assets/landscape.png

environment:
sdk: ">=2.2.0 <3.0.0"
- assets/landscape.png
Loading