Flutter image not render / showing from internet using Image.network - dart

I am facing a problem when working with flutter-image. I can render the image(s) from my device, but not the image(s) from the Internet!
I have to mention that I put the code in the androidManifest file to get permission for the internet as well.
But it does not work. Here is my code from the flutter documentation:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
var title = 'Web Images';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Image.network(
'https://picsum.photos/250?image=9',
),
),
);
}
}
I can't understand what the problem is! It doesn't show any errors or throw any exceptions. The image simply does not appear on the screen.
Is there anything I need to do to get the image rendered from the Internet or using url?

I've tested your code and it seems working on both android emulator and iOS simulator.
Android emulator:
iOS simulator:
There was a filed bug regarding this issue.
Since some of the workaround have been mentioned in the the comments like checking the INTERNET is enabled if you are running in a release mode.
The default Flutter app template enables INTERNET permission for
debug/profile modes (to support the Dart observatory) but not for
release mode.
You could also try the following:
Check the configuration of the DNS in your computer. It could be a possibility that it blocks the internet connection of your android emulator.
Check the app with a different device (e.g. physical android device since its working in iOS), then if its working, it is something in your computer or internet to check on.
Also, other workarounds was also mentioned in the filed bug comment:
By the way there are two folders where AndroidManifest.xml appears my
machine:
android/app/src/profile android/app/src/debug
Make sure you have the permissions in both
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flloadimage">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Also Here somethings else to try see if phone has problem. Login to
adb shell while device is launched (or plugged in) and ping the
website.
E.g. should look something like this
~$ adb shell
generic_x86:/ $ ping picsum.photos
PING picsum.photos (104.37.178.1) 56(84) bytes of data.
64 bytes from 104.37.178.1: icmp_seq=1 ttl=254 time=17.6 ms
64 bytes from 104.37.178.1: icmp_seq=2 ttl=254 time=22.4 ms
^C
--- picsum.photos ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5012ms
rtt min/avg/max/mdev = 13.638/19.442/24.621/3.508 ms
generic_x86:/ <press ctrl-d to exit to your prompt>
Other ideas
Try on another wifi such as a cafe.
Do a flutter clean command to rebuild
Install on another computer

Related

Appium Automating hybrid apps

Hi I try to write my first test for an Ionic App and I cant figure out howto do, as the documentation seems to miss some information.
ionic:
I have created a pipeline that builds an APK and and IPA file
I can run those files in the emulators (Android & iOS)
Appium
The server runs, and can connect to the local running Android Emulator
I've create the node.js project as documented in the getting started guide
The following works too:
async function main () {
const client = await wdio.remote(opts);
await client.deleteSession();
}
Result:
[Instrumentation] OK (1 test)
[Instrumentation] The process has exited with code
But now the documentation seems to miss a step, as it starts with (Automating hybrid apps):
driver
.contexts().then(function (contexts) { // get list of available views. Returns array: ["NATIVE_APP","WEBVIEW_1"]
return driver.context(contexts[1]); // choose the webview context
})
How do I get a driver instance in JavaScript, based on the client instance?
Also I have an "async function main ()" now. Is there no pattern to write it like async function test_01, test_02, or more meaningful?

How to debug iOS 14 widget in Xcode 12?

