Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update flutter_ume_kit_ui #107

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
9 changes: 9 additions & 0 deletions kits/flutter_ume_kit_ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.1.1

* image: ^3.0.5 升级到 image: ^4.0.15

* quiver: ^3.0.1 升级到 quiver: ^3.2.1

* mockito: ^5.0.12 升级到 mockito: ^5.3.2
p709723778 marked this conversation as resolved.
Show resolved Hide resolved


## 1.1.0

* 适配 Flutter 3.7,不兼容旧版本的适配
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:typed_data';
import 'dart:ui' as ui;

p709723778 marked this conversation as resolved.
Show resolved Hide resolved
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:image/image.dart' as img;
import 'package:flutter_ume/flutter_ume.dart';
import 'package:image/image.dart' as img;
p709723778 marked this conversation as resolved.
Show resolved Hide resolved

import 'icon.dart' as icon;

class ColorSucker extends StatefulWidget implements Pluggable {
Expand Down Expand Up @@ -129,15 +131,11 @@ class _ColorSuckerState extends State<ColorSucker> {
if (_snapshot == null) return;
double px = globalPosition.dx;
double py = globalPosition.dy;
int pixel32 = _snapshot!.getPixelSafe(px.toInt(), py.toInt());
int hex = _abgrToArgb(pixel32);
_currentColor = Color(hex);
}

int _abgrToArgb(int argbColor) {
int r = (argbColor >> 16) & 0xFF;
int b = argbColor & 0xFF;
return (argbColor & 0xFF00FF00) | (b << 16) | r;
img.Pixel pixel = _snapshot!.getPixelSafe(px.toInt(), py.toInt());

_currentColor = Color.fromARGB(
pixel.a.toInt(), pixel.r.toInt(), pixel.g.toInt(), pixel.b.toInt());
}

@override
Expand Down
35 changes: 15 additions & 20 deletions kits/flutter_ume_kit_ui/lib/third_party/cyclop/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'dart:async';
import 'dart:ui' as ui;

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:image/image.dart' as img;

//bool get isPhoneScreen => !(screenSize.shortestSide >= 600);

Size get screenSize => ui.window.physicalSize / ui.window.devicePixelRatio;
Expand Down Expand Up @@ -92,36 +91,32 @@ List<Color> getPixelColors(
),
);

Color getPixelColor(img.Image image, Offset offset) => (offset.dx >= 0 &&
offset.dy >= 0 &&
offset.dx < image.width &&
offset.dy < image.height)
? abgr2Color(image.getPixel(offset.dx.toInt(), offset.dy.toInt()))
: const Color(0x00000000);
ui.Color getPixelColor(img.Image image, Offset offset) {
img.Pixel pixel = image.getPixelSafe(offset.dx.toInt(), offset.dy.toInt());

return (offset.dx >= 0 &&
offset.dy >= 0 &&
offset.dx < image.width &&
offset.dy < image.height)
? Color.fromARGB(
pixel.a.toInt(), pixel.r.toInt(), pixel.g.toInt(), pixel.b.toInt())
: const Color(0x00000000);
}

ui.Offset _offsetFromIndex(int index, int numColumns) => Offset(
(index % numColumns).toDouble(),
((index ~/ numColumns) % numColumns).toDouble(),
);

Color abgr2Color(int value) {
final a = (value >> 24) & 0xFF;
final b = (value >> 16) & 0xFF;
final g = (value >> 8) & 0xFF;
final r = (value >> 0) & 0xFF;

return Color.fromARGB(a, r, g, b);
}

Future<img.Image?> repaintBoundaryToImage(
RenderRepaintBoundary renderer,
) async {
try {
final rawImage = await renderer.toImage(pixelRatio: 1);
final byteData =
await rawImage.toByteData(format: ui.ImageByteFormat.rawRgba);
final byteData = await rawImage.toByteData(format: ui.ImageByteFormat.png);
final pngBytes = byteData!.buffer.asUint8List();
return img.Image.fromBytes(rawImage.width, rawImage.height, pngBytes);

return img.decodeImage(pngBytes);
} catch (err) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:ui';

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:image/image.dart' as img;
Expand Down
8 changes: 4 additions & 4 deletions kits/flutter_ume_kit_ui/lib/third_party/cyclop/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ environment:
dependencies:
flutter:
sdk: flutter
image: ^3.0.5
quiver: ^3.0.1
basics: ^0.6.0
image: ^4.0.15
quiver: ^3.2.1
basics: ^0.10.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.4
flutter_lints: ^2.0.1

flutter:
10 changes: 5 additions & 5 deletions kits/flutter_ume_kit_ui/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_ume_kit_ui
description: UI Kits for flutter_ume.
version: 1.1.0
version: 1.1.1
homepage: https://github.com/bytedance/flutter_ume

environment:
Expand All @@ -13,15 +13,15 @@ dependencies:
flutter_ume: ">=1.0.0 <2.0.0"
touch_indicator: ^2.0.0

# for Cyclop
image: ^3.0.5
quiver: ^3.0.1
# for Cyclops
p709723778 marked this conversation as resolved.
Show resolved Hide resolved
image: ^4.0.15
quiver: ^3.2.1
basics: ">=0.6.0 <0.11.0"

dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.12
mockito: ^5.3.2
flutter_coverage_badge:
git:
url: https://github.com/smileShirely/flutter_coverage_badge.git
Expand Down