widget: use system defined corner radius
This commit is contained in:
parent
f8525db84e
commit
fdb34edf13
4 changed files with 13 additions and 4 deletions
|
@ -104,7 +104,11 @@ class HomeWidgetProvider : AppWidgetProvider() {
|
||||||
"drawEntryImage" to drawEntryImage,
|
"drawEntryImage" to drawEntryImage,
|
||||||
"reuseEntry" to reuseEntry,
|
"reuseEntry" to reuseEntry,
|
||||||
"isSystemThemeDark" to isNightModeOn,
|
"isSystemThemeDark" to isNightModeOn,
|
||||||
), object : MethodChannel.Result {
|
).apply {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
put("cornerRadiusPx", context.resources.getDimension(android.R.dimen.system_app_widget_background_radius))
|
||||||
|
}
|
||||||
|
}, object : MethodChannel.Result {
|
||||||
override fun success(result: Any?) {
|
override fun success(result: Any?) {
|
||||||
cont.resume(result)
|
cont.resume(result)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,13 @@ import 'package:aves_model/aves_model.dart';
|
||||||
import 'package:flutter/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
|
|
||||||
extension ExtraWidgetShape on WidgetShape {
|
extension ExtraWidgetShape on WidgetShape {
|
||||||
Path path(Size widgetSize, double devicePixelRatio) {
|
static const double _defaultCornerRadius = 24;
|
||||||
|
|
||||||
|
Path path(Size widgetSize, double devicePixelRatio, {double? cornerRadiusPx}) {
|
||||||
final rect = Offset.zero & widgetSize;
|
final rect = Offset.zero & widgetSize;
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case WidgetShape.rrect:
|
case WidgetShape.rrect:
|
||||||
return Path()..addRRect(BorderRadius.circular(24 * devicePixelRatio).toRRect(rect));
|
return Path()..addRRect(BorderRadius.circular(cornerRadiusPx ?? (_defaultCornerRadius * devicePixelRatio)).toRRect(rect));
|
||||||
case WidgetShape.circle:
|
case WidgetShape.circle:
|
||||||
return Path()
|
return Path()
|
||||||
..addOval(Rect.fromCircle(
|
..addOval(Rect.fromCircle(
|
||||||
|
|
|
@ -40,6 +40,7 @@ Future<Map<String, dynamic>> _drawWidget(dynamic args) async {
|
||||||
final widgetId = args['widgetId'] as int;
|
final widgetId = args['widgetId'] as int;
|
||||||
final widthPx = args['widthPx'] as int;
|
final widthPx = args['widthPx'] as int;
|
||||||
final heightPx = args['heightPx'] as int;
|
final heightPx = args['heightPx'] as int;
|
||||||
|
final cornerRadiusPx = args['cornerRadiusPx'] as double?;
|
||||||
final devicePixelRatio = args['devicePixelRatio'] as double;
|
final devicePixelRatio = args['devicePixelRatio'] as double;
|
||||||
final drawEntryImage = args['drawEntryImage'] as bool;
|
final drawEntryImage = args['drawEntryImage'] as bool;
|
||||||
final reuseEntry = args['reuseEntry'] as bool;
|
final reuseEntry = args['reuseEntry'] as bool;
|
||||||
|
@ -56,6 +57,7 @@ Future<Map<String, dynamic>> _drawWidget(dynamic args) async {
|
||||||
final bytes = await painter.drawWidget(
|
final bytes = await painter.drawWidget(
|
||||||
widthPx: widthPx,
|
widthPx: widthPx,
|
||||||
heightPx: heightPx,
|
heightPx: heightPx,
|
||||||
|
cornerRadiusPx: cornerRadiusPx,
|
||||||
outline: outline,
|
outline: outline,
|
||||||
shape: settings.getWidgetShape(widgetId),
|
shape: settings.getWidgetShape(widgetId),
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,6 +29,7 @@ class HomeWidgetPainter {
|
||||||
Future<Uint8List> drawWidget({
|
Future<Uint8List> drawWidget({
|
||||||
required int widthPx,
|
required int widthPx,
|
||||||
required int heightPx,
|
required int heightPx,
|
||||||
|
required double? cornerRadiusPx,
|
||||||
required Color? outline,
|
required Color? outline,
|
||||||
required WidgetShape shape,
|
required WidgetShape shape,
|
||||||
ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba,
|
ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba,
|
||||||
|
@ -45,7 +46,7 @@ class HomeWidgetPainter {
|
||||||
final recorder = ui.PictureRecorder();
|
final recorder = ui.PictureRecorder();
|
||||||
final rect = Offset.zero & widgetSizePx;
|
final rect = Offset.zero & widgetSizePx;
|
||||||
final canvas = Canvas(recorder, rect);
|
final canvas = Canvas(recorder, rect);
|
||||||
final path = shape.path(widgetSizePx, devicePixelRatio);
|
final path = shape.path(widgetSizePx, devicePixelRatio, cornerRadiusPx: cornerRadiusPx);
|
||||||
canvas.clipPath(path);
|
canvas.clipPath(path);
|
||||||
if (entryImage != null) {
|
if (entryImage != null) {
|
||||||
canvas.drawImage(entryImage, Offset(widgetSizePx.width - entryImage.width, widgetSizePx.height - entryImage.height) / 2, Paint());
|
canvas.drawImage(entryImage, Offset(widgetSizePx.width - entryImage.width, widgetSizePx.height - entryImage.height) / 2, Paint());
|
||||||
|
|
Loading…
Reference in a new issue