热门话题对接

hmxc
小赖 4 years ago
parent 45a20baf18
commit 6c030f22fd

@ -202,6 +202,7 @@ class _Community {
/// ///
String get sendAComment => '/user/gambit/comment'; String get sendAComment => '/user/gambit/comment';
} }
class _Upload { class _Upload {

@ -6,6 +6,7 @@ import 'num_ext.dart';
extension WidgetListExt on List<Widget> { extension WidgetListExt on List<Widget> {
List<Widget> sepWidget({Widget separate}) { List<Widget> sepWidget({Widget separate}) {
if (this.isEmpty) return [];
return List.generate(this.length * 2 - 1, (index) { return List.generate(this.length * 2 - 1, (index) {
if (index.isEven) if (index.isEven)
return this[index ~/ 2]; return this[index ~/ 2];

@ -0,0 +1,18 @@
class HotTopicModel {
int id;
String name;
HotTopicModel({this.id, this.name});
HotTopicModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['name'] = this.name;
return data;
}
}

@ -1,4 +1,8 @@
// Flutter imports: // 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'; import 'package:flutter/material.dart';
// Project imports: // Project imports:
@ -57,4 +61,13 @@ class AppProvider extends ChangeNotifier {
removeApplication(AO obj) { removeApplication(AO obj) {
if (_myApplications.remove(obj)) notifyListeners(); if (_myApplications.remove(obj)) notifyListeners();
} }
List<HotTopicModel> _hotTopicModels = [];
List<HotTopicModel> 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();
}
} }

@ -2,12 +2,15 @@
import 'dart:io'; import 'dart:io';
// Flutter imports: // 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/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// Package imports: // Package imports:
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
// Project imports: // Project imports:
@ -29,6 +32,7 @@ class _AddNewEventPageState extends State<AddNewEventPage> {
bool _commentable = true; bool _commentable = true;
List<File> _files = []; List<File> _files = [];
TextEditingController _textEditingController = TextEditingController(); TextEditingController _textEditingController = TextEditingController();
HotTopicModel _hotTopicModel;
/// ///
_addEvent() async { _addEvent() async {
@ -40,8 +44,7 @@ class _AddNewEventPageState extends State<AddNewEventPage> {
} }
Map<String, dynamic> params = { Map<String, dynamic> params = {
//TODO ID 'gambitId': _hotTopicModel == null ? -1 : _hotTopicModel.id,
'gambitId': -1,
'content': content, 'content': content,
'isComment': _commentable ? 1 : 0, 'isComment': _commentable ? 1 : 0,
'isPublic': 1, 'isPublic': 1,
@ -91,6 +94,46 @@ class _AddNewEventPageState extends State<AddNewEventPage> {
); );
} }
_pickTopic() {
final appProvider = Provider.of<AppProvider>(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<AppProvider>(context, listen: false);
appProvider.updateHotTopicModel();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -146,7 +189,7 @@ class _AddNewEventPageState extends State<AddNewEventPage> {
_buildSelectable(), _buildSelectable(),
Divider(height: 1.w), Divider(height: 1.w),
28.hb, 28.hb,
//TODO _pickTopic(),
], ],
).material(color: Colors.white), ).material(color: Colors.white),
); );

Loading…
Cancel
Save