133 lines
3.9 KiB
Dart
Executable File
133 lines
3.9 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:flutter_app/model/ImageModel.dart';
|
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:flutter_app/config/index.dart';
|
|
import 'package:flutter_app/common/Application.dart';
|
|
import 'package:flutter_app/event/indexLayoutChangeEvent.dart';
|
|
|
|
class ListWidget extends StatefulWidget {
|
|
List<Infos> _infos = new List();
|
|
ScrollController controller;
|
|
ScrollPhysics physics;
|
|
ListWidget(this._infos,this.controller,this.x);
|
|
|
|
@override
|
|
_ListWidget createState() => _ListWidget();
|
|
}
|
|
|
|
// ignore: must_be_immutable
|
|
class _ListWidget extends State<ListWidget> {
|
|
|
|
String status;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
this.registerIndexEvent();
|
|
getLayoutStyle().then((onValue) {
|
|
setState(() {
|
|
status = onValue;
|
|
});
|
|
});
|
|
}
|
|
|
|
@override
|
|
// ignore: missing_return
|
|
Widget build(BuildContext context) {
|
|
if (widget._infos.length != 0) {
|
|
if(status == "default") {
|
|
return new ListView.builder(
|
|
physics: widget.physics,
|
|
controller: widget.controller,
|
|
itemCount: widget._infos.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return new Column(
|
|
children: <Widget>[
|
|
new Image.network(
|
|
widget._infos[index].imgurl,
|
|
fit: BoxFit.cover,
|
|
width: ScreenUtil.screenWidth,
|
|
),
|
|
new Padding(
|
|
padding: const EdgeInsets.all(5.0),
|
|
child: new Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
new Text(
|
|
widget._infos[index].title,
|
|
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
|
|
),
|
|
new Row(
|
|
children: <Widget>[
|
|
new Icon(Icons.visibility),
|
|
new Text(widget._infos[index].view),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
);
|
|
} else {
|
|
return new GridView.custom(
|
|
physics: widget.physics,
|
|
controller: widget.controller,
|
|
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
mainAxisSpacing: 4.0,
|
|
crossAxisSpacing: 4.0,
|
|
),
|
|
childrenDelegate: new SliverChildBuilderDelegate( (context, index) {
|
|
return new Container(
|
|
child: new Image.network(
|
|
widget._infos[index].imgurl,
|
|
fit: BoxFit.cover,
|
|
width: ScreenUtil.screenWidth,
|
|
),
|
|
);
|
|
},
|
|
childCount: widget._infos.length,
|
|
),
|
|
);
|
|
}
|
|
|
|
}else {
|
|
return new SpinKitWave (
|
|
color: Colors.orange,
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void registerIndexEvent() {
|
|
Application.eventBus
|
|
.on<indexLayoutChangeEvent>()
|
|
.listen((indexLayoutChangeEvent onData) => this.changeTheme(onData));
|
|
}
|
|
|
|
// 更改页面布局
|
|
void changeTheme(indexLayoutChangeEvent onData) {
|
|
setState(() {
|
|
status = onData.LayoutStyle;
|
|
});
|
|
}
|
|
|
|
Future<String> getLayoutStyle() async {
|
|
SharedPreferences layoutSharedPreferences = await SharedPreferences.getInstance();
|
|
String ls = layoutSharedPreferences.getString("indexLayout");
|
|
if (ls == null) {
|
|
ls = Config.indexLayout;
|
|
}
|
|
Config.indexLayout = ls;
|
|
return ls;
|
|
}
|
|
|
|
State<StatefulWidget> createState() {
|
|
// TODO: implement createState
|
|
return null;
|
|
}
|
|
} |