From 00e65a99b1a1dbf9b207a63c43c7f5d3838bbc86 Mon Sep 17 00:00:00 2001 From: "xiaojia22326@163.com" Date: Fri, 18 Jan 2019 15:42:18 +0800 Subject: [PATCH] update SharedPreferences save data and android device layout overflow --- lib/components/disclaimer_msg.dart | 368 +++++++----------- lib/components/fourth_page_feature/pages.dart | 150 +++---- lib/views/first_page.dart | 58 +-- lib/views/welcome_page/fourth_page.dart | 48 +-- 4 files changed, 270 insertions(+), 354 deletions(-) diff --git a/lib/components/disclaimer_msg.dart b/lib/components/disclaimer_msg.dart index 999056f1..a070a2a2 100644 --- a/lib/components/disclaimer_msg.dart +++ b/lib/components/disclaimer_msg.dart @@ -6,260 +6,190 @@ * email: zhu.yan@alibaba-inc.com */ import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + //import 'package:flutter_rookie_book/model/collection_general.dart'; //import 'package:flutter_rookie_book/model/collection_general.dart'; - -const disclaimerText1 = '\r\r\r\r\r\r本APP属于个人的非赢利性开源项目,以供开源社区使用,凡本APP转载的所有的文章 、图片、音频、视频文件等资料的版权归版权所有人所有,本APP采用的非本站原创文章及图片等内容无法一一和版权者联系,如果本网所选内容的文章作者及编辑认为其作品不宜上网供大家浏览,或不应无偿使用请及时用电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。'; -const disclaimerText2 = '\n\r\r\r\r\r\r对于已经授权本APP独家使用并提供给本站资料的版权所有人的文章、图片等资料,如需转载使用,需取得本站和版权所有人的同意。本APP所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并自负版权等法律责任。'; - +const disclaimerText1 = + '\r\r\r\r\r\r本APP属于个人的非赢利性开源项目,以供开源社区使用,凡本APP转载的所有的文章 、图片、音频、视频文件等资料的版权归版权所有人所有,本APP采用的非本站原创文章及图片等内容无法一一和版权者联系,如果本网所选内容的文章作者及编辑认为其作品不宜上网供大家浏览,或不应无偿使用请及时用电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。'; +const disclaimerText2 = + '\n\r\r\r\r\r\r对于已经授权本APP独家使用并提供给本站资料的版权所有人的文章、图片等资料,如需转载使用,需取得本站和版权所有人的同意。本APP所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并自负版权等法律责任。'; class DisclaimerMsg extends StatefulWidget { final State pWidget; - DisclaimerMsg({ Key key, this.pWidget }) : super(key: key); + + DisclaimerMsg({Key key, this.pWidget}) : super(key: key); + DisclaimerMsgState createState() => DisclaimerMsgState(); } class DisclaimerMsgState extends State { + Future _prefs = SharedPreferences.getInstance(); + Future _unKnow; var _valBool = false; - var _page; - //CollectionControlModel _collectionControl = new CollectionControlModel(); - //List _collectionList = []; - // void init(BuildContext context) { - // Toast.show(context: context, message: "👉 APP免责声明",cb:showAlertDialog); - // } + var _readed = false; + + //SharedPreferences 存储结果 + Future refs(bool value) async { + final SharedPreferences prefs = await _prefs; + final bool unKnow = value; + setState(() { + _unKnow = prefs.setBool("disclaimer", unKnow).then((bool success) { + return unKnow; + }); + }); + } @override void initState() { super.initState(); -// _collectionList.clear(); -// _collectionControl.getAllCollection().then((resultList) { -// resultList.forEach((item) { -// _collectionList.add(item); -// print('=============db=========${item}'); -// }); -// }); - _page = widget.pWidget; - } - - - - void refs(bool value){ - if(this.mounted){ - setState(() { - _valBool=value; - _page.save(value); - }); - -// _collectionControl -// .insert(CollectionGeneral(key: 'disclaimer', values: value.toString())) -// .then((result) { -// print('result2====${result}'); -// } -// ); - } + //获取SharedPreferences 存储结果 + _unKnow = _prefs.then((SharedPreferences prefs) { + return (prefs.getBool('disclaimer') ?? false); + }); + _unKnow.then((bool value) { + _valBool = value; + _readed = value; + }); } void showAlertDialog(BuildContext context) { -// new Future.delayed(Duration(seconds: 5)).then((value) { -// Navigator.of(context).pop(); -// }); showDialog( context: context, barrierDismissible: false, // user must tap button! builder: (BuildContext context) { return AlertDialog( //title: Text('免责声明'), - content:SingleChildScrollView( - child: ListBody( - children: [ - Container( - padding: EdgeInsets.fromLTRB(5.0, 5.0, 10.0, 10.0), - //width: 100, - height: 35, - child: Text('免责声明',style:TextStyle(fontSize: 18,fontWeight:FontWeight.w700 )), - decoration: BoxDecoration( - //color: Colors.blue, - image: DecorationImage( - fit: BoxFit.fitWidth, - image: AssetImage('assets/images/paimaiLogo.png') - ), - borderRadius: BorderRadius.all( - Radius.circular(10.0), - ), - //alignment: Alignment.bottomRight, - ) - ), - SizedBox(height:20), - Text(disclaimerText1), - Text(disclaimerText2), - ], - ), - ), - shape:RoundedRectangleBorder(borderRadius: new BorderRadius.circular(20.0)), // 圆角 - actions: [ - Container( - width: 270, - alignment: Alignment.centerLeft, - padding: new EdgeInsets.fromLTRB(0.0, 0.0, 30.0, 0.0), - child: - Row( - mainAxisAlignment:MainAxisAlignment.spaceAround, - //crossAxisAlignment:CrossAxisAlignment.start, + content: SingleChildScrollView( + child: ListBody( children: [ - Row( - mainAxisAlignment:MainAxisAlignment.center, - children: [ - Checkbox( - activeColor: Theme.of(context).primaryColor, - tristate:false, - value: _valBool, - onChanged: (bool bol) { - refs(bol); - Navigator.of(context).pop(); // here I pop to avoid multiple Dialogs - showAlertDialog(context); //here i call the same function - } - ), - Text('不再自动提示',style:TextStyle(fontSize: 14)), - ], - ), - new Flexible( - flex: 1, - child: Container(width: 100,) - ), - FlatButton( - child: Text('知道了',style:TextStyle(fontSize: 16,color: Colors.white)), - color: Theme.of(context).primaryColor, - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ] -// SizedBox( -// width:150, -// height:55, -// child: CheckboxListTile( -// title: Text('不再显示',style:TextStyle(fontSize: 14)), -// controlAffinity: ListTileControlAffinity.leading, -// activeColor: Colors.red, -// value: _valBool, -// onChanged: (bool value) { -// refs(value); -// Navigator.of(context).pop(); // here I pop to avoid multiple Dialogs -// showAlertDialog(context); //here i call the same function -// } -// ) -// //secondary: const Icon(Icons.hourglass_empty), -// ), -// Checkbox( -// activeColor: Colors.red, -// tristate:false, -// value: _valBool, -// onChanged: (bool bol) { -// refs(bol); -// Navigator.of(context).pop(); // here I pop to avoid multiple Dialogs -// showAlertDialog(context); //here i call the same function -// } -// ), -// Text('不再显示',style:TextStyle(fontSize: 14)), -// FlatButton( -// child: Text('知道了',style:TextStyle(fontSize: 16,color: Colors.green)), -// onPressed: () { -// Navigator.of(context).pop(); -// }, -// ), -// ], + Container( + padding: EdgeInsets.fromLTRB(5.0, 5.0, 10.0, 10.0), + //width: 100, + height: 35, + child: Text('免责声明', + style: TextStyle( + fontSize: 18, fontWeight: FontWeight.w700)), + decoration: BoxDecoration( + //color: Colors.blue, + image: DecorationImage( + fit: BoxFit.fitWidth, + image: AssetImage('assets/images/paimaiLogo.png')), + borderRadius: BorderRadius.all( + Radius.circular(10.0), + ), + //alignment: Alignment.bottomRight, + )), + SizedBox(height: 20), + Text(disclaimerText1), + Text(disclaimerText2), + ], + ), + ), + shape: RoundedRectangleBorder( + borderRadius: new BorderRadius.circular(20.0)), // 圆角 + + actions: [ + new Container( + width: 250, + child: _create(), ) - )], + ], ); }, ); } + + Row _create() { + //已读 + if (_readed) { + return Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + FlatButton( + padding: EdgeInsets.symmetric(horizontal: 20.0), + child: Text('已阅读知晓', + style: TextStyle(fontSize: 16, color: Colors.white)), + //可点击 + color: Theme.of(context).primaryColor, + onPressed: () { + Navigator.of(context).pop(); + }, + ), + SizedBox( + width: 10.0, + ) + ], + ); + } + + //第一次读取 + return Row(mainAxisAlignment: MainAxisAlignment.spaceAround, + //crossAxisAlignment:CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Checkbox( + activeColor: Theme.of(context).primaryColor, + tristate: false, + value: _valBool, + onChanged: (bool bol) { + setState(() { + _valBool = bol; + }); +// refs(bol); + Navigator.of(context) + .pop(); // here I pop to avoid multiple Dialogs + showAlertDialog(context); //here i call the same function + }), + Text('不再自动提示', style: TextStyle(fontSize: 14)), + ], + ), + FlatButton( + child: Text('知道了', + style: TextStyle(fontSize: 16, color: Colors.white)), + //可点击 + color: _valBool + ? Theme.of(context).primaryColor + : Theme.of(context).primaryColor.withAlpha(800), + onPressed: () { + // if (_valBool) { + refs(_valBool); + Navigator.of(context).pop(); + // } + }, + ), + ]); + } + Widget build(BuildContext context) { return new GestureDetector( - onTap: () { - showAlertDialog(context); - }, - child: Stack( - //alignment: const Alignment(1.6, 1.6), - children: [ - new Container( - width:90.0, - alignment: Alignment.center, - decoration: new BoxDecoration( - borderRadius:new BorderRadius.horizontal(right: Radius.circular(10)), - color: Colors.black45, - ), - child: new Text( - '🔔 免责声明', - style: new TextStyle( - fontSize: 14.0, - //fontWeight: FontWeight.bold, - color: Colors.white, + onTap: () { + showAlertDialog(context); + }, + child: Stack( + //alignment: const Alignment(1.6, 1.6), + children: [ + new Container( + width: 90.0, + alignment: Alignment.center, + decoration: new BoxDecoration( + borderRadius: + new BorderRadius.horizontal(right: Radius.circular(10)), + color: Colors.black45, ), - ), - ), - ], - ) - ); - } - - Widget build2(BuildContext context) { - return Container( - padding: new EdgeInsets.all(0.0), - alignment:Alignment.centerRight, - child:FlatButton( - //padding: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0), - child: new Text( - '👉 APP免责声明', - style: new TextStyle( - fontSize: 12.0, //textsize - color: Colors.black54, // textcolor - ), - ), - //color: Theme.of(context).accentColor, - color: Theme.of(context).accentColor, - //elevation: 0.0,//shadow - //splashColor: Colors.blueGrey, - onPressed: () { - showAlertDialog(context); - //Toast.show(context: context, message: "👉 APP免责声明",cb:showAlertDialog); - }) - ); - } -} - -class Toast { - static void show({@required BuildContext context, @required String message,Function cb}) { - //创建一个OverlayEntry对象 - OverlayEntry overlayEntry = new OverlayEntry(builder: (context) { - return new Positioned( - top: MediaQuery.of(context).size.height * 0.12, - right:5.0, - child:RaisedButton( - padding: new EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0), child: new Text( - '👉 APP免责声明', + '🔔 免责声明', style: new TextStyle( - fontSize: 14.0, //textsize - color: Colors.black54, // textcolor + fontSize: 14.0, + //fontWeight: FontWeight.bold, + color: Colors.white, ), ), - //color: Theme.of(context).accentColor, - color: Colors.red, - //elevation: 0.0,//shadow - //splashColor: Colors.blueGrey, - onPressed: () { - if(cb is Function){ - cb(context); - } - }) - ); - }); - //往Overlay中插入插入OverlayEntry - Overlay.of(context).insert(overlayEntry); - new Future.delayed(Duration(seconds: 2)).then((value) { - //overlayEntry.remove(); - }); + ), + ], + )); } -} \ No newline at end of file +} diff --git a/lib/components/fourth_page_feature/pages.dart b/lib/components/fourth_page_feature/pages.dart index 3fefb7fb..dbc01b02 100644 --- a/lib/components/fourth_page_feature/pages.dart +++ b/lib/components/fourth_page_feature/pages.dart @@ -15,14 +15,14 @@ final pages = [ //'assets/world.png', 'assets/images/p1.png', 'FLutterGo的背景', - '🐢 官网文档示例较不够健全,不够直观\n🐞 运行widget demo要到处翻阅资料\n🐌 英文文档翻译生涩难懂,学习资料太少\n', + '🐢 官网文档示例较不够健全,不够直观\n🐞 运行widget demo要到处翻阅资料\n🐌 英文文档翻译生涩难懂,学习资料太少\n🚀 需要的效果不知道用哪个widget\n', 'assets/images/calendar.png'), new PageViewModel( const Color(0xFFFF682D), //'assets/home.png', 'assets/images/p3.png', 'FlutterGo的特点', - '🐡 详解常用widget多达 130+ 个\n🦋 持续迭代追新官方版本\n🐙 配套Demo详解widget用法\n🚀 一站式搞定所有常用widget,开箱即查\n', + '🐡 详解常用widget多达 140+ 个\n🦋 持续迭代追新官方版本\n🐙 配套Demo详解widget用法\n🚀 一站式搞定所有常用widget,开箱即查\n', 'assets/images/house.png', ), ]; @@ -36,27 +36,32 @@ class Page extends StatelessWidget { this.percentVisible = 1.0, }); _goHomePage(context) { - Navigator.of(context).pushNamedAndRemoveUntil( - '/home', (Route route) => false); + Navigator.of(context) + .pushNamedAndRemoveUntil('/home', (Route route) => false); } - Widget creatButton(BuildContext context,String txt,IconData iconName,String type){ + Widget creatButton( + BuildContext context, String txt, IconData iconName, String type) { return RaisedButton.icon( onPressed: () { - if(type == 'start'){ + if (type == 'start') { _goHomePage(context); - }else if(type == 'goGithub'){ - Application.router.navigateTo(context, '${Routes.webViewPage}?title=${Uri.encodeComponent(txt)} Doc&&url=${Uri.encodeComponent("https://github.com/alibaba/flutter-go")}'); + } else if (type == 'goGithub') { + Application.router.navigateTo(context, + '${Routes.webViewPage}?title=${Uri.encodeComponent(txt)} Doc&&url=${Uri.encodeComponent("https://github.com/alibaba/flutter-go")}'); } }, elevation: 10.0, - color:Colors.black26, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20)), + color: Colors.black26, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), //如果不手动设置icon和text颜色,则默认使用foregroundColor颜色 - icon: new Icon(iconName,color: Colors.white,size:20.0), - label: new Text(txt, maxLines: 1,style: TextStyle(color:Colors.white,fontSize: 16,fontWeight: FontWeight.w700),) - ); + icon: new Icon(iconName, color: Colors.white, size: 20.0), + label: new Text( + txt, + maxLines: 1, + style: TextStyle( + color: Colors.white, fontSize: 16, fontWeight: FontWeight.w700), + )); } @override @@ -66,60 +71,69 @@ class Page extends StatelessWidget { color: viewModel.color, padding: const EdgeInsets.fromLTRB(0, 0, 0, 0), child: new Opacity( - opacity: percentVisible, - child: new Column( - crossAxisAlignment:CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Transform( - transform: new Matrix4.translationValues(0.0, 50.0 * (1.0 - percentVisible) ,0.0), - child: new Padding( - padding: new EdgeInsets.only(top: 20.0, bottom: 10.0), - child: - new Image.asset( - viewModel.heroAssetPath, - width: 200.0, - height: 200.0), - ), - ), - new Transform( - transform: new Matrix4.translationValues(0.0, 30.0 * (1.0 - percentVisible) ,0.0), - child: new Padding( - padding: new EdgeInsets.only(top: 10.0, bottom: 10.0), - child: new Text( - viewModel.title, - style: new TextStyle( - color: Colors.white, - fontFamily: 'FlamanteRoma', - fontSize: 34.0, - ), - ), - ), - ), - new Transform( - transform: new Matrix4.translationValues(0.0, 30.0 * (1.0 - percentVisible) ,0.0), - child: new Padding( - padding: new EdgeInsets.only(bottom: 10.0), - child: new Text( - viewModel.body, - textAlign: TextAlign.center, - style: new TextStyle( - height:1.2, - color: Colors.white, - fontFamily: 'FlamanteRomaItalic', - fontSize: 18.0, - ), - ), - ), - ), - ButtonBar( - alignment: MainAxisAlignment.center, - children: [ - creatButton(context,'开始使用',Icons.add_circle_outline,'start'), - creatButton(context,'GitHub',Icons.arrow_forward,'goGithub'), - ],) - ]), - )); + opacity: percentVisible, + child:ListView( + children: [ + layout(context) + ], + ), + )); + } + + Column layout(BuildContext context) { + return new Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Transform( + transform: new Matrix4.translationValues( + 0.0, 50.0 * (1.0 - percentVisible), 0.0), + child: new Padding( + padding: new EdgeInsets.only(top: 20.0, bottom: 10.0), + child: new Image.asset(viewModel.heroAssetPath, + width: 160.0, height: 160.0), + ), + ), + new Transform( + transform: new Matrix4.translationValues( + 0.0, 30.0 * (1.0 - percentVisible), 0.0), + child: new Padding( + padding: new EdgeInsets.only(top: 10.0, bottom: 10.0), + child: new Text( + viewModel.title, + style: new TextStyle( + color: Colors.white, + fontFamily: 'FlamanteRoma', + fontSize: 28.0, + ), + ), + ), + ), + new Transform( + transform: new Matrix4.translationValues( + 0.0, 30.0 * (1.0 - percentVisible), 0.0), + child: new Padding( + padding: new EdgeInsets.only(bottom: 10.0), + child: new Text( + viewModel.body, + textAlign: TextAlign.center, + style: new TextStyle( + height: 1.2, + color: Colors.white, + fontFamily: 'FlamanteRomaItalic', + fontSize: 18.0, + ), + ), + ), + ), + ButtonBar( + alignment: MainAxisAlignment.center, + children: [ + creatButton(context, '开始使用', Icons.add_circle_outline, 'start'), + creatButton(context, 'GitHub', Icons.arrow_forward, 'goGithub'), + ], + ) + ]); } } diff --git a/lib/views/first_page.dart b/lib/views/first_page.dart index d364b3e3..6de4a951 100644 --- a/lib/views/first_page.dart +++ b/lib/views/first_page.dart @@ -7,7 +7,6 @@ import 'package:flutter_go/components/pagination.dart'; import 'package:flutter_go/components/first_page_item.dart'; import 'package:flutter_go/components/disclaimer_msg.dart'; import 'package:shared_preferences/shared_preferences.dart'; - import '../common/net_utils.dart'; GlobalKey key; @@ -18,54 +17,35 @@ class FirstPage extends StatefulWidget { } class FirstPageState extends State with AutomaticKeepAliveClientMixin{ + Future _prefs=SharedPreferences.getInstance(); + Future _unKnow; @override bool get wantKeepAlive => true; - save(bool flag) async{ - //print('=============save=========$flag'); - SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('disclaimer', flag.toString()); - } - Future get() async { - var value; - SharedPreferences prefs = await SharedPreferences.getInstance(); - value = prefs.getString('disclaimer'); - return value; - } - - @override + @override void initState() { super.initState(); - if(key == null) { - //print('=============111=========${key}'); - delayed(); + if (key == null) { + key = GlobalKey(); + //获取sharePre + _unKnow = _prefs.then((SharedPreferences prefs) { + return (prefs.getBool('disclaimer') ?? false); + }); + /** + * 判断是否需要弹出免责声明,已经勾选过不在显示,就不会主动弹 + */ + _unKnow.then((bool value) { + print("==========FirstPageState========_unKnow========${value}"); + if (!value) { + key.currentState.showAlertDialog(context); + } + }); } - key = GlobalKey(); - + } - /* - * 判断是否需要弹出免责声明,已经勾选过不在显示,就不会主动弹 - * */ - Future delayed() async { - await new Future.delayed(const Duration(seconds: 1)); -// if (this.mounted) { -// setState(() { -// print('test=======>${key.currentState}'); -// key.currentState.showAlertDialog(context); -// //key.currentState.init(context); -// }); -// } - Future flag = get(); - flag.then((String value) { - //print('=============get=========$value'); - if(value.toString() == 'false'){ // 如果没有勾选下次开启 - key.currentState.showAlertDialog(context); - } - }); - } Future getIndexListData([Map params]) async { const juejin_flutter = 'https://timeline-merger-ms.juejin.im/v1/get_tag_entry?src=web&tagId=5a96291f6fb9a0535b535438'; diff --git a/lib/views/welcome_page/fourth_page.dart b/lib/views/welcome_page/fourth_page.dart index 149f3689..b2ca6f41 100644 --- a/lib/views/welcome_page/fourth_page.dart +++ b/lib/views/welcome_page/fourth_page.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'package:flutter/material.dart'; @@ -13,34 +12,32 @@ class FourthPage extends StatefulWidget { } class FourthPageState extends State with TickerProviderStateMixin { - StreamController slideUpdateStream; AnimatedPageDragger animatedPageDragger; - int activeIndex = 0 ; + int activeIndex = 0; SlideDirection slideDirection = SlideDirection.none; - int nextPageIndex = 0 ; - double slidePercent= 0.0; + int nextPageIndex = 0; + double slidePercent = 0.0; - FourthPageState(){ + FourthPageState() { slideUpdateStream = new StreamController(); - slideUpdateStream.stream.listen((SlideUpdate event){ + slideUpdateStream.stream.listen((SlideUpdate event) { setState(() { - if( event.updateType == UpdateType.dragging){ + if (event.updateType == UpdateType.dragging) { slideDirection = event.direction; slidePercent = event.slidePercent; - if( slideDirection == SlideDirection.leftToRight ){ + if (slideDirection == SlideDirection.leftToRight) { nextPageIndex = activeIndex - 1; - } else if (slideDirection == SlideDirection.rightToLeft){ + } else if (slideDirection == SlideDirection.rightToLeft) { nextPageIndex = activeIndex + 1; - } else{ + } else { nextPageIndex = activeIndex; } - } else if( event.updateType == UpdateType.doneDragging){ - if(slidePercent > 0.5){ - + } else if (event.updateType == UpdateType.doneDragging) { + if (slidePercent > 0.5) { animatedPageDragger = new AnimatedPageDragger( slideDirection: slideDirection, transitionGoal: TransitionGoal.open, @@ -48,8 +45,7 @@ class FourthPageState extends State with TickerProviderStateMixin { slideUpdateStream: slideUpdateStream, vsync: this, ); - - } else{ + } else { animatedPageDragger = new AnimatedPageDragger( slideDirection: slideDirection, transitionGoal: TransitionGoal.close, @@ -62,13 +58,10 @@ class FourthPageState extends State with TickerProviderStateMixin { } animatedPageDragger.run(); - } - else if( event.updateType == UpdateType.animating){ + } else if (event.updateType == UpdateType.animating) { slideDirection = event.direction; slidePercent = event.slidePercent; - } - - else if (event.updateType == UpdateType.doneAnimating){ + } else if (event.updateType == UpdateType.doneAnimating) { activeIndex = nextPageIndex; slideDirection = SlideDirection.none; @@ -78,23 +71,22 @@ class FourthPageState extends State with TickerProviderStateMixin { } }); }); - - } @override Widget build(BuildContext context) { return new Stack( children: [ - new Page( // page 的主要内容 + new Page( + // page 的主要内容 viewModel: pages[activeIndex], - percentVisible: 1.0 , + percentVisible: 1.0, ), new PageReveal( revealPercent: slidePercent, child: new Page( viewModel: pages[nextPageIndex], - percentVisible: slidePercent , + percentVisible: slidePercent, ), ), new PagerIndicator( @@ -106,8 +98,8 @@ class FourthPageState extends State with TickerProviderStateMixin { ), ), new PageDragger( - canDragLeftToRight: activeIndex > 0 , - canDragRightToLeft: activeIndex < pages.length - 1 , + canDragLeftToRight: activeIndex > 0, + canDragRightToLeft: activeIndex < pages.length - 1, slideUpdateStream: this.slideUpdateStream, ) ],