I am working on an iOS 14 widget which I would like to my existing iOS 11+ app. The whole process is quite cumbersome because it happens quite often that something does not work as expected.
For example the widget shows unexpected data, or is not rendered as expected (e.g. as described here). I assume that something wents wrong when the system requests the widget and its content from my app extension. However I cannot figure out what this might be.
Is there any way to actually debug the widget extension? Seeing when the code is executed and how it works?
I have already tried to hook up the debugger to the widget extension (using the Debug/Attach to process menu in Xcode). While the process is listed there, the debugger shows no log output nor stops on breakpoints.
Using the system console to show the logs of the iOS simulator devices does not work as well. It does not matter if print(...) or NSLog(...) is used. No output reaches the console.
On the top left of Xcode->
Click project name, you can see a list, select widget name, run it
Click widget name, you can see a list, select project name, run it
Xcode: Version 12.3, iPad: iPadOS 14.3
This works for me.
Since I found no other way to debug the widget extension I wrote a logging method which adds the log output to a a file a the apps group folder:
static func logToFile(_ text: String) {
if let documentsDirectory = FileManager().containerURL(forSecurityApplicationGroupIdentifier: "my.app.group.key") {
let logFileUrl = documentsDirectory.appendingPathComponent("log.txt")
do {
var logContent = try String(contentsOf: logFileUrl, encoding: .utf8)
logContent = (logContent.count > 0 ? "\(text)\n\(logContent)" : text)
try logContent.write(to: logFileUrl, atomically: false, encoding: .utf8)
}
catch {}
}
}
Not the best solution but the only one I found so far.
Select your widget target at the top left corner of Xcode, build and run the app,
then the widget process will be able to debug and show logs.
(This example project is downloaded provided by Apple: https://developer.apple.com/documentation/widgetkit/building_widgets_using_widgetkit_and_swiftui)
Seems Xcode bug here.
Quick fix works for me is open log console manually by cmd + shift + y.
And also add breakpoints.
And then run widget to see logs.
I've run into this issue as well. Logs were not showing (or only showing sometimes) when I run my widget extension in Xcode.
After hours of debugging, the thing that fixed it for me was plugging in my actual device (iPhone 12 Pro Max) and running the widget on that physical device instead of the simulator.
Try disabling bitcode in your extensions, I've had a hard time getting logs until I do it.

Detecting app run on emulator or real device

I need to detect, if an app is running on an iOS or Android emulator to skip an QR code scan method and just return a scanned code.
Q: How do I detect
on which device type - iOS or Android - an app is running and
if an app is running on an emulator?
Just found this plugin, which prints various details:
https://pub.dartlang.org/packages/device_info#-readme-tab-
Output on Android emulator [see last line]:
safe_device: ^1.1.1
import 'package:safe_device/safe_device.dart';
Checks whether device is real or emulator
bool isRealDevice = await SafeDevice.isRealDevice;
(ANDROID ONLY) Check if development Options is enable on device
bool isDevelopmentModeEnable = await SafeDevice.isDevelopmentModeEnable;

Error in using UIAutomatorviewer for testing Android app in Appium

I have to automate an Android application, I am doing the same through Appium.
The problem I am facing is after launching the Appium server, the app is getting installed in the emulator 4.4.2. To inspect the element I am using UIAutomatorviewer which comes default with SDK. But while inspecting the element of the app, I am getting the error:
Error obtaining UI hierarchy
Reason:Error while obtaining UI hierarchy XML file.com.android.ddmlb.SynchException.Remote object doesn't exist.
I tried to find the solution so that I can inspect the element so that I can script, but in vain.
Can someone please tell how to fix the issue so that I can inspect elements?
Is there any other way I can inspect element in the app apart from using UIAutomator viewer?
After my tryst with the uiautomator viewer i came to know that we get the error only when:
appium server is running and we try to capture the screenshot using uiautomatorviewer.
So, whenever you want to use uiautomatorviewer make sure that server is in stopped state.
I fixed the same issue by using following methods.
(1) Connect your Android device to your development machines;
(2) Go to command line in terminal or DOS command line for Windows;
(3) Using "adb shell" into your Android devices;
(4) Change the user to root by input "su root" in command line;
(5) Change the access right to /data/local/tmp by input "chmod 777 /data/local/tmp";
(6) Go back to uiautomatorviewer and do screen shot again, the error should be gone;
I guess there are some file can't be access if it doesn't own right in /data/local/tmp.
Make sure everything on your screen is static. And flashing input cursor is also not allowed. Any painting actions will stop uiautomator from dumping current UI.
You can test by using following adb command:
adb shell uiautomator dump /data/local/tmp/uidump.xml
if the message ERROR: could not get idle state. appears, you are suffering from this issue.
See lines 87 & 101 of DumpCommand:
try {
...
uiAutomation.waitForIdle(1000, 1000 * 10);
...
} catch (TimeoutException re) {
System.err.println("ERROR: could not get idle state.");
return;
}
Easiest solution..
Restart the device. Restart uiautomatorviewer.
Worked like a charm for me .... :P
Stop the Appium Server. Then try again. It works.
I had the same problem because I used "adbd insecure". So I just disabled "adbd insecure", and reload uiautomatorviewer, everything is OK.
In case of rooted devices: Enable the root access in developer options for adb. Restart adb as root
I have spent over a week to resolve this issue. When you connect your device and using ASM 3.0, when screen is projected open the UIAutomator to capture the current android screen. Without Appium it should capture. For use Android Studio instead of android sdk. Uninstall and reinstall Android Studio. It is working perfect for me now.
Answer to your question #2
You can inspect Android app directly from your real Android device.
You need to:
Connect Android device to your computer/laptop
Go to Android device Settings -> Enable Developer Options and Android debbuging
Please see here:
Start the app you wish to inspect in your Android device
Open up the Chrome browser on your computer/laptop and do a right click -> More Tools -> Inspect devices -> Click on your device -> (Click on Android device OK to authorize) -> Click Inspect
Please see here:
That's it. Hope it helps!
I got also the same issue (Also if Appium Server was not running). After switch, OFF / ON USB-Debugging was working for me.
I got it resolved
I closed the Appium Server running on my machine and opened it again.
Later open uiautomater, and it worked for me
The one that works is in this path:
Android/Sdk/tools/bin/uiautomatorviewer
Paste this in your terminal and it will run automator that works
we have to use device which has API level morethan 17 or jelly bean
Way to bypass the ERROR:
could not get idle state.
By using uiautomator to get uix and screenshot.
public class DeviceMethods extends UiAutomatorTestCase {
public void dump(){
try {
getUiDevice().dumpWindowHierarchy("window_dump.uix") ;
getUiDevice().takeScreenshot(new File("/data/local/tmp/window_dump.png"));
} catch (Exception e) {
}
}
you need to create the uiautomator jar and push it to /data/local/tmp
use this tutorial on how to use uiautomator
after you get the files just open them in uiautomatorviewer
What worked for me:
stop appium
open an emulator device (tested with Android 7.1.1)
go into settings > developer options > Enable view attribute inspection
open a shell on the computer, cmd or terminal depending on your OS
enter the following commands:
adb shell
su
cd /data
cd /local
chmod 777 tmp
start uiautomatorviewer
take an xml screenshot
"su chmod 777 /data/local/tmp" didnt work for me so I drilled down and it worked. I assume that you have to do this in an emulator and not a physical device unless the device is rooted. ¯ \ _ (ツ)_/¯
Lotsa Luck!
This happens because adb is using port and it's blocked by appium server.
I have found out best solution for this
Kill the adb.exe from taskbar processes and try launching uiautomatorviewer again
Check whether you have enabled these under "developer options" in the phone.
Verify apps via USB
View attribute inspection
USB debugging
1) stop appium Server
2) open an emulator device
3) go into settings > developer options > Enable view attribute inspection
4) developer options in invisible? Go into settings > Tap on About device/phone > Scroll down till the last option(Build number) > Continuously Tap on "Build number" for 7 times > you should get an Toast message "You're a developer" > come back from that screen > Go back into settings > Now you should see developer options Tap on it > Enable view attribute inspection
5) You should no more get this error message
Why don't you use appium inspector instead? You can download it and follow instructions from here
try switching Off and then ON the USB debugging option.. this work for me

BlackBerry advertising for Torch

I downloaded the advertising SDK and followed the directions in the development guide PDF that came with the SDK.
This is what my code looks like after setting all the config stuff step by step in the PDF:
Banner bannerAd = new Banner("my zone id #", null);
bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
add(bannerAd);
When I have just lines 1 and 2 nothing happens, but when I put in line 3 my simulator will not start and it also does not work on an actual device. I am not getting exceptions and do not see anything weird in the event log.
The simulator I am running is a BlackBerry Torch, so is the actual device, and the advertising SDK is for post6.0 devices.

Resources