diff --git a/.dart_tool/build_resolvers/sdk.sum b/.dart_tool/build_resolvers/sdk.sum deleted file mode 100644 index a788675..0000000 Binary files a/.dart_tool/build_resolvers/sdk.sum and /dev/null differ diff --git a/.dart_tool/build_resolvers/sdk.sum.deps b/.dart_tool/build_resolvers/sdk.sum.deps deleted file mode 100644 index 1c10e44..0000000 --- a/.dart_tool/build_resolvers/sdk.sum.deps +++ /dev/null @@ -1 +0,0 @@ -{"sdk":"2.7.2 (Mon Mar 23 22:11:27 2020 +0100) on \"macos_x64\"","analyzer":"/Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.39.14","build_resolvers":"/Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/build_resolvers-1.3.11"} \ No newline at end of file diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 92d5aef..8c1af58 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -770,7 +770,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-09-21T03:19:08.272955Z", + "generated": "2020-09-22T07:54:03.242397Z", "generator": "pub", "generatorVersion": "2.7.2" } diff --git a/lib/pages/setting_page/models/setting_page_style_item_model.dart b/lib/pages/setting_page/models/setting_page_style_item_model.dart new file mode 100644 index 0000000..c166bc3 --- /dev/null +++ b/lib/pages/setting_page/models/setting_page_style_item_model.dart @@ -0,0 +1,34 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'setting_page_style_item_model.g.dart'; + +@JsonSerializable() +class SettingPageStyleItemModel extends Object { + @JsonKey(name: 'name') + String name; + + @JsonKey(name: 'name_color') + String nameColor; + + @JsonKey(name: 'desc') + String desc; + + @JsonKey(name: 'desc_color') + String descColor; + + @JsonKey(name: 'skip_identifier') + String skipIdentifier; + + SettingPageStyleItemModel( + this.name, + this.nameColor, + this.desc, + this.descColor, + this.skipIdentifier, + ); + + factory SettingPageStyleItemModel.fromJson(Map srcJson) => + _$SettingPageStyleItemModelFromJson(srcJson); + + Map toJson() => _$SettingPageStyleItemModelToJson(this); +} diff --git a/lib/pages/setting_page/models/setting_page_style_item_model.g.dart b/lib/pages/setting_page/models/setting_page_style_item_model.g.dart new file mode 100644 index 0000000..996447a --- /dev/null +++ b/lib/pages/setting_page/models/setting_page_style_item_model.g.dart @@ -0,0 +1,28 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'setting_page_style_item_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SettingPageStyleItemModel _$SettingPageStyleItemModelFromJson( + Map json) { + return SettingPageStyleItemModel( + json['name'] as String, + json['name_color'] as String, + json['desc'] as String, + json['desc_color'] as String, + json['skip_identifier'] as String, + ); +} + +Map _$SettingPageStyleItemModelToJson( + SettingPageStyleItemModel instance) => + { + 'name': instance.name, + 'name_color': instance.nameColor, + 'desc': instance.desc, + 'desc_color': instance.descColor, + 'skip_identifier': instance.skipIdentifier, + }; diff --git a/lib/pages/setting_page/models/setting_page_style_model.dart b/lib/pages/setting_page/models/setting_page_style_model.dart new file mode 100644 index 0000000..70ed1c4 --- /dev/null +++ b/lib/pages/setting_page/models/setting_page_style_model.dart @@ -0,0 +1,51 @@ +import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_item_model.dart'; + +class SettingPageStyleModel extends Object { + String appBarName; + String appBarNameColor; + String appBarBgColor; + String logoutName; + String logoutNameColor; + String settingsBgColor; + List> settings; + + SettingPageStyleModel(this.appBarName, + this.appBarNameColor, + this.appBarBgColor, + this.logoutName, + this.logoutNameColor, + this.settingsBgColor, + this.settings,); + + factory SettingPageStyleModel.fromJson(Map json) { + var st = (json['settings'] as List).map((list) { + return (list as List) + ?.map((item) => + SettingPageStyleItemModel.fromJson( + Map.from(item))) + ?.toList() ?? + []; + })?.toList(); + return SettingPageStyleModel( + json['app_bar_name'] as String, + json['app_bar_name_color'] as String, + json['app_bar_bg_color'] as String, + json['logout_name'] as String, + json['logout_name_color'] as String, + json['settings_bg_color'] as String, + st, + ); + } + + Map toJson() { + return { + 'app_bar_name': this.appBarName, + 'app_bar_name_color': this.appBarNameColor, + 'app_bar_bg_color': this.appBarBgColor, + 'logout_name': this.logoutName, + 'logout_name_color': this.logoutNameColor, + 'settings_bg_color': this.settingsBgColor, + 'settings': this.settings, + }; + } +} diff --git a/lib/pages/setting_page/setting_page.dart b/lib/pages/setting_page/setting_page.dart index 4425023..d8bb7ec 100644 --- a/lib/pages/setting_page/setting_page.dart +++ b/lib/pages/setting_page/setting_page.dart @@ -1,4 +1,10 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_item_model.dart'; +import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_model.dart'; +import 'package:zhiying_base_widget/pages/setting_page/setting_page_bloc.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; class SettingPage extends StatefulWidget { final Map data; @@ -12,6 +18,110 @@ class SettingPage extends StatefulWidget { class _SettingPageState extends State { @override Widget build(BuildContext context) { - return Scaffold(); + return BlocProvider( + bloc: SettingPageBloc(), + child: _SettingContainer(widget.data), + ); + } +} + +class _SettingContainer extends StatefulWidget { + final Map data; + + const _SettingContainer( + this.data, { + Key key, + }) : super(key: key); + + @override + _SettingContainerState createState() => _SettingContainerState(); +} + +class _SettingContainerState extends State<_SettingContainer> { + SettingPageBloc _bloc; + + @override + void initState() { + _bloc = BlocProvider.of(context); + _bloc.loadData(widget.data['skip_identifier']); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return StreamBuilder( + stream: _bloc.outData, + builder: (BuildContext context, AsyncSnapshot snapshot) { + SettingPageStyleModel style = snapshot.data; + return Scaffold( + backgroundColor: Color(0xfff9f9f9), + appBar: _createNav(style), + body: SingleChildScrollView( + child: Column( + children: style?.settings?.map((list) { + return _createSection(list); + })?.toList() ?? + [], + ), + )); + }); + } + + // 导航栏 + Widget _createNav(SettingPageStyleModel style) { + return CupertinoNavigationBar( + border: Border( + bottom: BorderSide( + width: 0.0, // One physical pixel. + style: BorderStyle.none, + ), + ), + backgroundColor: HexColor.fromHex(style?.appBarBgColor ?? 'ffffff'), + leading: Navigator.canPop(context) + ? GestureDetector( + child: Container( + padding: EdgeInsets.zero, + child: Icon( + Icons.arrow_back_ios, + size: 20, + ), + ), + onTap: () { + if (Navigator.canPop(context)) { + Navigator.pop(context); + } + }, + ) + : Container(), + middle: Text( + style?.appBarName ?? '设置', + style: TextStyle( + fontSize: 15, + color: HexColor.fromHex(style?.appBarNameColor ?? '333333'), + ), + ), + ); + } + + Widget _createSection(List sections) { + return Container( + margin: EdgeInsets.only(top: 8), + child: Column( + children: sections.map((item) { + return _createItem(item); + }).toList(), + ), + ); + } + + Widget _createItem(SettingPageStyleItemModel item) { + return Container( + width: double.infinity, + height: 50, + color: Colors.white, + child: Row( + children: [Text(item.name), Text('aaaaa')], + ), + ); } } diff --git a/lib/pages/setting_page/setting_page_bloc.dart b/lib/pages/setting_page/setting_page_bloc.dart new file mode 100644 index 0000000..908f78e --- /dev/null +++ b/lib/pages/setting_page/setting_page_bloc.dart @@ -0,0 +1,36 @@ +import 'dart:async'; +import 'dart:convert' as convert; + +import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_model.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class SettingPageBloc extends BlocBase { + SettingPageStyleModel _style; + + StreamController _styleController = + StreamController(); + + Stream get outData => _styleController.stream; + + @override + void dispose() { + _styleController.close(); + _styleController = null; + } + + void loadData(String skipIdentifier) async { + Api api = Api( + '/api/v1/mod/${skipIdentifier.toString()}', method: NetMethod.GET,); + _loadData(await api.onCache()); + _loadData(await api.onRequest()); + } + + void _loadData(dynamic data) { + Map json = Map.from(data); + String d = json['data']; + Map da = Map.from(convert.jsonDecode(d)); + _style = SettingPageStyleModel.fromJson(da); + _styleController.add(_style); + } +} diff --git a/lib/widgets/mine/mine_nav/mine_nav.dart b/lib/widgets/mine/mine_nav/mine_nav.dart index eff9c3c..10620ff 100644 --- a/lib/widgets/mine/mine_nav/mine_nav.dart +++ b/lib/widgets/mine/mine_nav/mine_nav.dart @@ -96,7 +96,7 @@ class MineNavIcon extends StatelessWidget { ), onTap: () { print('页面跳转 ${model.skipIdentifier}'); - RouterUtil.route(data, context); + RouterUtil.route(model.toJson(), context); }, ); }