惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tor Project blog
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
I
InfoQ
The Cloudflare Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
美团技术团队
B
Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
TaoSecurity Blog
TaoSecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
H
Heimdal Security Blog
爱范儿
爱范儿
博客园_首页
SecWiki News
SecWiki News
腾讯CDC
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
The Register - Security
The Register - Security
N
News | PayPal Newsroom
Recent Commits to openclaw:main
Recent Commits to openclaw:main
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Security Latest
Security Latest
A
Arctic Wolf
P
Privacy & Cybersecurity Law Blog
T
The Blog of Author Tim Ferriss
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
Attack and Defense Labs
Attack and Defense Labs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
C
Check Point Blog
Y
Y Combinator Blog
T
The Exploit Database - CXSecurity.com
aimingoo的专栏
aimingoo的专栏
I
Intezer
博客园 - 叶小钗
Cisco Talos Blog
Cisco Talos Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
小众软件
小众软件

博客园 - ZhangShengjie

苹果Universal Link 配置 pod 错误 iignoring ffi-1.15.4 because its extensions are not built. Try: gem pristine ffi --version 1.15.4 Xcode 模拟器 运行ipa iOS订阅详解 swift高阶函数 Flutter界面跳转 Flutter 使用inspector 调试UI Android Studio 调试flutter项目 Flutter 新建的Project Type类型对比 Mac上好用的数据库 iOS项目中加入flutter pod init 报错 /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34:in `force_encoding': can't modify frozen String (FrozenError) HASH与对称加密详解 Mac 安装 Flutter flutter iOS 使用BasicMessageChannel 通信 详解RSA加密原理 insert_dylib 编译没有product class-dump使用报错 Cannot find offset for address 0x88000000010af973 in stringAtAddress: 终端使用ipatool下载Appstore的Ipa文件到电脑
Flutter常见库使用
ZhangShengjie · 2023-12-27 · via 博客园 - ZhangShengjie

1、网络库 dio

dio: ^5.4.0

import 'package:dio/dio.dart';

final dio = Dio();

void getHttp() async {
  final response = await dio.get('https://dart.dev');
  print(response);
}

2、JSON解析

json_serializable: ^6.7.1 
json_annotation: ^4.8.1
build_runner: ^2.4.7
新建一个模型 test_model.dart
import 'package:json_annotation/json_annotation.dart';
part 'test_model.g.dart';

@JsonSerializable()
class TestModel {
  String name = "";
  int age = 0;
  double height = 0;

  TestModel({required this.name, required this.age, required this.height});

  factory TestModel.fromJson(Map<String, dynamic> json) => _$TestModelFromJson(json);

  Map<String, dynamic> toJson() => _$TestModelToJson(this);
}

终端执行 

dart run build_runner build

3、获取文件路径

path_provider: ^2.1.1

 void _downlodUrl() async {
    var url = 'https://sample-videos.com/video123/flv/240/big_buck_bunny_240p_10mb.flv';
    var path = await getDownloadsDirectory();
    print("ios paht:$path");
    String savePath = "${path?.path}/temp.mp4";
    print(savePath);
    Dio().download(url, savePath,onReceiveProgress: (c,t) {
      var progress = "${(c / t * 100)}%";
    print(progress);
    });
  }

4、数据存储

shared_preferences: ^2.2.2

// Obtain shared preferences.
final SharedPreferences prefs = await SharedPreferences.getInstance();

// Save an integer value to 'counter' key.
await prefs.setInt('counter', 10);
// Save an boolean value to 'repeat' key.
await prefs.setBool('repeat', true);
// Save an double value to 'decimal' key.
await prefs.setDouble('decimal', 1.5);
// Save an String value to 'action' key.
await prefs.setString('action', 'Start');
// Save an list of strings to 'items' key.
await prefs.setStringList('items', <String>['Earth', 'Moon', 'Sun']);

//获取

// Try reading data from the 'counter' key. If it doesn't exist, returns null.
final int? counter = prefs.getInt('counter');
// Try reading data from the 'repeat' key. If it doesn't exist, returns null.
final bool? repeat = prefs.getBool('repeat');
// Try reading data from the 'decimal' key. If it doesn't exist, returns null.
final double? decimal = prefs.getDouble('decimal');
// Try reading data from the 'action' key. If it doesn't exist, returns null.
final String? action = prefs.getString('action');
// Try reading data from the 'items' key. If it doesn't exist, returns null.
final List<String>? items = prefs.getStringList('items');

// Remove data for the 'counter' key.await prefs.remove('counter');

 5.图片快速加载

flutter_gen_runner

flutter_gen_runner: ^5.3.2

yaml中添加

  build_runner: ^2.4.7
  flutter_gen_runner: ^5.3.2

yaml添加图片路径

导入库后执行命令

 dart run build_runner build

更新图片

flutter clean  

dart run build_runner build

使用

Assets.asset.image.img1.image()

 6.打开相册、相机

image_picker

image_picker: ^1.0.6 

在项目中添加相应的权限

如果运行报错、先用xdode运行程序、把权限授权了在运行

  void openAlbum() async{
    final ImagePicker picker = ImagePicker();
// Pick an image.
    final XFile? image = await picker.pickImage(source: ImageSource.gallery);
  }
}

 7.局部刷新框架  getX 

get: ^4.6.6

1.修改 MaterialApp 为  GetMaterialApp

2.Controller继承与GetXController

class MinePageController extends GetxController {
//GetX改造步骤3:给变量值添加.obs
var_backgroundurl = Assets.image.defaultPhotopath.obs
String get backgroundUrl => _backgroundUrl.value
set backgroundUrl(String url) => _backgroundUrlvalue = url