203 lines
5.6 KiB
Dart
Executable File
203 lines
5.6 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:flutter_app/view/page/help.dart';
|
|
|
|
import 'package:flutter_app/config/index.dart';
|
|
|
|
import 'package:flutter_app/event/themeChangeEvent.dart';
|
|
import 'package:flutter_app/event/indexLayoutChangeEvent.dart';
|
|
import 'package:flutter_app/common/Application.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:flutter_app/R.dart';
|
|
import 'package:flutter_app/model/IndexModel.dart';
|
|
//import 'package:flutter_app/view/components/ListWidget.dart';
|
|
|
|
import 'package:flutter_app/service/service.dart';
|
|
import 'package:flutter_refresh/flutter_refresh.dart';
|
|
|
|
class Home extends StatefulWidget {
|
|
@override
|
|
_Home createState() => _Home();
|
|
}
|
|
|
|
//
|
|
class _Home extends State<Home> with AutomaticKeepAliveClientMixin<Home> {
|
|
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
|
|
List<Body> modules = [];
|
|
int page = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// getData();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
getData() async {
|
|
this.page += 1;
|
|
Index data = await ServiceMethods().getImageList({ "page": this.page });
|
|
setState(() {
|
|
modules = data.body;
|
|
});
|
|
print(this.modules);
|
|
}
|
|
|
|
Future<Null> onFooterRefresh() {
|
|
return new Future.delayed(new Duration(seconds: 2), () {
|
|
getData();
|
|
});
|
|
}
|
|
|
|
Future<Null> onHeaderRefresh() {
|
|
return new Future.delayed(new Duration(seconds: 2), () {
|
|
print("上拉");
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: appBars(),
|
|
body: Container(
|
|
child: InkWell(
|
|
onTap: () {
|
|
this.getData();
|
|
},
|
|
child: new Text(
|
|
'测试',
|
|
textAlign: TextAlign.center,
|
|
),
|
|
)
|
|
),
|
|
drawer: drawers()
|
|
);
|
|
}
|
|
|
|
// 主体内容区域
|
|
// ignore: non_constant_identifier_names
|
|
// Widget BodyLayout () {
|
|
// return new Refresh(
|
|
// onFooterRefresh: onFooterRefresh,
|
|
// onHeaderRefresh: onHeaderRefresh,
|
|
// childBuilder: (BuildContext context, { ScrollController controller, ScrollPhysics physics }) {
|
|
// return new ListWidget(modules,controller,physics);
|
|
// },
|
|
// );
|
|
// }
|
|
|
|
// 顶部appbar
|
|
Widget appBars() {
|
|
return AppBar(
|
|
leading: new IconButton(
|
|
icon: new Icon(Icons.help_outline),
|
|
tooltip: '关于',
|
|
onPressed: () {
|
|
Navigator.push(context,new MaterialPageRoute(
|
|
builder:(context) => new Help())
|
|
);
|
|
},
|
|
),
|
|
title: Text('精选美图'),
|
|
actions: <Widget>[
|
|
IconButton(
|
|
icon: Config.indexLayout == "default" ? Icon(Icons.subject) : Icon(Icons.border_all),
|
|
tooltip: '切换布局',
|
|
onPressed: () {
|
|
setState(() {
|
|
if (Config.indexLayout == "default") {
|
|
Config.indexLayout = "twoColumn";
|
|
}else {
|
|
Config.indexLayout = "default";
|
|
}
|
|
changeIndexLayout();
|
|
});
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 抽屉侧边栏
|
|
Widget drawers() {
|
|
return new Drawer(
|
|
child: new ListView(
|
|
padding: new EdgeInsets.all(0.0),
|
|
children: <Widget>[
|
|
new UserAccountsDrawerHeader(
|
|
accountName: new Text(
|
|
'编码猿',
|
|
style: new TextStyle( fontWeight: FontWeight.bold ),
|
|
), //用户名
|
|
accountEmail: new Text('2271608011@qq.com'), //用户邮箱
|
|
currentAccountPicture: new GestureDetector( //用户头像
|
|
onTap: () => print('current user'),
|
|
child: new CircleAvatar( //圆形图标控件
|
|
backgroundImage: new AssetImage(
|
|
R.libStaticImgLogoPng
|
|
),
|
|
),
|
|
),
|
|
decoration: new BoxDecoration( //用一个BoxDecoration装饰器提供背景图片
|
|
image: new DecorationImage(
|
|
fit: BoxFit.fill,
|
|
image: new ExactAssetImage(R.libStaticImgShopJpg),
|
|
),
|
|
),
|
|
),
|
|
new ListTile(
|
|
title: new Text('设置中心'),
|
|
leading: new Icon(Icons.settings),
|
|
),
|
|
new ListTile(
|
|
title: Text(Config.dark ? "日间模式" : "夜间模式"),
|
|
leading: new Icon(Icons.brightness_2),
|
|
onTap: () {
|
|
setState(() {
|
|
if (Config.dark == true) {
|
|
Config.dark = false;
|
|
} else {
|
|
Config.dark = true;
|
|
}
|
|
print(Config.dark);
|
|
changeTheme();
|
|
});
|
|
},
|
|
),
|
|
new ListTile( //第二个功能项
|
|
title: new Text('关于我'),
|
|
leading: new Icon(Icons.account_circle),
|
|
onTap: () {
|
|
Navigator.of(context).pushNamed('/about');
|
|
},
|
|
),
|
|
new Divider(), //分割线控件
|
|
new ListTile( //退出按钮
|
|
title: new Text('关闭'),
|
|
leading: new Icon(Icons.cancel),
|
|
onTap: () => Navigator.of(context).pop(), //点击后收起侧边栏
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
changeIndexLayout() async {
|
|
SharedPreferences sp = await SharedPreferences.getInstance();
|
|
sp.setString("indexLayout", Config.indexLayout);
|
|
Application.eventBus.fire(new indexLayoutChangeEvent(Config.indexLayout));
|
|
}
|
|
|
|
changeTheme() async {
|
|
SharedPreferences sp = await SharedPreferences.getInstance();
|
|
sp.setBool("themeIndex", Config.dark);
|
|
Application.eventBus.fire(new themeChangeEvent(Config.dark));
|
|
}
|
|
|
|
} |