main.dart import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'This is a Slide Example', home: Scaffold( appBar: AppBar( title: Text('ABC'), ), body: Column(children:[ Padding( child: Text( 'This is a Slide Example', style: TextStyle(fontSize: 20), ), padding: EdgeInsets.all(50), ), SlideExample(), RangeSliderExample() ]))); } } class SlideExample extends StatefulWidget { @override _Slider1State createState() => _Slider1State(); } class _Slider1State extends State { double rating = 0; @override Widget build(BuildContext context) { // TODO: implement build return Slider( label: "$rating", divisions: 10, value: rating, onChanged: (newRating) { setState(() => rating = newRating); }, ); } } class RangeSliderExample extends StatefulWidget { @override _RangeSliderExampleState createState() => _RangeSliderExampleState(); } class _RangeSliderExampleState extends State { var selectedRange = RangeValues(0.2, 0.8); @override Widget build(BuildContext context) { // TODO: implement build return RangeSlider( values: selectedRange, onChanged: (RangeValues newRange) { setState(() { selectedRange = newRange; }); }, ); } }
flutter Slide拖动滑条
2019/11/04 by Leave a Comment
空闲时间用Flutter写的安卓APP 金庸武侠小说集离线版
2019/10/25 by Leave a Comment
空闲时间用Flutter写的安卓APP 金庸武侠小说集离线版 ,Google Play上架中,APK版本直接下载:
Flutter Widget创建时运行异步操作
2019/09/18 by 2 Comments
样例代码
import 'package:flutter/material.dart'; import 'dart:async'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return MaterialApp( home: Scaffold( body: Center(child: AsyncTest()), )); } } class AsyncTest extends StatefulWidget { @override _AsyncTestState createState() => _AsyncTestState(); } int getNumber(int n) { if (n == 0) { return 0; } else if (n == 1) { return 1; } else { return getNumber(n - 1) + getNumber(n - 2); } } Future loadAsset(BuildContext context) async { return await DefaultAssetBundle.of(context) .loadString('assets/novels/0-1.txt'); } class _AsyncTestState extends State { bool loading = true; @override void initState() { super.initState(); loadAsset(context).then((result) { debugPrint( 'consume cpu time function result is ' + getNumber(20).toString()); Future.delayed(Duration(seconds: 1)).then((result) { setState(() { loading = false; }); }); }); } @override Widget build(BuildContext context) { // TODO: implement build if (loading == true) { return CircularProgressIndicator(); } return Text('load finished '); } }
几点说明:
- 使用StatefulWidget 有状态Widget
- 在initState函数中执行异步操作
- 保证在已有结果的状态下调用setState
参考:
https://flutter.institute/run-async-operation-on-widget-creation/
git npm brew yarn 配置proxy
2019/06/14 by Leave a Comment
all export https_proxy=http://127.0.0.1:6152 export http_proxy=http://127.0.0.1:6152 export all_proxy=socks5://127.0.0.1:6153 git npm brew yarn 配置代理 //git列出 git config --global http.proxy //git设置 git config --global http.proxy 'socks5://127.0.0.1:6153' //git取消设置 git config --global --unset http.proxy npm //列出所有配置 npm config ls -l //列出 npm config list //设置 npm config set https-proxy http://127.0.0.1:6152 npm config set proxy http://127.0.0.1:6152 //npm 取消配置 npm config list delete https-proxy npm config set proxy //yarn 列出 yarn config list //yarn 设置 yarn config set proxy http://127.0.0.1:6152 yarn config set https-proxy http://127.0.0.1:6152 //yarn 取消配置 yarn config delete proxy yarn config delete https-proxy //brew 列出 all_proxy=socks5://127.0.0.1:6153 brew install mysql
flutter pub get缓慢解决方案
2018/09/06 by Leave a Comment
flutter pub get缓慢解决方案
windows
set PUB_HOSTED_URL=https://pub.flutter-io.cn set FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn flutter pub get
Linux MACOS
export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn flutter pub get