Home > OS >  The image loads me in the emulator but not from the cell phone with the apk - flutter
The image loads me in the emulator but not from the cell phone with the apk - flutter

Time:10-22

When loading this image in the android emulator it is displayed but it looks gray on the cell phone. When calling this image in the emulator it loads me without problems but when I generate the apk the image no longer falls on the cell phone, the gray background remains.:

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';

class ImageScreen extends StatelessWidget {
  final String url;

  ImageScreen({
    Key key,
    @required this.url,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      child: Expanded(
        child: CachedNetworkImage(
          imageUrl: '${this.url}',
          // Ajust the image changing the box fit attributte
          fit: BoxFit.cover,
          placeholder: (_, __) {
            return Center(
              child: CupertinoActivityIndicator(
                radius: 15,
              ),
            );
          },
        ),
      ),
    );
  }
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

This has to two with one of the problems.

1- I think you are using the release file in the physical device but using debug file in the emulator. If this is the case the add android internet permission in this location

android/src/main/AndroidManifest.xml

2- In the debug file you can getting some error. For me when I was working on my project. An error happen which is Incorrect use of ParentDataWidget. But as this error not give me any problem in the debug mode but in the release the screen goes grey. First I have to resolve the error then it works both on android debug and the release mode.

CodePudding user response:

I could solve for that leave the code as follows:

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ImageScreen extends StatelessWidget {
  final url;

  ImageScreen({
    Key key,
    @required this.url,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: CachedNetworkImage(
        imageUrl: '${this.url}',
        // Ajust the image changing the box fit attributte
        //fit: BoxFit.cover,
      ),
    );
  }
}
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related