From 3055c29e7b8d15f8c8cb50a28397ee2ed289c193 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sun, 10 Mar 2019 21:26:05 +0800 Subject: [PATCH] feat: list group style --- lib/screens/notifications.dart | 76 +++++++++++++++++----------------- lib/screens/user.dart | 23 +++++----- lib/widgets/list_group.dart | 23 +++++++--- 3 files changed, 68 insertions(+), 54 deletions(-) diff --git a/lib/screens/notifications.dart b/lib/screens/notifications.dart index c5001ae..3b42ab1 100644 --- a/lib/screens/notifications.dart +++ b/lib/screens/notifications.dart @@ -119,41 +119,42 @@ $key: pullRequest(number: ${item.number}) { var group = entry.value; var repo = group.repo; return ListGroup( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - repo, - style: TextStyle(color: Colors.black, fontSize: 16), - ), - Link( - material: false, - onTap: () async { - await SettingsProvider.of(context) - .putWithCredentials('/repos/$repo/notifications'); - await _onSwitchTab(); - }, - child: Icon( - Octicons.check, - color: Colors.black45, - size: 24, - ), - ), - ], - ), - items: group.items, - itemBuilder: (item, index) { - return NotificationItem( - payload: item, - markAsRead: () { - if (mounted) { - setState(() { - groupMap[entry.key].items[index].unread = false; - }); - } + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + repo, + style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600), + ), + Link( + material: false, + onTap: () async { + await SettingsProvider.of(context) + .putWithCredentials('/repos/$repo/notifications'); + await _onSwitchTab(); }, - ); - }); + child: Icon( + Octicons.check, + color: Colors.black45, + size: 24, + ), + ), + ], + ), + items: group.items, + itemBuilder: (item, index) { + return NotificationItem( + payload: item, + markAsRead: () { + if (mounted) { + setState(() { + groupMap[entry.key].items[index].unread = false; + }); + } + }, + ); + }, + ); } Future _onSwitchTab([int index]) async { @@ -257,9 +258,10 @@ $key: pullRequest(number: ${item.number}) { return groupMap.isEmpty ? EmptyWidget() : Column( - children: groupMap.entries - .map((entry) => _buildGroupItem(context, entry)) - .toList()); + children: [Padding(padding: EdgeInsets.only(top: 10))]..addAll( + groupMap.entries + .map((entry) => _buildGroupItem(context, entry)) + .toList())); }, ); } diff --git a/lib/screens/user.dart b/lib/screens/user.dart index d38c9cc..88d593d 100644 --- a/lib/screens/user.dart +++ b/lib/screens/user.dart @@ -79,17 +79,18 @@ class _UserScreenState extends State { } return ListGroup( - title: Text( - title, - style: TextStyle(fontSize: 16), - ), - items: items, - itemBuilder: (item, _) { - return RepoItem( - item, - showOwner: item['owner']['login'] != widget.login, - ); - }); + title: Text( + title, + style: TextStyle(fontSize: 16), + ), + items: items, + itemBuilder: (item, _) { + return RepoItem( + item, + showOwner: item['owner']['login'] != widget.login, + ); + }, + ); } Widget _buildEmail(payload) { diff --git a/lib/widgets/list_group.dart b/lib/widgets/list_group.dart index 2f63cbb..4c3d439 100644 --- a/lib/widgets/list_group.dart +++ b/lib/widgets/list_group.dart @@ -1,17 +1,25 @@ import 'package:flutter/material.dart'; import '../widgets/empty.dart'; +var borderColor = Color.fromRGBO(27, 31, 35, .15); + class ListGroup extends StatelessWidget { final Widget title; final List items; final Widget Function(T item, int index) itemBuilder; + final EdgeInsetsGeometry padding; - ListGroup({this.title, this.items, this.itemBuilder}); + ListGroup({ + @required this.title, + @required this.items, + @required this.itemBuilder, + this.padding = const EdgeInsets.only(left: 10, right: 10, bottom: 10), + }); Widget _buildItem(MapEntry entry) { return Container( decoration: BoxDecoration( - border: Border(bottom: BorderSide(color: Colors.black12)), + border: Border(top: BorderSide(color: borderColor)), ), child: itemBuilder(entry.value, entry.key), ); @@ -19,16 +27,19 @@ class ListGroup extends StatelessWidget { @override Widget build(BuildContext context) { - return Padding( - padding: EdgeInsets.all(10), + return Container( + padding: padding, child: Container( - decoration: BoxDecoration(border: Border.all(color: Colors.black12)), + decoration: BoxDecoration( + border: Border.all(color: borderColor), + borderRadius: BorderRadius.all(Radius.circular(3)), + ), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Container( + color: Color(0xfff6f8fa), padding: EdgeInsets.all(8), - color: Color(0x10000000), child: title, ), items.isEmpty