前言
本篇主要记录一下在学习Flutter的过程中遇到的一些问题,及解决方法,菜鸟学习,持续更新中...
1. Flutter添加图片的踩坑过程
今天添加图片一直报错:
Error on line 48, column 4: Expected a key while parsing a block mapping.
╷
48 │ assets:
│ ^
╵
这是因为图片文件夹目录路径不对,要放在项目目录也就是Lib文件夹下:

在Flutter中,所有的图片资源与自定义字体资源,默认情况下都需要添加在Flutter应用根目录下的assets目录下(assets文件目录需要用户自己新建,名称必须是“assets”,否则会报找不到图片的错误),并且需要在项目的pubspec.yaml文件下对应的位置的添加图片名称。
然后放开 pubspec.yaml 中 assets 里的注释,内容改成如图所示的,但是依然报错,这是因为配置文件,pubspec.yaml 中未对齐,层次不对,注意“-”前后的空格,Flutter对空格有很严格的要求,

对齐以后就好了:

码代码,使用 Card 组件添加一个图片
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
primarySwatch: Colors.blue,
),
home: Scaffold(
// 应用顶栏
appBar: AppBar(
title: Text("Hello World"),
),
body: Card(
child: Column(
children: [Image.asset('asset/images/lake.png'), Text('添加图片')],
),
),
),
);
}
}
但是依旧报错,读不到这个图片,

pubspec.yaml 配置文件中拼接上全路径就可以了:
assets:
- assets/images/lake.png
把Assets 文件夹移出来和lib平级,pubspec.yaml 中写不写图片名字都可以。

Postman请求调试不通问题
用Postman测试后台接口死活不通,报错如下:
Error: Hostname/IP does not match certificate's altnames: Host: pmsdev.foton.com.cn. is not in the cert's altnames: DNS:*.bfda.cn, DNS:bfda.cn
翻译:
错误:主机名/IP 与证书的替代名称不匹配:主机:pmsdev.foton.com.cn。 不在证书的替代名称中:DNS:*.bfda.cn, DNS:bfda.cn
原来是证书的问题,https证书无效的,设置忽略https证书即可,

取消系统代理

还有<title>400 Bad Request</title>设置的问题:

把这些默认的勾选上,就OK了。
网友评论