Exemplo n.º 1
0
        public override Widget build(BuildContext context)
        {
            var children = this.widget.children;
            var slivers  = new List <Widget>();

            int id = 0;

            foreach (var child in children)
            {
                Widget sliver = new SliverList(
                    del: new SliverChildBuilderDelegate((BuildContext Subcontext, int index1) => {
                    return(child);
                },
                                                        childCount: 1),
                    key: id == this.widget.centerIndex ? this._selectedKey : null);

                slivers.Add(sliver);
                id++;
            }

            slivers.Add(new SliverToBoxAdapter(
                            child: this.widget.footerBuilder != null && this.widget.enablePullUp
                    ? this._buildWrapperByConfig(this.widget.footerConfig, false)
                    : new Container()
                            ));
            slivers.Insert(
                0,
                new SliverToBoxAdapter(
                    child: this.widget.headerBuilder != null && this.widget.enablePullDown
                        ? this._buildWrapperByConfig(this.widget.headerConfig, true)
                        : new Container()));
            return(new LayoutBuilder(builder: (cxt, cons) => {
                return new Stack(
                    children: new List <Widget> {
                    new Positioned(
                        top: !this.widget.enablePullDown || this.widget.headerConfig is LoadConfig
                                ? 0.0f
                                : -this._headerHeight,
                        bottom: !this.widget.enablePullUp || this.widget.footerConfig is LoadConfig
                                ? 0.0f
                                : -this._footerHeight,
                        left: 0.0f,
                        right: 0.0f,
                        child: new NotificationListener <ScrollNotification>(
                            child: new CustomScrollView(
                                physics: new RefreshScrollPhysics(enableOverScroll: false),
                                controller: this._scrollController,
                                slivers: slivers,
                                center: this._selectedKey
                                ),
                            onNotification: this._dispatchScrollEvent
                            )
                        )
                }
                    );
            }));
        }
