flutter - How to solve flutter "Infinity or NaN toInt" on some images
问题描述
I have a simple project that should just display an image. I should mention that am very new to flutter.
Below is the main.dart
import 'package:flutter/material.dart';
import 'package:flutter_shoe/ColorHolder.dart';
import 'package:flutter_shoe/home_page.dart';
import 'package:flutter_shoe/profile_page.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primaryColor: primaryColor,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage(),
);
}
}
And here is the HomepageClass
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Icon(Icons.menu),
title: Text("Home"),
centerTitle: true,
actions: [
Icon(Icons.circle_notifications),
],
),
body: Container(
child: Image.asset(
"assets/imgs/curved.png",
// "assets/imgs/doc.jpg",
width: 500,
height: 200,
),
),
);
}
}
The above code is giving me the error
Unsupported operation: Infinity or NaN toInt
The error points to the line that contains the image asset.
I have tried using several different images and it is working well with some images and gives error on other images. I need it to always work with all images.
A sample working image has dimensions 626 by 626 and is jpg A sample non working image has dimension 1080 by 768 and is png
I have tried replacing container with Expandable. I have appended height and width value to the container. Still not working I have changed the width and height of image to double.maxFinite. Not working.
I don't find anything on their docs that is helping.
Someone help me know where I am going wrong.
解决方案
I solved it. Turns out that I should not use hot-reload after adding a new assets. All I needed was to stop the project and re-run it afresh.
推荐阅读
- mysql - MySQL 批量插入事务无法正常工作
- java - 在 Android 中向 Google 地图添加自定义标记
- azure-devops - 如何根据 Azure AD 组中的成员身份将用户添加到 Azure DevOps 组织?
- java - 使用 spring data jpa 更新多对多表,不兼容的类型
- html - 如何在 wordpress 网站中导入/查看 STL 文件?
- python - 制作一个可以捕捉到屏幕的 pygame 可调整大小的窗口
- tensorflow.js - [BodyPix]在 Firefox 中运行 segmentPerson 时导致的内存泄漏
- python - 为什么通过 Web 服务 API 调用 Azure ML 分类模型不返回概率分数?
- c++ - 结构向量中的内存使用情况
- laravel - Routed not found 404 错误,但是 laravel 中存在路由