当前位置:网站首页>flutter 参数传一个范型数据
flutter 参数传一个范型数据
2022-08-02 07:18:00 【氤氲息】
可以一个个的传参数进去,也可以整个范型传值进去
///窗口模型
class ChatDialogModel {
BottleModel bottleModel;
int type;
ChatDialogModel({
required this.bottleModel, required this.type});
}
//范类
/// app_id : "string"
/// down_time : 0
/// down_user_id : 0
/// drift_bottle_id : 0
/// level : 0
/// no_read_num : 0
/// status : 0
/// text : "string"
/// up_time : 0
/// up_user_id : 0
class BottleModel {
BottleModel({
String? appId,
int? downTime,
int? downUserId,
int? driftBottleId,
int? level,
int? noReadNum,
int? status,
String? text,
int? upTime,
int? upUserId,
}) {
_appId = appId;
_downTime = downTime;
_downUserId = downUserId;
_driftBottleId = driftBottleId;
_level = level;
_noReadNum = noReadNum;
_status = status;
_text = text;
_upTime = upTime;
_upUserId = upUserId;
}
BottleModel.fromJson(dynamic json) {
_appId = json['app_id'];
_downTime = json['down_time'];
_downUserId = json['down_user_id'];
_driftBottleId = json['drift_bottle_id'];
_level = json['level'];
_noReadNum = json['no_read_num'];
_status = json['status'];
_text = json['text'];
_upTime = json['up_time'];
_upUserId = json['up_user_id'];
}
String? _appId;
int? _downTime;
int? _downUserId;
int? _driftBottleId;
int? _level;
int? _noReadNum;
int? _status;
String? _text;
int? _upTime;
int? _upUserId;
BottleModel copyWith({
String? appId,
int? downTime,
int? downUserId,
int? driftBottleId,
int? level,
int? noReadNum,
int? status,
String? text,
int? upTime,
int? upUserId,
}) =>
BottleModel(
appId: appId ?? _appId,
downTime: downTime ?? _downTime,
downUserId: downUserId ?? _downUserId,
driftBottleId: driftBottleId ?? _driftBottleId,
level: level ?? _level,
noReadNum: noReadNum ?? _noReadNum,
status: status ?? _status,
text: text ?? _text,
upTime: upTime ?? _upTime,
upUserId: upUserId ?? _upUserId,
);
String? get appId => _appId;
int? get downTime => _downTime;
int? get downUserId => _downUserId;
int? get driftBottleId => _driftBottleId;
int? get level => _level;
int? get noReadNum => _noReadNum;
int? get status => _status;
String? get text => _text;
int? get upTime => _upTime;
int? get upUserId => _upUserId;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{
};
map['app_id'] = _appId;
map['down_time'] = _downTime;
map['down_user_id'] = _downUserId;
map['drift_bottle_id'] = _driftBottleId;
map['level'] = _level;
map['no_read_num'] = _noReadNum;
map['status'] = _status;
map['text'] = _text;
map['up_time'] = _upTime;
map['up_user_id'] = _upUserId;
return map;
}
}
///弹出留言窗口,里面的参数要带上那个范类,required是该数据是必须的
showChatDialog(context, int state, int index,
{
required ChatDialogModel chatDialogModel}) {
showModalBottomSheet(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24), topRight: Radius.circular(24))),
isScrollControlled: true,
enableDrag: false,
backgroundColor: CommonColors.getColorF5F8F5,
context: context,
builder: (context) =>
ChatDialog(state, index, chatDialogModel: chatDialogModel))//范型数据传给chatDialog
.then((value) {
EventBusUtil.fire(
OnCloseBottleRefresh(CloudCustomDataBean.TYPE_DRIFT_BOTTLE));
});
}
ChatDialog里面
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:provider/provider.dart';
import 'package:social_im/constant/constant.dart';
import 'package:social_im/logevent/key_events.dart';
import 'package:social_im/logevent/log_event.dart';
import 'package:social_im/pages/moment/dialog/playDisposition.dart';
import 'package:social_im/provider/bottle_provider.dart';
import 'package:social_im/utils/date_util.dart';
import '../../../common/Global.dart';
import '../../../common/avatar.dart';
import '../../../common/colors.dart';
import '../../../common/globalEventBus.dart';
import '../../../generated/l10n.dart';
import '../../../http/api.dart';
import '../../../http/net_callback.dart';
import '../../../http/rxhttp.dart';
import '../../../http/utils/NetUtils.dart';
import '../../../http/utils/response.dart';
import '../../../im/user_info.dart';
import '../../../models/activity/matchUserBean.dart';
import '../../../models/cloudCustomDataBean.dart';
import '../../../router.dart';
import '../../../utils/image_utile.dart';
import '../../../utils/loadingUtil.dart';
import '../../../utils/textfield_util.dart';
import '../../../widget/user_ex_info.dart';
import '../../moment/dialog/matchFriendDialog.dart';
import '../../person/personItemPage/friendFilesPage.dart';
import '../../widget/myText.dart';
import '../../widget/splitLine.dart';
import '../chat_view.dart';
import '../data/bottle_model.dart';
import '../data/reply_list.dart';
import '../data/unlock_user.dart';
///漂流瓶留言窗口
class ChatDialog extends StatefulWidget {
final ChatDialogModel chatDialogModel;
int state;
int index;
ChatDialog(this.state, this.index, {
Key? key, required this.chatDialogModel})
: super(key: key);
@override
State<StatefulWidget> createState() => _ChatDialog();
}
class _ChatDialog extends State<ChatDialog> with WidgetsBindingObserver {
final TextEditingController _inputController = TextEditingController();
final FocusNode _focusNode = FocusNode();
bool isShowKeyboard = false;
double keyboardSize = Global.screenHeight * 0.4;
UnlockUser? _unlockUser;
ReplyList? replyList;
late StreamSubscription<MatchDialogEvent> _matchDialogEvent;
@override
void initState() {
super.initState();
_getUnLockUserInfoStatus(widget.chatDialogModel.type == 0
? widget.chatDialogModel.bottleModel.upUserId ?? 0
: widget.chatDialogModel.bottleModel.downUserId ?? 0);//可以在这里直接用了
WidgetsBinding.instance!.addObserver(this);
//输入框焦点监测
_focusNode.addListener(() {
if (_focusNode.hasFocus) {
if (MediaQuery.of(context).viewInsets.bottom > 0) {
isShowKeyboard = true;
}
} else {
isShowKeyboard = false;
}
if (mounted) {
setState(() {
});
}
});
_getReplyList(
driftBottleId: widget.chatDialogModel.bottleModel.driftBottleId,
status: 1,
pageTime: DateUtil.getNowDateS(),
);
_matchDialogEvent = EventBusUtil.listen((event) {
if (event.matchType == 2 && event.playType == PlayDisposition.BOTTLE) {
unlockUserInfo();
}
});
} //软键盘高度
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setShowBottomView();
},
child: Container(
decoration: BoxDecorationUtil().setFillBoxDecorationImg(
'assets/images/match/bg_match_chat.png'),
height: Global.screenHeight - 140,
child: Column(mainAxisSize: MainAxisSize.min, children: [
addHeadView(),
if (widget.index % 3 == 0)
Container(
width: MediaQuery.of(context).size.width,
alignment: Alignment.centerLeft,
margin:
const EdgeInsets.only(left: 16, right: 16, bottom: 16),
padding: const EdgeInsets.only(
left: 16, top: 16, bottom: 16, right: 16),
decoration: BoxDecoration(
color: const Color(0xFFF8F9FF),
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(color: Color(0xFFBCC0EE), blurRadius: 3)
]),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.chatDialogModel.bottleModel.text ?? '',
style: const TextStyle(
color: Color(0xFF333333), fontSize: 18),
),
Container(
margin: EdgeInsets.only(top: 8),
child: Text(
DateUtil.formatDateMs(
widget.chatDialogModel.bottleModel.downTime! *
1000,
format: 'yyyy.MM.dd'),
style: const TextStyle(
color: Color(0xFF999999), fontSize: 12),
),
),
],
)),
if (widget.index % 3 == 1)
Container(
width: MediaQuery.of(context).size.width,
alignment: Alignment.centerLeft,
margin:
const EdgeInsets.only(left: 16, right: 16, bottom: 16),
padding: const EdgeInsets.only(
left: 16, top: 16, bottom: 16, right: 16),
decoration: BoxDecoration(
color: const Color(0xFFEDFAFF),
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(color: Color(0xFFBCE2F1), blurRadius: 3)
]),
child: ContentLeftText(
widget.chatDialogModel.bottleModel.text ?? '',
14,
CommonColors.getColor333333)),
if (widget.index % 3 == 2)
Container(
width: MediaQuery.of(context).size.width,
alignment: Alignment.centerLeft,
margin:
const EdgeInsets.only(left: 16, right: 16, bottom: 16),
padding: const EdgeInsets.only(
left: 16, top: 16, bottom: 16, right: 16),
decoration: BoxDecoration(
color: const Color(0xFFFBFFF2),
borderRadius: BorderRadius.circular(12),
boxShadow: const [
BoxShadow(color: Color(0xFFDBEBB6), blurRadius: 3)
]),
child: ContentLeftText(
widget.chatDialogModel.bottleModel.text ?? '',
14,
CommonColors.getColor333333)),
Expanded(
child: ChatView(
bottleModel: widget.chatDialogModel.bottleModel,
)),
Container(
margin: EdgeInsets.only(
left: 15,
right: 15,
top: 10,
bottom: isShowKeyboard ? keyboardSize : 30),
padding: const EdgeInsets.only(left: 16),
alignment: Alignment.bottomRight,
decoration: BoxDecorationUtil()
.setFillBoxDecoration(Colors.white, 14.0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: TextField(
controller: _inputController,
onSubmitted: (s) {
// onSubmitted(s, context);
},
focusNode: _focusNode,
autocorrect: false,
textAlign: TextAlign.left,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.send,
cursorColor: CommonColors.getThemeColor(),
decoration: const InputDecoration(
border: InputBorder.none,
isCollapsed: true,
isDense: true),
style: const TextStyle(fontSize: 14))),
GestureDetector(
onTap: () {
String s = _inputController.text.toString();
if (s == '' || s == null) {
return;
}
///todo sendMSG
_sendreply(
widget.chatDialogModel.bottleModel
.driftBottleId ??
0,
widget.state,
s);
_inputController.clear();
},
child: Container(
padding: const EdgeInsets.only(
top: 12, bottom: 12, right: 19, left: 19),
margin: const EdgeInsets.only(left: 16),
alignment: Alignment.center,
decoration: BoxDecorationUtil()
.setFillBoxDecoration(
CommonColors.getColor27D6BC, 14.0),
child: ContentCenterTextBlod(S.current.send_out,
16.0, Colors.white, FontWeight.normal)))
]))
])));
}
Widget addHeadView() {
return Container(
color: Colors.transparent,
padding: const EdgeInsets.only(top: 16, bottom: 13),
child: Row(mainAxisSize: MainAxisSize.max, children: [
GestureDetector(
onTap: () {
closeView();
},
child: const Padding(
padding: EdgeInsets.only(left: 16, right: 10),
child: Image(
image: AssetImage('assets/images/[email protected]'),
width: 24,
height: 24))),
if (getAvatar() == "") Spacer(),
if (getAvatar() != "")
GestureDetector(
onTap: () {
},
child: Padding(
padding: const EdgeInsets.only(right: 8),
child: PhysicalModel(
shape: BoxShape.circle,
color: Colors.transparent,
borderRadius: BorderRadius.circular(4.8),
clipBehavior: Clip.antiAlias,
child: Avatar(
width: 36,
height: 36,
radius: 0,
avtarUrl: getAvatar(),
svgaAvtarUrl: Global.defUserImag)))),
if (getSex() != 2 || getBirthday() != -1 || getName() != "")
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
UserExInfoWidget(
nickName: getName(),
nickFontSize: 17.0,
nickFontColor: CommonColors.getColor1A1A1A,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
alignment: Alignment.center,
margin: const EdgeInsets.only(right: 6),
padding: const EdgeInsets.fromLTRB(3, 1, 5, 2),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Image(
image: AssetImage(getSex() == 1
? 'assets/images/icon_gender_male.png'
: 'assets/images/icon_gender_female.png'),
gaplessPlayback: true,
width: 11,
height: 11),
Padding(
padding:
const EdgeInsets.only(top: 2),
child: ContentText(
'${
UserInfoUtil().getAge(getBirthday())}',
9.0,
Colors.white))
]),
decoration: BoxDecorationUtil()
.setFillBoxDecoration(
getSex() == 1
? CommonColors.getColor7E8FF7
: CommonColors.getColorF77EBE,
10.0)),
Offstage(
offstage: true,
child: Container(
padding: const EdgeInsets.only(right: 6),
child: ImageUtile.imageWidget(
'assets/images/vip/[email protected]2x.png',
height: 14)))
]))
])),
GestureDetector(
onTap: () {
setShowBottomView();
Future.delayed(const Duration(milliseconds: 100), () {
if (_unlockUser != null) {
showUserInfo();
} else {
_getUnLockUserInfoStatus(
widget.chatDialogModel.type == 0
? widget.chatDialogModel.bottleModel.upUserId ?? 0
: widget.chatDialogModel.bottleModel.downUserId ??
0, callBack: () {
showUserInfo();
});
}
// showUserInfo(playType);
});
},
child: const Padding(
padding: EdgeInsets.only(left: 10, right: 16),
child: Image(
image: AssetImage(
'assets/images/match/icon_match_user_info.png'),
width: 32,
height: 32)))
]));
}
///解锁用户信息窗口
showUserInfo() {
// if (UserInfoUtil()
// .isMyUser('${widget.chatDialogModel.bottleModel.downUserId}')) {
// MyRouter.pushMy(context, PersonalFilesPage());
// return;
// }
// if (_unlockUser?.unlockStatus == 1) {
// MyRouter.pushMy(
// context,
// UserInfoUtil()
// .isMyUser('${widget.chatDialogModel.bottleModel.downUserId}')
// ? PersonalFilesPage()
// : FriendFilesPage(
// false, '${widget.chatDialogModel.bottleModel.downUserId}'));
// }
if (_unlockUser?.unlockStatus == 1) {
if (widget.chatDialogModel.type == 0) {
MyRouter.pushMy(
context,
FriendFilesPage(
false, '${
widget.chatDialogModel.bottleModel.upUserId}'));
} else if (widget.chatDialogModel.type != 0) {
MyRouter.pushMy(
context,
FriendFilesPage(
false, '${
widget.chatDialogModel.bottleModel.downUserId}'));
}
} else {
showModalBottomSheet(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24), topRight: Radius.circular(24))),
isScrollControlled: true,
enableDrag: false,
backgroundColor: CommonColors.getColorF5F8F5,
context: context,
builder: (context) => MatchFriendDialog(
2,
PlayDisposition.BOTTLE,
MatchUserBean(
userID: _unlockUser?.userInfo?.userId,
nickName: _unlockUser?.userInfo?.nickname,
avatar: _unlockUser?.userInfo?.avatar,
// avatarThumb:_unlockUser?.userInfo?.avatarThumb,
sign: _unlockUser?.userInfo?.sign,
sex: _unlockUser?.userInfo?.sex,
birthday: _unlockUser?.userInfo?.birthday,
vipLevel: _unlockUser?.userInfo?.vipLevel
// vipExpirationTime:_unlockUser?.userInfo?.vipExpirationTime
)));
}
}
setShowBottomView() {
TextFieldUtil.stowTheKeyboard(context);
}
closeView() {
setShowBottomView();
Future.delayed(const Duration(milliseconds: 100), () {
Navigator.pop(context);
});
}
}
///窗口模型
class ChatDialogModel {
BottleModel bottleModel;
int type;
ChatDialogModel({
required this.bottleModel, required this.type});
}
///弹出留言窗口
showChatDialog(context, int state, int index,
{
required ChatDialogModel chatDialogModel}) {
showModalBottomSheet(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24), topRight: Radius.circular(24))),
isScrollControlled: true,
enableDrag: false,
backgroundColor: CommonColors.getColorF5F8F5,
context: context,
builder: (context) =>
ChatDialog(state, index, chatDialogModel: chatDialogModel))
.then((value) {
EventBusUtil.fire(
OnCloseBottleRefresh(CloudCustomDataBean.TYPE_DRIFT_BOTTLE));
});
}
使用方式,调用showChatDialog,传值进去
Expanded(
child: TabBarView(
controller: _tabController,
children: tabs.map((chose) {
switch (chose.position) {
case 0:
return MyThrowBottle(
downList: driftBottleList?.downList ?? [],
onItemClicked: (index) {
showChatDialog(context, 2, index,
chatDialogModel: ChatDialogModel(
type: 0,
bottleModel: driftBottleList
?.downList![index] ??
BottleModel()));
},
);
case 1:
return MyBottle(
upList: driftBottleList?.upList ?? [],
onItemClicked: (index) {
showChatDialog(context, 1, index,
chatDialogModel: ChatDialogModel(
type: 1,
bottleModel: driftBottleList
?.upList![index] ??
BottleModel()));
});
default:
return Container();
}
}).toList()))
边栏推荐
猜你喜欢

