【问题标题】:Unable to load even when the indentation is right即使缩进正确也无法加载
【发布时间】:2021-06-25 19:23:04
【问题描述】:

它给出了无法加载资产的错误

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.teal,
        body: SafeArea(
          child: Column(
            children: <Widget>[
              CircleAvatar(
                radius: 50.0,
                backgroundImage: AssetImage("images/rishi.jpg"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

即使我检查了 pubspec 文件的缩进,它也会给我错误...附在下面

flutter:

 
  uses-material-design: true

  
  assets:
    - images/rishi.jpg

【问题讨论】:

  • 尝试Image.asset('path') 加载。还要确保图像资产位于各自的path
  • @Dinesh 我在附加源后忘记冷启动并且每次都在进行热重载。不过谢谢

标签: flutter


【解决方案1】:

将新资源附加为资产后,需要在热重载之前进行冷启动。否则会报错。

【讨论】:

    猜你喜欢
    • 2021-04-08
    • 2023-04-09
    • 2019-12-13
    • 2016-06-15
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多