Exemplo n.º 2
0
        public override Widget build(BuildContext context)
        {
            var channel = widget.channels[widget.selectedChannelId];

            Widget members;

            var screenSize     = MediaQuery.of(context).size;
            var screenWidth    = screenSize.width;
            var screenHeight   = screenSize.height;
            var containerWidth = screenWidth - 48;

            if (screenWidth >= 750)
            {
                containerWidth -= 375;
            }

            var countPerRow = (containerWidth / 240).floor();
            var rowCount    = ((widget.members.ContainsKey(channel.id) ? widget.members[channel.id].Count : 0) /
                               (float)countPerRow).ceil();

            if (!widget.hasMoreMembers.ContainsKey(widget.selectedChannelId))
            {
                widget.hasMoreMembers[widget.selectedChannelId] = true;
            }
            if (widget.hasMoreMembers[widget.selectedChannelId])
            {
                rowCount += 1;
            }

            members = new SliverList(
                del: new SliverChildBuilderDelegate(
                    builder: (buildContext, index) =>
            {
                if (widget.hasMoreMembers[widget.selectedChannelId] && index == rowCount - 1)
                {
                    return(new Container(
                               height: 78,
                               alignment: Alignment.center,
                               child: new LoadTrigger(
                                   onLoad: () =>
                    {
                        var offset = widget.members.ContainsKey(channel.id)
                                            ? widget.members[channel.id].Count
                                            : 0;
                        Utils.Get <GetMembersResponse>(
                            $"/api/connectapp/channels/{channel.id}/members?offset={offset}"
                            ).Then(response =>
                        {
                            response.list.ForEach(member =>
                            {
                                if (widget.members[channel.id].All(m => m.user.id != member.user.id))
                                {
                                    widget.members[channel.id].Add(member);
                                }

                                widget.users.putIfAbsent(member.user.id, () => member.user);
                            });

                            m_AmIOwner = widget.members[channel.id].Any(member =>
                                                                        member.user.id == Window.currentUserId && member.role == "owner");
                            widget.hasMoreMembers[widget.selectedChannelId] = response.total > widget.members[channel.id].Count;
                            if (mounted)
                            {
                                using (WindowProvider.of(context).getScope())
                                {
                                    setState(() => { });
                                }
                            }
                        });
                    }
                                   )
                               ));
                }

                var children = new List <Widget> {
                };
                for (var i = 0; i < countPerRow; ++i)
                {
                    if (index * countPerRow + i < widget.members[channel.id].Count)
                    {
                        var member = widget.members[channel.id][index * countPerRow + i];
                        children.Add(
                            new Expanded(
                                child: new Container(
                                    height: 78,
                                    width: 240,
                                    alignment: Alignment.center,
                                    child: new Container(
                                        height: 50,
                                        padding: EdgeInsets.only(
                                            top: 6,
                                            bottom: 4
                                            ),
                                        child: new Row(
                                            children: new List <Widget>
                        {
                            new Container(
                                margin: EdgeInsets.only(right: 8),
                                child: new Avatar(member.user)
                                ),
                            new Expanded(
                                child: new Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: new List <Widget>
                            {
                                new Text(
                                    member.user.fullName,
                                    style: new TextStyle(
                                        fontSize: 14,
                                        fontWeight: FontWeight.w500,
                                        fontFamily: "PingFang"
                                        ),
                                    overflow: TextOverflow.ellipsis
                                    ),
                                new Text(
                                    member.user.title ?? string.Empty,
                                    style: new TextStyle(
                                        color: new Color(0xff5a5a5b),
                                        fontSize: 14,
                                        fontFamily: "PingFang"
                                        ),
                                    overflow: TextOverflow.ellipsis
                                    )
                            }
                                    )
                                )
                        }
                                            )
                                        )
                                    )
                                )
                            );
                    }
                    else
                    {
                        children.Add(
                            new Expanded(
                                child: new Container(
                                    height: 78,
                                    width: 240
                                    )
                                )
                            );
                    }
                }

                return(new Container(
                           margin: EdgeInsets.symmetric(horizontal: 24),
                           decoration: new BoxDecoration(
                               border: new Border(
                                   top: new BorderSide(
                                       color: new Color(0xfff0f0f0)
                                       )
                                   )
                               ),
                           child: new Row(
                               mainAxisAlignment: MainAxisAlignment.start,
                               children: children
                               )
                           ));
            },
                    childCount: rowCount
                    )
                );

            var headerChildren = new List <Widget>
            {
                new Expanded(
                    child: new Text(
                        $"{channel.name}",
                        style: new TextStyle(
                            fontSize: 16,
                            fontWeight: FontWeight.w500,
                            color: new Color(0xff212121),
                            fontFamily: "PingFang"
                            )
                        )
                    ),
            };

            headerChildren.Add(
                new GestureDetector(
                    onTap: () =>
            {
                if (screenWidth < 750)
                {
                    m_AnimationController.reverse();
                }
                else
                {
                    HomePage.of(this.context).HideChannelInfo();
                }
            },
                    child: new Icon(
                        IconFont.IconFontClose,
                        color: new Color(0xff979a9e),
                        size: 28
                        )
                    )
                );

            Widget all = new Container(
                color: new Color(0xffffffff),
                child: new Scroller(
                    child: new CustomScrollView(
                        slivers: new List <Widget>
            {
                new SliverToBoxAdapter(
                    child: new Container(
                        height: 64,
                        decoration: new BoxDecoration(
                            border: new Border(
                                bottom: new BorderSide(
                                    color: new Color(0xffd8d8d8)
                                    )
                                )
                            ),
                        padding: EdgeInsets.symmetric(horizontal: 24),
                        alignment: Alignment.center,
                        child: new Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: headerChildren
                            )
                        )
                    ),
                MediaQuery.of(context).size.width < 750 ? BuildNarrowInfo() : BuildWideInfo(),
                new SliverToBoxAdapter(
                    child: new Container(
                        decoration: new BoxDecoration(
                            border: new Border(
                                top: new BorderSide(
                                    color: new Color(0xffd8d8d8)
                                    ),
                                bottom: new BorderSide(
                                    color: new Color(0xffd8d8d8)
                                    )
                                )
                            ),
                        padding: EdgeInsets.symmetric(vertical: 18),
                        margin: EdgeInsets.symmetric(horizontal: 24),
                        height: 78,
                        child: new Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: new List <Widget>
                {
                    new Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: new List <Widget>
                    {
                        new Text(
                            "消息免打扰",
                            style: new TextStyle(
                                fontSize: 14,
                                color: new Color(0xff212121),
                                fontFamily: "PingFang"
                                )
                            ),
                        new Text(
                            "打开后,将不会收到消息提醒",
                            style: new TextStyle(
                                fontSize: 14,
                                color: new Color(0xff797979),
                                fontFamily: "PingFang"
                                )
                            ),
                    }
                        ),
                    new Switch(
                        m_MuteController
                        )
                }
                            )
                        )
                    ),
                new SliverToBoxAdapter(
                    child: new Container(
                        decoration: new BoxDecoration(
                            border: new Border(
                                bottom: new BorderSide(
                                    color: new Color(0xffd8d8d8)
                                    )
                                )
                            ),
                        padding: EdgeInsets.symmetric(vertical: 18),
                        margin: EdgeInsets.symmetric(horizontal: 24),
                        height: 78,
                        child: new Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: new List <Widget>
                {
                    new Column(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: new List <Widget>
                    {
                        new Text(
                            "设为置顶",
                            style: new TextStyle(
                                fontSize: 14,
                                color: new Color(0xff212121),
                                fontFamily: "PingFang"
                                )
                            ),
                        new Text(
                            "打开后,当前群聊将会被置顶在群聊列表",
                            style: new TextStyle(
                                fontSize: 14,
                                color: new Color(0xff797979),
                                fontFamily: "PingFang"
                                )
                            )
                    }
                        ),
                    new Switch(
                        m_PinController
                        )
                }
                            )
                        )
                    ),
                new SliverToBoxAdapter(
                    child: new Container(
                        margin: EdgeInsets.only(top: 24, left: 24, right: 24),
                        padding: EdgeInsets.only(bottom: 8),
                        child: new Text(
                            $"群聊成员({channel.memberCount})",
                            style: new TextStyle(
                                fontSize: 18,
                                fontWeight: FontWeight.w500,
                                fontFamily: "PingFang"
                                )
                            )
                        )
                    ),
                members,
                new SliverToBoxAdapter(
                    child: new Container(
                        height: 56
                        )
                    )
            }
                        )
                    )
                );

            var stacked = new List <Widget> {
                all
            };

            if (!m_AmIOwner)
            {
                var quitButtonChildren = new List <Widget>();
                if (m_Quiting)
                {
                    quitButtonChildren.Add(
                        new Text(
                            "退出群聊",
                            style: new TextStyle(
                                fontSize: 18,
                                color: new Color(0x00000000),
                                fontFamily: "PingFang"
                                )
                            )
                        );
                    quitButtonChildren.Add(
                        new Loading(
                            size: 24
                            )
                        );
                }
                else
                {
                    quitButtonChildren.Add(new Text(
                                               "退出群聊",
                                               style: new TextStyle(
                                                   fontSize: 18,
                                                   color: new Color(0xfff44336),
                                                   fontFamily: "PingFang"
                                                   )
                                               )
                                           );
                }

                stacked.Add(
                    new Positioned(
                        bottom: 0,
                        left: 0,
                        right: 0,
                        child: new GestureDetector(
                            onTap: () =>
                {
                    if (m_Quiting)
                    {
                        return;
                    }
                    setState(() => m_Quiting = true);
                    var requestUrl           = string.IsNullOrEmpty(channel.groupId)
                                    ? $"/api/connectapp/v1/channels/{channel.id}/leave"
                                    : $"/api/connectapp/v1/groups/{channel.groupId}/leave";
                    var state = HomePage.of(context);
                    Utils.Post <Models.Channel>(
                        requestUrl,
                        "{}"
                        ).Then(c =>
                    {
                        state.Select(string.Empty);
                        state.RemoveChannel(channel);
                    });
                },
                            child: new Container(
                                height: 56,
                                decoration: new BoxDecoration(
                                    color: new Color(0xffffffff),
                                    border: new Border(
                                        top: new BorderSide(
                                            color: new Color(0xffd8d8d8)
                                            )
                                        )
                                    ),
                                alignment: Alignment.center,
                                child: new Stack(
                                    children: quitButtonChildren
                                    )
                                )
                            )
                        )
                    );
            }

            all = new Stack(
                children: stacked
                );

            if (screenWidth < 750)
            {
                all = Transform.translate(
                    offset: new Offset(0, (1 - m_AnimationController.value) * screenHeight),
                    child: all
                    );
            }

            return(all);
        }