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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 [Bug] Exception Invalid image dimensions. #252

Open
moha-b opened this issue Apr 21, 2024 · 0 comments
Open

馃悶 [Bug] Exception Invalid image dimensions. #252

moha-b opened this issue Apr 21, 2024 · 0 comments

Comments

@moha-b
Copy link

moha-b commented Apr 21, 2024

On the home widget, the temperature and date display correctly, but the image does not. I followed the example explanation and here is a code snippet.

What I follow

HomeWidget.renderFlutterWidget(
const Icon(
Icons.flutter_dash,
size: 200,
),
logicalSize: const Size(200, 200),
key: 'dashIcon',
),

Dart Code

try {
            print(state.weather.theme.image);
            await Future.wait([
              HomeWidget.saveWidgetData('date', state.weather.date),
              HomeWidget.saveWidgetData(
                  'temperature', state.weather.temperature.toString()),
              HomeWidget.updateWidget(androidName: 'WeatherWidget'),
              HomeWidget.renderFlutterWidget(
                Image.asset(state.weather.theme.image),
                key: 'image',
              ),
            ]);
          } on PlatformException catch (exception) {
            log("Error Sending Data", error: exception);
          }

Log

I/flutter (31368): assets/images/weather/Day Sun.webp    // <- the image exist
E/BitmapFactory( 2649): Unable to decode stream: java.io.FileNotFoundException: Image: open failed: ENOENT (No such file or directory)
I/AppWidgetManager(31368): updateAppWidget() appWidgetIds = [29]
E/flutter (31368): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Failed to render the widget: Exception: Invalid image dimensions.
E/flutter (31368): #0      HomeWidget.renderFlutterWidget (package:home_widget/src/home_widget.dart:264:7)
E/flutter (31368): <asynchronous suspension>
E/flutter (31368): #1      Future.wait.<anonymous closure> (dart:async/future.dart:518:21)
E/flutter (31368): <asynchronous suspension>
E/flutter (31368): #2      HomeScreen.build.<anonymous closure> (package:clima/features/home/screens/home_screen.dart:23:13)
E/flutter (31368): <asynchronous suspension>
E/flutter (31368): 

What I follow

val image = widgetData.getString("dashIcon", null)
if (image != null) {
setImageViewBitmap(R.id.widget_img, BitmapFactory.decodeFile(image))
setViewVisibility(R.id.widget_img, View.VISIBLE)
} else {
setViewVisibility(R.id.widget_img, View.GONE)
}

Native Code

 appWidgetIds.forEach { widgetId ->
            val views = RemoteViews(context.packageName,R.layout.weather_widget).apply {
                val widgetData = HomeWidgetPlugin.getData(context)
                val temp = widgetData.getString("temperature","Temperature")
                val date = widgetData.getString("date","Date")
                val image = widgetData.getString("image", null)
                if (image != null) {
                    setImageViewBitmap(R.id.image, BitmapFactory.decodeFile(image))
                    setViewVisibility(R.id.image, View.VISIBLE)
                } else {
                    setViewVisibility(R.id.image, View.GONE)
                }
                setTextViewText(R.id.temperature,temp)
                setTextViewText(R.id.date,date)
            }
            appWidgetManager.updateAppWidget(widgetId,views)
        }

Widget Info

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:description="@string/app_widget_description"
    android:initialKeyguardLayout="@layout/weather_widget"
    android:initialLayout="@layout/weather_widget"
    android:minWidth="40dp"
    android:minHeight="40dp"
    android:previewImage="@drawable/example_appwidget_preview"
    android:previewLayout="@layout/weather_widget"
    android:resizeMode="horizontal|vertical"
    android:targetCellWidth="3"
    android:targetCellHeight="2"
    android:updatePeriodMillis="86400000"
    android:widgetCategory="home_screen" />

I understand that the image may be large, but there are no restrictions in the documentation.

image

The Problem is the image is not appearing even if I resize it

HomeWidget.renderFlutterWidget(
                Image.asset(
                  state.weather.theme.image,
                  width: 100,
                  height: 100,
                ),
                key: 'image',
              ),

The code is no longer throwing an Exception, but the image is still not appearing.

WhatsApp Image 2024-04-21 at 07 54 26_212c4836

Native Ui

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/Widget.Android.AppWidget.Container"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:padding="16dp"
    >

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        android:layout_margin="8dp"
        android:contentDescription="@string/weather_image" />
    <TextView
        android:id="@+id/temperature"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:contentDescription="@string/temperature"
        android:textSize="24sp"
        android:textStyle="bold|italic" />
    <TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:contentDescription="@string/date"
        android:textSize="16sp"
        android:textStyle="bold|italic" />
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant