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