- 获取当前时间日期
定时器var now=DateTime.now();print(now);//2021-09-24 10:05:23.109118print(now.millisecondsSinceEpoch);//1632449123109,日期转时间戳print(DateTime.fromMillisecondsSinceEpoch(now.millisecondsSinceEpoch));//2021-09-24 10:05:23.109,时间戳转日期print(formatDate(now, [yyyy,'年',mm,'月',dd,'日']));//2021年09月24日,需安装date_format
josnvar timer=Timer.periodic(Duration(milliseconds: 3000), (timer) {print(1);//timer.cancel();//销毁});
http——get、postMap userInfo={'name':'jack','age':20};print(json.encode(userInfo));//josn转strString userInfo2='{"name":"jack","age":20}';print(json.decode(userInfo2));//str转josn
颜色转换,Color到MaterialColor ```dart import ‘dart:ui’; import ‘package:flutter/material.dart’;_http_get() async{var url=Uri.parse('http://jd.itying.com/api/httpGet');var response=await http.get(url);print('${response.statusCode}');//200,状态码200成功print('${response.body}');//{"msg":"这是Get请求返回的数据"}print(json.decode(response.body)['msg']);//这是Get请求返回的数据}_http_post() async{var url=Uri.parse('http://jd.itying.com/api/httpPost');var response=await http.post(url,body: {"name":"jack","age":'20'});print('${response.statusCode}');//200,状态码200成功print('${response.body}');//{"msg":"post成功","body":{"name":"jack","age":"20"}}print(json.decode(response.body)['msg']);//post成功print(json.decode(response.body)['body']['name']);//jack}...ElevatedButton(onPressed: _http_get, child: Text('http_get')),ElevatedButton(onPressed: _http_post, child: Text('http_post')),
//调用的时候需要把hex改一下,比如#223344 #换成0xFF变成 0xFF223344
MaterialColor createMaterialColor(Color color) {
List strengths =
for (int i = 1; i < 10; i++) { strengths.add(0.1 i); } strengths.forEach((strength) { final double ds = 0.5 - strength; swatch[(strength 1000).round()] = Color.fromRGBO( r + ((ds < 0 ? r : (255 - r)) ds).round(), g + ((ds < 0 ? g : (255 - g)) ds).round(), b + ((ds < 0 ? b : (255 - b)) * ds).round(), 1, ); }); return MaterialColor(color.value, swatch); } … createMaterialColor(Color(0xFFfb7299)) ```
