ABausG / home_widget

Flutter Package for Easier Creation of Home Screen Widgets
785 stars 218 forks source link

`pixelRatio` for rendered Flutter widget should default to the device's pixel ratio #205

Open ueman opened 10 months ago

ueman commented 10 months ago

When creating screenshot widget with

var path = await HomeWidget.renderFlutterWidget(
  const LineChart(),
  key: 'lineChart',
  logicalSize: const Size(400, 400),
  pixelRatio: 3,
);

You're able to set a pixelRatio. This should default to whatever is set in MediaQueryData.devicePixelRatio. Another way of accessing that data should be possible via the PlatformDispatcher.instance.implicitView.devicePixelRatio.

It should default to whatever the current device pixelratio is, since otherways I always have to manually set it to that value. So by doing this already inside the app, it improves the quality of life of the users.

So this

var path = await HomeWidget.renderFlutterWidget(
  const LineChart(),
  key: 'lineChart',
  logicalSize: const Size(400, 400),
  pixelRatio: PlatformDispatcher.instance.implicitView?.devicePixelRatio ?? 3,
);

becomes this

var path = await HomeWidget.renderFlutterWidget(
  const LineChart(),
  key: 'lineChart',
  logicalSize: const Size(400, 400),
);

and the screenshot of the widget is always in the correct resolution.

Additionally, I believe this piece of code

https://github.com/ABausG/home_widget/blob/daea9c164886a00d247b84183a746b7535ebcaa4/lib/home_widget.dart#L149

should also reuse the configured pixel ratio, right?

morningf commented 4 months ago

I agree, this suggestion should be adopted.

dkbast commented 3 months ago

This would also make updating the home widget from anywhere thats not "UI" code much easier :)