From 6c030f22fd8f7260503b24525576df43a0bedb85 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Sun, 7 Feb 2021 16:01:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=83=AD=E9=97=A8=E8=AF=9D=E9=A2=98=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 1 + lib/extensions/widget_list_ext.dart | 1 + lib/model/community/hot_topic_model.dart | 18 +++++++ lib/provider/app_provider.dart | 13 +++++ .../community_views/add_new_event_page.dart | 49 +++++++++++++++++-- 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 lib/model/community/hot_topic_model.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index a5812abe..3628907f 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -202,6 +202,7 @@ class _Community { ///社区话题:评论 String get sendAComment => '/user/gambit/comment'; + } class _Upload { diff --git a/lib/extensions/widget_list_ext.dart b/lib/extensions/widget_list_ext.dart index 03daa608..1382ca1d 100644 --- a/lib/extensions/widget_list_ext.dart +++ b/lib/extensions/widget_list_ext.dart @@ -6,6 +6,7 @@ import 'num_ext.dart'; extension WidgetListExt on List { List sepWidget({Widget separate}) { + if (this.isEmpty) return []; return List.generate(this.length * 2 - 1, (index) { if (index.isEven) return this[index ~/ 2]; diff --git a/lib/model/community/hot_topic_model.dart b/lib/model/community/hot_topic_model.dart new file mode 100644 index 00000000..4bb0f456 --- /dev/null +++ b/lib/model/community/hot_topic_model.dart @@ -0,0 +1,18 @@ +class HotTopicModel { + int id; + String name; + + HotTopicModel({this.id, this.name}); + + HotTopicModel.fromJson(Map json) { + id = json['id']; + name = json['name']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['name'] = this.name; + return data; + } +} diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 3f9de533..9d848015 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -1,4 +1,8 @@ // Flutter imports: +import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/community/hot_topic_model.dart'; +import 'package:akuCommunity/utils/network/base_model.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:flutter/material.dart'; // Project imports: @@ -57,4 +61,13 @@ class AppProvider extends ChangeNotifier { removeApplication(AO obj) { if (_myApplications.remove(obj)) notifyListeners(); } + + List _hotTopicModels = []; + List get hotTopicModels => _hotTopicModels; + updateHotTopicModel() async { + BaseModel model = await NetUtil().get(API.community.hotTopic); + _hotTopicModels = + (model.data as List).map((e) => HotTopicModel.fromJson(e)).toList(); + notifyListeners(); + } } diff --git a/lib/ui/community/community_views/add_new_event_page.dart b/lib/ui/community/community_views/add_new_event_page.dart index b88ec46a..2b4f899c 100644 --- a/lib/ui/community/community_views/add_new_event_page.dart +++ b/lib/ui/community/community_views/add_new_event_page.dart @@ -2,12 +2,15 @@ import 'dart:io'; // Flutter imports: +import 'package:akuCommunity/model/community/hot_topic_model.dart'; +import 'package:akuCommunity/provider/app_provider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; // Package imports: import 'package:bot_toast/bot_toast.dart'; import 'package:get/get.dart'; +import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; // Project imports: @@ -29,6 +32,7 @@ class _AddNewEventPageState extends State { bool _commentable = true; List _files = []; TextEditingController _textEditingController = TextEditingController(); + HotTopicModel _hotTopicModel; ///发表动态 _addEvent() async { @@ -40,8 +44,7 @@ class _AddNewEventPageState extends State { } Map params = { - //TODO 话题ID - 'gambitId': -1, + 'gambitId': _hotTopicModel == null ? -1 : _hotTopicModel.id, 'content': content, 'isComment': _commentable ? 1 : 0, 'isPublic': 1, @@ -91,6 +94,46 @@ class _AddNewEventPageState extends State { ); } + _pickTopic() { + final appProvider = Provider.of(context); + return Wrap( + direction: Axis.horizontal, + children: [ + '选择话题:'.text.black.size(34.sp).make(), + ...appProvider.hotTopicModels + .map((e) => _renderTopic(e)) + .toList() + .sepWidget(separate: 20.wb), + ], + ); + } + + Widget _renderTopic(HotTopicModel model) { + bool sameModel = model.id == _hotTopicModel?.id ?? -1; + return MaterialButton( + elevation: 0, + color: sameModel ? kPrimaryColor : Colors.white, + onPressed: () { + _hotTopicModel = model; + setState(() {}); + }, + child: model.name.text.size(34.sp).black.make(), + shape: StadiumBorder( + side: BorderSide( + color: Color(0xFF999999), + width: 1.w, + ), + ), + ); + } + + @override + void initState() { + super.initState(); + final appProvider = Provider.of(context, listen: false); + appProvider.updateHotTopicModel(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -146,7 +189,7 @@ class _AddNewEventPageState extends State { _buildSelectable(), Divider(height: 1.w), 28.hb, - //TODO 选择话题 + _pickTopic(), ], ).material(color: Colors.white), );