OC-error prompt

2022-08-01 第四小组 修身课 学习笔记(every day)

(2022 Nioke Duo School 5) C-Bit Transmission (Thinking)

mysql操作入门(四)-----数据排序(升序、降序、多字段排序)

Splunk Filed extraction 字段截取
![[Unity3D] Beginner Encryption Skills (Anti-Cracking)](/img/07/4a0731dd66b058c07d6240ffd36eea.png)
[Unity3D] Beginner Encryption Skills (Anti-Cracking)

论文理解:“Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution,Denoising, and “

MySQL-执行流程+缓存+存储引擎

Compact格式下MySQL的数据如何存储到磁盘

Probability Theory and Mathematical Statistics
随机推荐
MySQL-索引优化和查询优化
FormData上传二进制文件、对象、对象数组
爬虫 视频爬取工具you-get
ROS文件系统以及相关命令
我与csdn
Chain Of Responsibility
pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies
MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
MPLS和BGP的综合实验
Transimpedance amplifier
Link with Game Glitch
通过建立新的SaaS业务来推动增长的六种方法
Install Metasploitable2 on VMware
Inverter insulation detection detection function and software implementation
Aided by training and learning by battle | The new version of the Offensive and Defense World Platform is officially launched!
Data reveal that the average cost is as high as $4.35 million in 2022, a record!
FormData upload binary file, object, object array
机器学习笔记--数学库
MySQL - locking mechanism
数据中台:始于阿里,兴于DaaS