当前位置:网站首页>Fluent 2 Advanced (V):json_ Serializable use
Fluent 2 Advanced (V):json_ Serializable use
2022-07-22 20:06:00 【Wu Qingsen】
The later request for network use is free Bmob , It is recommended to generate entity classes json_serializable .
Advanced failed .
Add dependency :
environment:
sdk: ">=2.15.0-116.0.dev <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
json_annotation: ^4.4.0 # add to 1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
build_runner: ^2.1.5 # add to 2
json_serializable: ^6.1.0 # add to 3
create a file home_page_bean.dart , Write parameters and construction methods , The second bag needs handwriting , The format is to add .g :
part 'home_page_bean.g.dart';
Don't worry about mistakes first :
import 'package:json_serializable/json_serializable.dart';
part 'home_page_bean.g.dart';
@JsonSerializable()
class HomePage {
int? type; // classification , Such as recommendation
String? title; // title
String? content; // Content
String? playnum; // Number of plays
String? classname; // classification , Such as film and television , Chase fan, etc
String? videoLength; // Video duration
String? comments; // Comment on
String? up; // Blogger
String? videourl; // Video playback link
// Construction method
HomePage();
}
Manually add fromjson Methods and tojson Method , Don't worry about handwritten errors :
import 'package:json_annotation/json_annotation.dart';
part 'home_page_bean.g.dart';
@JsonSerializable()
class HomePage {
int? type; // classification , Such as recommendation
String? title; // title
String? content; // Content
String? playnum; // Number of plays
String? classname; // classification , Such as film and television , Chase fan, etc
String? videoLength; // Video duration
String? comments; // Comment on
String? up; // Blogger
String? videourl; // Video playback link
// Construction method
HomePage();
factory HomePage.fromJson(Map<String, dynamic> json) =>
_$HomePageFromJson(json);
Map<String, dynamic> toJson() => _$HomePageToJson(this);
}
And then execute the command :
flutter packages pub run build_runner build
Wait to compile the file :home_page_bean.g.dart
But most of the time, there are problems in the actual project compilation , I haven't passed it for a day . Have to say flutter Compatibility is bad enough . Finally, I created a new project , Plug in installed , After generating it, copy it to my project .
I use the non empty version flutter , Probably encountered problems :
Compilation goes into an endless loop , Repeat printing :
I will flutter And build runner Use it together , But today it just received this empty error . I even thought I had restored my code changes , But it is still the same mistake .
error :
>[SEVERE] json_serializable:json_serializable on test/widget_test.dart:
>NoSuchMethodError: The getter 'uri' was called on null.
>Receiver: null
>Tried calling: uri
>[INFO] 3.3s elapsed, 1/17 actions completed.
>[INFO] 4.4s elapsed, 1/17 actions completed.
>[INFO] 5.4s elapsed, 1/17 actions completed.
>[INFO] 6.4s elapsed, 1/17 actions completed.
>[INFO] 7.5s elapsed, 1/17 actions completed.
>[INFO] 8.5s elapsed, 1/17 actions completed.
>[INFO] 9.6s elapsed, 1/17 actions completed.
>[INFO] 10.7s elapsed, 1/17 actions completed.
>[INFO] 11.8s elapsed, 1/17 actions completed.
>[INFO] 12.9s elapsed, 1/17 actions completed.
>[INFO] 14.0s elapsed, 1/17 actions completed.
>[INFO] 15.0s elapsed, 1/17 actions completed.
>[INFO] 16.1s elapsed, 1/17 actions completed.
>[INFO] 17.1s elapsed, 1/17 actions completed.
>[WARNING] No actions completed for 15.1s, waiting on:
> json_serializable:json_serializable on lib/common_widgets/alert_screens.dart
> json_serializable:json_serializable on lib/common_widgets/app_logo.dart
> json_serializable:json_serializable on lib/common_widgets/app_tab_bar.dart
> json_serializable:json_serializable on lib/common_widgets/buttons_widgets.dart
> json_serializable:json_serializable on lib/common_widgets/cards.dart
> .. and 11 more
> [INFO] 18.2s elapsed, 1/17 actions completed.
> [INFO] 19.3s elapsed, 1/17 actions completed.
The solution is to update the plug-in :
Updated plug-ins , and data_plugin: ^0.0.16 Conflict , The plug-in used here is old , and json_serializable It's new , I can only reduce the version back .
There are also various error reporting problems , Search found let update plug-ins , Very speechless :
/D:/rruanjian/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_span-1.7.0/lib/src/file.dart:437:1: Error: This requires the 'extension-methods' experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running.
extension FileSpanExtension on FileSpan {
^^^^^^^^^
/D:/rruanjian/flutter/.pub-cache/hosted/pub.flutter-io.cn/source_span-1.7.0/lib/src/file.dart:437:32: Error: A function declaration needs an explicit list of parameters.
Try adding a parameter list to the function declaration.
extension FileSpanExtension on FileSpan {
...
^^^^^^^^
Something like that . These problems have been circulating , I have solved it for a day .
Some people encounter the problem of the above cycle , Please help me solve it , My configuration is like this , Temporarily removed json_serializable:
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
http: ^0.12.0+1
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
data_plugin: ^0.0.16
json_annotation: ^2.0.0
fluttertoast: ^8.0.6
permission_handler: ^5.0.1+1
shared_preferences: ^0.5.7+3
underline_indicator: ^0.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
边栏推荐
- Xcode11 add lanuchimage black screen can't display problem
- grep实际使用 ps/netstat/sort
- var、let、const区别
- From data standards to database design: solve the last mile problem of basic data standards (Part 2)
- Spark RDD的依赖于DAG的工作原理
- Dynamic memory management and flexible array
- appstore 上传屏幕快照尺寸
- appsstore transporter上传的时候一直卡在正在验证问题
- NC27 集合的所有子集(一)
- jps没有namenode和datanode原因
猜你喜欢
随机推荐
System table space is full
Flutter开发(三十一):Flutter启动白屏
Kotlin学习三:页面的常用写法
How to clear localstorage data after closing the browser
Win10图标变白纸了,恢复方法
plsql不能初始化
leetcode 209. 长度最小的子数组
pyinstaller打包scrapy
Kotlin学习一:变量、函数、条件语句与循环语句
NC26 括号生成
Spark loads CSV and JSON files (attached to the virtual machine to execute the jar package)
Spark GraphX 中的 pregel函数(转载)
HTB- Armageddon
The difference between location.replace and location.href
Error reported by Xcode compiling pod third-party library
【数据库基础干货】MySQL基础及慢查询优化实践
2017年终总结
Spark RDD算子:RDD分区,HashPartitioner、RangePartitioner、自定义分区
小鸟平台隐私政策
var、let、const区别