@@ -70,10 +70,10 @@ class BaseWidgetRegister { | |||||
'profile_header', DefaultWidgetCreater((model) => MineHeader(model))); | 'profile_header', DefaultWidgetCreater((model) => MineHeader(model))); | ||||
WidgetFactory.regist( | WidgetFactory.regist( | ||||
'profile_earning', DefaultWidgetCreater((model) => MineData(model))); | 'profile_earning', DefaultWidgetCreater((model) => MineData(model))); | ||||
WidgetFactory.regist( | |||||
'profile_functions', DefaultWidgetCreater((model) => MineQuickEntry())); | |||||
WidgetFactory.regist('profile_functions', | |||||
DefaultWidgetCreater((model) => MineQuickEntry(model))); | |||||
WidgetFactory.regist('profile_my_functions', | WidgetFactory.regist('profile_my_functions', | ||||
DefaultWidgetCreater((model) => MineQuickEntry())); | |||||
DefaultWidgetCreater((model) => MineQuickEntry(model))); | |||||
WidgetFactory.regist('profile_carousel', | WidgetFactory.regist('profile_carousel', | ||||
DefaultWidgetCreater((model) => HomeBannerWidget(model))); | DefaultWidgetCreater((model) => HomeBannerWidget(model))); | ||||
@@ -1,41 +0,0 @@ | |||||
import 'dart:async'; | |||||
import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/models/mine_quick_entry_model.dart'; | |||||
import 'package:zhiying_comm/util/base_bloc.dart'; | |||||
import 'package:zhiying_comm/zhiying_comm.dart'; | |||||
class MineQuickEntryBloc extends BlocBase { | |||||
List<MineQuickEntryModel> _icons = List(); | |||||
StreamController<List<MineQuickEntryModel>> _iconsController = | |||||
StreamController<List<MineQuickEntryModel>>(); | |||||
Stream<List<MineQuickEntryModel>> get outData => _iconsController.stream; | |||||
@override | |||||
void dispose() { | |||||
_iconsController.close(); | |||||
_iconsController = null; | |||||
} | |||||
void loadData(int id) { | |||||
NetUtil.request('/api/v1/mod', | |||||
method: NetMethod.POST, | |||||
params: Map<String, dynamic>.from({ | |||||
'ids': [id] | |||||
}), | |||||
onCache: (data) {}, onSuccess: (data) { | |||||
String key = id.toString(); | |||||
Map<String, dynamic> json = Map<String, dynamic>.from(data); | |||||
if (json.containsKey(key)) { | |||||
List<dynamic> list = json[key]; | |||||
_icons = list.map((item) { | |||||
return MineQuickEntryModel.fromJson(Map<String, dynamic>.from(item)); | |||||
}).toList(); | |||||
} | |||||
_iconsController.add(_icons); | |||||
}); | |||||
} | |||||
} |
@@ -1,51 +1,96 @@ | |||||
import 'package:flutter/material.dart'; | |||||
import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/bloc/mine_quick_entry_bloc.dart'; | |||||
import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/mine_quick_entry_sk.dart'; | |||||
import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/models/mine_quick_entry_model.dart'; | |||||
import 'package:zhiying_comm/util/base_bloc.dart'; | |||||
class MineQuickEntry extends StatefulWidget { | |||||
@override | |||||
_MineQuickEntryState createState() => _MineQuickEntryState(); | |||||
} | |||||
class _MineQuickEntryState extends State<MineQuickEntry> { | |||||
@override | |||||
Widget build(BuildContext context) { | |||||
return BlocProvider<MineQuickEntryBloc>( | |||||
bloc: MineQuickEntryBloc(), | |||||
child: _MineQuickEntryContainer(), | |||||
); | |||||
} | |||||
} | |||||
import 'dart:convert' as convert; | |||||
class _MineQuickEntryContainer extends StatefulWidget { | |||||
@override | |||||
_MineQuickEntryContainerState createState() => | |||||
_MineQuickEntryContainerState(); | |||||
} | |||||
class _MineQuickEntryContainerState extends State<_MineQuickEntryContainer> { | |||||
MineQuickEntryBloc _bloc; | |||||
import 'package:cached_network_image/cached_network_image.dart'; | |||||
import 'package:flutter/material.dart'; | |||||
import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/model/mine_quick_model.dart'; | |||||
import 'package:zhiying_comm/zhiying_comm.dart'; | |||||
@override | |||||
void initState() { | |||||
_bloc = BlocProvider.of<MineQuickEntryBloc>(context); | |||||
_bloc.loadData(4); | |||||
class MineQuickEntry extends StatelessWidget { | |||||
final Map<String, dynamic> data; | |||||
Map<String, dynamic> json; | |||||
MineQuickModel model; | |||||
super.initState(); | |||||
MineQuickEntry(this.data, {Key key}) : super(key: key) { | |||||
String d = data['data']; | |||||
json = convert.jsonDecode(d); | |||||
model = MineQuickModel.fromJson(Map<String, dynamic>.from(json)); | |||||
} | } | ||||
@override | @override | ||||
Widget build(BuildContext context) { | Widget build(BuildContext context) { | ||||
return StreamBuilder<List<MineQuickEntryModel>>( | |||||
stream: _bloc.outData, | |||||
builder: (BuildContext context, AsyncSnapshot snapshot) { | |||||
if (snapshot.data == null) { | |||||
return MineQuickEntrySkeleton(); | |||||
} | |||||
int column = int.tryParse(model.layout) ?? 4; | |||||
return MineQuickEntrySkeleton(); | |||||
}); | |||||
return (model?.items?.length ?? 0) <= 0 | |||||
? Container() | |||||
: Container( | |||||
margin: EdgeInsets.only( | |||||
left: 12.5, | |||||
right: 12.5, | |||||
top: 6, | |||||
bottom: 6, | |||||
), | |||||
width: double.infinity, | |||||
decoration: BoxDecoration( | |||||
borderRadius: BorderRadius.circular(7.5), | |||||
color: HexColor.fromHex(model.myFunctionsBgColor)), | |||||
child: Column( | |||||
crossAxisAlignment: CrossAxisAlignment.start, | |||||
children: <Widget>[ | |||||
(model?.title ?? '') == '' | |||||
? Container() | |||||
: Container( | |||||
margin: | |||||
EdgeInsets.only(left: 12.5, right: 12.5, top: 12.5), | |||||
child: Text( | |||||
model.title, | |||||
style: TextStyle( | |||||
fontSize: 15, fontWeight: FontWeight.w500), | |||||
), | |||||
), | |||||
GridView.builder( | |||||
shrinkWrap: true, | |||||
physics: NeverScrollableScrollPhysics(), | |||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | |||||
crossAxisCount: column, | |||||
crossAxisSpacing: 1, | |||||
mainAxisSpacing: 1, | |||||
childAspectRatio: 1, | |||||
), | |||||
itemCount: model?.items?.length ?? 0, | |||||
itemBuilder: (BuildContext context, int index) { | |||||
return GestureDetector( | |||||
child: Container( | |||||
child: Center( | |||||
child: Column( | |||||
mainAxisAlignment: MainAxisAlignment.center, | |||||
children: <Widget>[ | |||||
Container( | |||||
width: 36, | |||||
height: 36, | |||||
margin: EdgeInsets.only(bottom: 4), | |||||
child: CachedNetworkImage( | |||||
imageUrl: model.items[index].icon, | |||||
fit: BoxFit.cover, | |||||
), | |||||
), | |||||
Text( | |||||
model.items[index].name, | |||||
style: TextStyle( | |||||
color: HexColor.fromHex('#333333'), | |||||
fontSize: 11), | |||||
) | |||||
], | |||||
), | |||||
), | |||||
), | |||||
onTap: () { | |||||
RouterUtil.route(model.items[index].toJson(), context); | |||||
}, | |||||
); | |||||
}, | |||||
), | |||||
], | |||||
), | |||||
); | |||||
} | } | ||||
} | } |
@@ -0,0 +1,68 @@ | |||||
import 'package:json_annotation/json_annotation.dart'; | |||||
part 'mine_quick_model.g.dart'; | |||||
@JsonSerializable() | |||||
class MineQuickModel extends Object { | |||||
@JsonKey(name: 'my_functions_text') | |||||
String title; | |||||
@JsonKey(name: 'my_functions_text_color') | |||||
String titleColor; | |||||
@JsonKey(name: 'layout') | |||||
String layout; | |||||
@JsonKey(name: 'functions_bg_color') | |||||
String myFunctionsBgColor; | |||||
@JsonKey(name: 'functions_list') | |||||
List<MineQuickItemModel> items; | |||||
MineQuickModel( | |||||
this.title, | |||||
this.titleColor, | |||||
this.layout, | |||||
this.myFunctionsBgColor, | |||||
this.items, | |||||
); | |||||
factory MineQuickModel.fromJson(Map<String, dynamic> srcJson) => | |||||
_$MineQuickModelFromJson(srcJson); | |||||
Map<String, dynamic> toJson() => _$MineQuickModelToJson(this); | |||||
} | |||||
@JsonSerializable() | |||||
class MineQuickItemModel extends Object { | |||||
@JsonKey(name: 'name') | |||||
String name; | |||||
@JsonKey(name: 'name_color') | |||||
String nameColor; | |||||
@JsonKey(name: 'icon') | |||||
String icon; | |||||
@JsonKey(name: 'required_login') | |||||
String requiredLogin; | |||||
@JsonKey(name: 'required_taobao_auth') | |||||
String requiredTaobaoAuth; | |||||
@JsonKey(name: 'skip_identifier') | |||||
String skipIdentifier; | |||||
MineQuickItemModel( | |||||
this.name, | |||||
this.icon, | |||||
this.requiredLogin, | |||||
this.requiredTaobaoAuth, | |||||
this.skipIdentifier, | |||||
); | |||||
factory MineQuickItemModel.fromJson(Map<String, dynamic> srcJson) => | |||||
_$MineQuickItemModelFromJson(srcJson); | |||||
Map<String, dynamic> toJson() => _$MineQuickItemModelToJson(this); | |||||
} |
@@ -0,0 +1,50 @@ | |||||
// GENERATED CODE - DO NOT MODIFY BY HAND | |||||
part of 'mine_quick_model.dart'; | |||||
// ************************************************************************** | |||||
// JsonSerializableGenerator | |||||
// ************************************************************************** | |||||
MineQuickModel _$MineQuickModelFromJson(Map<String, dynamic> json) { | |||||
return MineQuickModel( | |||||
json['my_functions_text'] as String, | |||||
json['my_functions_text_color'] as String, | |||||
json['layout'] as String, | |||||
json['functions_bg_color'] as String, | |||||
(json['functions_list'] as List) | |||||
?.map((e) => e == null | |||||
? null | |||||
: MineQuickItemModel.fromJson(e as Map<String, dynamic>)) | |||||
?.toList(), | |||||
); | |||||
} | |||||
Map<String, dynamic> _$MineQuickModelToJson(MineQuickModel instance) => | |||||
<String, dynamic>{ | |||||
'my_functions_text': instance.title, | |||||
'my_functions_text_color': instance.titleColor, | |||||
'layout': instance.layout, | |||||
'functions_bg_color': instance.myFunctionsBgColor, | |||||
'functions_list': instance.items, | |||||
}; | |||||
MineQuickItemModel _$MineQuickItemModelFromJson(Map<String, dynamic> json) { | |||||
return MineQuickItemModel( | |||||
json['name'] as String, | |||||
json['icon'] as String, | |||||
json['required_login'] as String, | |||||
json['required_taobao_auth'] as String, | |||||
json['skip_identifier'] as String, | |||||
)..nameColor = json['name_color'] as String; | |||||
} | |||||
Map<String, dynamic> _$MineQuickItemModelToJson(MineQuickItemModel instance) => | |||||
<String, dynamic>{ | |||||
'name': instance.name, | |||||
'name_color': instance.nameColor, | |||||
'icon': instance.icon, | |||||
'required_login': instance.requiredLogin, | |||||
'required_taobao_auth': instance.requiredTaobaoAuth, | |||||
'skip_identifier': instance.skipIdentifier, | |||||
}; |
@@ -1,3 +0,0 @@ | |||||
class MineQuickEntryModel { | |||||
static fromJson(Map map) {} | |||||
} |