Skip to content

Commit

Permalink
init chat ui
Browse files Browse the repository at this point in the history
  • Loading branch information
bai-3 authored and bai-3 committed Oct 31, 2024
1 parent 2951444 commit b65faec
Show file tree
Hide file tree
Showing 31 changed files with 800 additions and 740 deletions.
2 changes: 1 addition & 1 deletion lib/application/store/im_state.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ignore_for_file: depend_on_referenced_packages
import 'dart:async';
import 'package:dtim/infra/pages/channel/setting/key_verification_dialog.dart';
import 'package:dtim/infra/pages/chat/channel/setting/key_verification_dialog.dart';
import 'package:dtim/domain/utils/functions.dart';
import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:easy_debounce/easy_debounce.dart';
Expand Down
22 changes: 13 additions & 9 deletions lib/infra/components/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Avatar extends StatelessWidget {
final double fontSize;
final Color? bg;
final Color? color;
final double radius;

const Avatar({
required this.id,
Expand All @@ -31,10 +32,11 @@ class Avatar extends StatelessWidget {
this.onTap,
this.client,
this.fontSize = 18,
Key? key,
this.radius = 3,
super.key,
this.bg,
this.color,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -81,7 +83,7 @@ class Avatar extends StatelessWidget {
} else {
container = id == ""
? CircleAvatar(
radius: 3,
radius: radius,
child: Container(
width: size,
height: size,
Expand All @@ -96,6 +98,7 @@ class Avatar extends StatelessWidget {
size,
color: color,
bg: bg,
radius: radius,
);
}

Expand All @@ -113,8 +116,9 @@ class BaseAvatar extends StatefulWidget {
final double avatarWidth;
final Color? bg;
final Color? color;
final double radius;

const BaseAvatar(this.avatarSrc, this.online, this.avatarWidth, {super.key, this.bg, this.color});
const BaseAvatar(this.avatarSrc, this.online, this.avatarWidth, {super.key, this.bg, this.color, this.radius = 3});

@override
State<BaseAvatar> createState() => _BaseAvatarState();
Expand All @@ -125,16 +129,16 @@ class _BaseAvatarState extends State<BaseAvatar> {

buildCtx(BuildContext context) {
final constTheme = Theme.of(context).extension<ExtColors>()!;
final imgw = (widget.avatarWidth * 0.7).toInt();
final imgw = (widget.avatarWidth * 0.7 - widget.radius/4).toInt();
final imgbg = widget.color ?? constTheme.centerChannelColor;
final boxBg = widget.bg ?? constTheme.centerChannelColor.withOpacity(0.1);
final img = Identicon(fg: [imgbg.red, imgbg.green, imgbg.blue]).generate(
getUserShortId(widget.avatarSrc),
scale: (widget.avatarWidth / 50).ceil(),
scale: (widget.avatarWidth / 6).ceil(),
);

ctx = Container(
decoration: BoxDecoration(borderRadius: BorderRadius.circular(3), color: boxBg),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(widget.radius), color: boxBg),
padding: EdgeInsets.all((widget.avatarWidth - imgw) / 2),
alignment: Alignment.topLeft,
child: Image.memory(
Expand Down Expand Up @@ -178,11 +182,11 @@ class BaseAvatarWithPop extends StatefulWidget {
this.name,
this.online,
this.avatarWidth, {
Key? key,
super.key,
this.bg,
this.color,
this.mxContent,
}) : super(key: key);
});

@override
State<BaseAvatarWithPop> createState() => _BaseAvatarWithPopState();
Expand Down
1 change: 0 additions & 1 deletion lib/infra/components/components.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export 'app_bar.dart';
export 'channel_list.dart';
export 'move_window.dart';
export 'direct_chat.dart';
export 'avatar.dart';
Expand Down
15 changes: 12 additions & 3 deletions lib/infra/components/hover_list_item.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:dtim/application/chain/wetee/wetee_gen/types/frame_support/dispatch/raw_origin.dart';
import 'package:flutter/material.dart';

class HoverListItem extends StatefulWidget {
Expand All @@ -9,9 +10,11 @@ class HoverListItem extends StatefulWidget {
final Widget? trailing;
final Widget child;
final String subkey;
final double radius;
final EdgeInsetsGeometry? margin;

const HoverListItem({
Key? key,
super.key,
required this.onPressed,
required this.child,
this.trailing,
Expand All @@ -20,7 +23,9 @@ class HoverListItem extends StatefulWidget {
this.ishover,
required this.subkey,
this.onHover,
}) : super(key: key);
this.radius = 0,
this.margin,
});

@override
HoverListItemState createState() => HoverListItemState();
Expand Down Expand Up @@ -50,7 +55,11 @@ class HoverListItemState extends State<HoverListItem> {
behavior: HitTestBehavior.translucent,
onTap: () => widget.onPressed(),
child: Container(
color: calcHover ? widget.hoverColor : widget.color,
margin: widget.margin,
decoration: BoxDecoration(
borderRadius: widget.radius > 0 ? BorderRadius.circular(widget.radius) : BorderRadius.zero,
color: calcHover ? widget.hoverColor : widget.color,
),
child: widget.trailing == null
? widget.child
: Row(
Expand Down
7 changes: 4 additions & 3 deletions lib/infra/components/me_pop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class MePop extends StatefulWidget {
this.name,
this.online,
this.avatarWidth, {
Key? key,
super.key,
this.bg,
this.color,
this.mxContent,
}) : super(key: key);
});

@override
State<MePop> createState() => _MePopState();
Expand All @@ -54,7 +54,8 @@ class _MePopState extends State<MePop> {
color: widget.color,
id: widget.id,
mxContent: widget.mxContent,
size: 40.w,
size: widget.avatarWidth,
radius: widget.avatarWidth/2,
),
menuBuilder: () => Container(
width: 270.w,
Expand Down
7 changes: 3 additions & 4 deletions lib/infra/components/model_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ class ModelBar extends StatelessWidget implements PreferredSizeWidget {
final String _title;
final Widget? tools;
final Function? onBack;
ModelBar({Key? key, this.onBack, this.tools, String? title, double? height})
: _height = (height ?? 50.w).toInt().toDouble(),
_title = title ?? "",
super(key: key);
ModelBar({super.key, this.onBack, this.tools, String? title, double? height})
: _height = (height ?? 55.w).toInt().toDouble(),
_title = title ?? "";

@override
Widget build(BuildContext context) {
Expand Down
171 changes: 87 additions & 84 deletions lib/infra/components/sider_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,101 +9,104 @@ class SiderBarItem extends StatelessWidget {
final String name;
final bool selected;
final Function? onTap;
final Color? bg;

const SiderBarItem(this.name, {super.key, this.icon, required this.selected, this.onTap, this.img});
const SiderBarItem(this.name, {super.key, this.icon, required this.selected, this.onTap, this.img, this.bg});

@override
Widget build(BuildContext context) {
final constTheme = Theme.of(context).extension<ExtColors>()!;
return InkWell(
onTap: () {
onTap?.call();
},
child: Container(
width: 52.w,
height: 52.w,
padding: EdgeInsets.only(top: 4.w),
decoration: BoxDecoration(
color: selected ? constTheme.sidebarText.withOpacity(0.1) : Colors.transparent,
borderRadius: BorderRadius.circular(6.w),
),
margin: EdgeInsets.only(bottom: 5.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
icon != null
? Icon(
icon!,
color: constTheme.sidebarText,
size: 20.w,
)
: (img != null
? Image.network(
img!,
width: 20.w,
height: 20.w,
fit: BoxFit.cover,
color: constTheme.sidebarText,
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Container(
width: 20.w,
height: 20.w,
decoration: BoxDecoration(
color: constTheme.sidebarText,
borderRadius: BorderRadius.all(Radius.circular(3.w)),
),
child: Center(
child: Text(
name[0],
style: TextStyle(
fontSize: 12.w,
color: constTheme.sidebarBg,
fontWeight: FontWeight.bold,
final bgc = bg ?? constTheme.sidebarText.withOpacity(0.1);
return Padding(
padding: EdgeInsets.only(bottom: 5.w),
child: InkWell(
onTap: () {
onTap?.call();
},
child: Container(
width: 52.w,
padding: EdgeInsets.only(top: 10.w, bottom: 6.w),
decoration: BoxDecoration(
color: selected ? bgc : Colors.transparent,
borderRadius: BorderRadius.circular(6.w),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
icon != null
? Icon(
icon!,
color: constTheme.sidebarText,
size: 16.w,
)
: (img != null
? Image.network(
img!,
width: 16.w,
height: 16.w,
fit: BoxFit.cover,
color: constTheme.sidebarText,
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Container(
width: 16.w,
height: 16.w,
decoration: BoxDecoration(
color: constTheme.sidebarText,
borderRadius: BorderRadius.all(Radius.circular(3.w)),
),
child: Center(
child: Text(
name[0],
style: TextStyle(
fontSize: 12.w,
color: constTheme.sidebarBg,
fontWeight: FontWeight.bold,
),
),
),
),
);
},
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Container(
width: 20.w,
height: 20.w,
decoration: BoxDecoration(
color: constTheme.sidebarText,
borderRadius: BorderRadius.all(Radius.circular(3.w)),
),
child: Center(
child: Text(
name[0],
style: TextStyle(
fontSize: 12.w,
color: constTheme.sidebarBg,
fontWeight: FontWeight.bold,
);
},
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Container(
width: 20.w,
height: 20.w,
decoration: BoxDecoration(
color: constTheme.sidebarText,
borderRadius: BorderRadius.all(Radius.circular(3.w)),
),
child: Center(
child: Text(
name[0],
style: TextStyle(
fontSize: 12.w,
color: constTheme.sidebarBg,
fontWeight: FontWeight.bold,
),
),
),
),
);
},
)
: SizedBox(
width: 20.w,
height: 20.w,
)),
SizedBox(height: 3.w),
Container(
padding: EdgeInsets.symmetric(horizontal: 3.w),
height: 14.w,
child: Text(
name.split("&").first,
style: TextStyle(
color: constTheme.sidebarText,
fontSize: 10.w,
);
},
)
: SizedBox(
width: 20.w,
height: 20.w,
)),
// SizedBox(height: 3.w),
Container(
padding: EdgeInsets.symmetric(horizontal: 3.w),
height: 14.w,
child: Text(
name.split("&").first,
style: TextStyle(
color: constTheme.sidebarText,
fontSize: 10.w,
),
overflow: TextOverflow.ellipsis,
),
overflow: TextOverflow.ellipsis,
),
),
],
],
),
),
),
);
Expand Down
Loading

0 comments on commit b65faec

Please sign in to comment.