From 2d69a45bbf0f8a7c7e9241a873e4418cd0073dfe Mon Sep 17 00:00:00 2001 From: Sun Date: Wed, 2 Jun 2021 22:53:05 +0800 Subject: [PATCH] add some back UI --- lib/apps/chat/add.dart | 200 ++++++++++++++---------------- lib/apps/chat/list.dart | 14 +-- lib/apps/file/list.dart | 14 +-- lib/apps/group_chat/add.dart | 35 +++--- lib/apps/group_chat/list.dart | 14 +-- lib/apps/group_chat/provider.dart | 4 + lib/apps/service/list.dart | 32 +++-- lib/pages/home.dart | 14 +-- src/apps/group_chat/layer.rs | 4 +- 9 files changed, 158 insertions(+), 173 deletions(-) diff --git a/lib/apps/chat/add.dart b/lib/apps/chat/add.dart index e84fcde..2a131d1 100644 --- a/lib/apps/chat/add.dart +++ b/lib/apps/chat/add.dart @@ -17,6 +17,7 @@ import 'package:esse/global.dart'; import 'package:esse/provider.dart'; import 'package:esse/apps/chat/models.dart'; +import 'package:esse/apps/chat/list.dart'; import 'package:esse/apps/chat/provider.dart'; class ChatAddPage extends StatefulWidget { @@ -31,7 +32,6 @@ class ChatAddPage extends StatefulWidget { } class _ChatAddPageState extends State { - final _formKey = GlobalKey(); TextEditingController userIdEditingController = TextEditingController(); TextEditingController addrEditingController = TextEditingController(); TextEditingController remarkEditingController = TextEditingController(); @@ -115,113 +115,101 @@ class _ChatAddPageState extends State { final requestKeys = requests.keys.toList().reversed.toList(); // it had sorted. return Scaffold( - body: SafeArea( - child: Padding( - padding: const EdgeInsets.all(10.0), - child: Column(children: [ - Row( - children: [ - if (!isDesktop) - GestureDetector( - onTap: () { - context.read().requestClear(); - Navigator.pop(context); - }, - child: Container( - width: 20.0, - child: Icon(Icons.arrow_back, color: color.primary)), - ), - SizedBox(width: 15.0), - Expanded( - child: Text(lang.addFriend, - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0)), - ), - TextButton( - onPressed: () => showShadowDialog( - context, - Icons.info, - lang.info, - UserInfo(app: 'add-friend', - id: account.id, name: account.name, addr: Global.addr) - ), - child: Text(lang.myQrcode, style: TextStyle(fontSize: 16.0)), - ), - ], - ), - isDesktop ? SizedBox(height: 20.0) : SizedBox(height: 50.0), - Expanded( - child: SingleChildScrollView( - child: Container( - constraints: BoxConstraints(minWidth: 200, maxWidth: 600), - padding: const EdgeInsets.all(20), - child: Form( - key: _formKey, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - ShadowButton( - icon: Icons.camera_alt, - color: color, - text: lang.scanQr, - action: () => Navigator.push( - context, - MaterialPageRoute(builder: (context) => QRScan(callback: scanCallback)) - )), - if (MediaQuery.of(context).size.width < 400) Spacer(), - ShadowButton( - icon: Icons.image, - color: color, - text: lang.scanImage, - action: chooseImage), - ], - ), - ), - const SizedBox(height: 40.0), - InputText( - icon: Icons.person, - text: lang.id, - controller: userIdEditingController, - focus: userIdFocus), - const SizedBox(height: 20.0), - InputText( - icon: Icons.location_on, - text: lang.address, - controller: addrEditingController, - focus: addrFocus), - const SizedBox(height: 20.0), - InputText( - icon: Icons.turned_in, - text: lang.remark, - controller: remarkEditingController, - focus: remarkFocus), - const SizedBox(height: 20.0), - ButtonText(action: send, text: lang.send, width: 600.0), - const SizedBox(height: 20.0), - const Divider(height: 1.0, color: Color(0x40ADB0BB)), - const SizedBox(height: 10.0), - if (requests.isNotEmpty) - ListView.builder( - itemCount: requestKeys.length, - shrinkWrap: true, - physics: ClampingScrollPhysics(), - scrollDirection: Axis.vertical, - itemBuilder: (BuildContext context, int index) => - _RequestItem(request: requests[requestKeys[index]]), - ), - ], - ), - ), + appBar: AppBar( + title: Text(lang.addFriend), + bottom: PreferredSize( + child: Container(color: const Color(0x40ADB0BB), height: 1.0), + preferredSize: Size.fromHeight(1.0) + ), + leading: isDesktop + ? IconButton( + onPressed: () { + context.read().requestClear(); + context.read().updateActivedWidget(ChatList()); + }, + icon: Icon(Icons.arrow_back, color: color.primary), + ) : null, + actions: [ + TextButton( + onPressed: () => showShadowDialog( + context, + Icons.info, + lang.info, + UserInfo(app: 'add-friend', + id: account.id, name: account.name, addr: Global.addr) + ), + child: Text(lang.myQrcode, style: TextStyle(fontSize: 16.0)), + ), + ] + ), + body: Container( + padding: const EdgeInsets.all(10.0), + alignment: Alignment.topCenter, + child: SingleChildScrollView( + child: Container( + width: 600, + padding: const EdgeInsets.all(20), + child: Column( + children: [ + Container( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + ShadowButton( + icon: Icons.camera_alt, + color: color, + text: lang.scanQr, + action: () => Navigator.push( + context, + MaterialPageRoute(builder: (context) => QRScan(callback: scanCallback)) + )), + if (MediaQuery.of(context).size.width < 400) Spacer(), + ShadowButton( + icon: Icons.image, + color: color, + text: lang.scanImage, + action: chooseImage), + ], ), ), - ), - ] - ) - ) - )); + const SizedBox(height: 40.0), + InputText( + icon: Icons.person, + text: lang.id, + controller: userIdEditingController, + focus: userIdFocus), + const SizedBox(height: 20.0), + InputText( + icon: Icons.location_on, + text: lang.address, + controller: addrEditingController, + focus: addrFocus), + const SizedBox(height: 20.0), + InputText( + icon: Icons.turned_in, + text: lang.remark, + controller: remarkEditingController, + focus: remarkFocus), + const SizedBox(height: 20.0), + ButtonText(action: send, text: lang.send, width: 600.0), + const SizedBox(height: 20.0), + const Divider(height: 1.0, color: Color(0x40ADB0BB)), + const SizedBox(height: 10.0), + if (requests.isNotEmpty) + ListView.builder( + itemCount: requestKeys.length, + shrinkWrap: true, + physics: ClampingScrollPhysics(), + scrollDirection: Axis.vertical, + itemBuilder: (BuildContext context, int index) => + _RequestItem(request: requests[requestKeys[index]]), + ), + ], + ), + ), + ), + ), + ); } } diff --git a/lib/apps/chat/list.dart b/lib/apps/chat/list.dart index 35d68d7..aa42c13 100644 --- a/lib/apps/chat/list.dart +++ b/lib/apps/chat/list.dart @@ -36,14 +36,12 @@ class _ChatListState extends State { preferredSize: Size.fromHeight(1.0) ), ), - body: SafeArea( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), - child: ListView.builder( - itemCount: chatKeys.length, - itemBuilder: (BuildContext ctx, int index) => ListChat(friend: friends[chatKeys[index]]), - ) - ), + body: Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: ListView.builder( + itemCount: chatKeys.length, + itemBuilder: (BuildContext ctx, int index) => ListChat(friend: friends[chatKeys[index]]), + ) ), floatingActionButton: FloatingActionButton( onPressed: () { diff --git a/lib/apps/file/list.dart b/lib/apps/file/list.dart index c63c2f0..0ce8a67 100644 --- a/lib/apps/file/list.dart +++ b/lib/apps/file/list.dart @@ -83,14 +83,12 @@ class _FilesListState extends State { preferredSize: Size.fromHeight(1.0) ), ), - body: SafeArea( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), - child: ListView.builder( - itemCount: FILE_DIRECTORY.length, - itemBuilder: (BuildContext ctx, int index) => item(index, color, isDesktop), - ) - ), + body: Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: ListView.builder( + itemCount: FILE_DIRECTORY.length, + itemBuilder: (BuildContext ctx, int index) => item(index, color, isDesktop), + ) ), ); } diff --git a/lib/apps/group_chat/add.dart b/lib/apps/group_chat/add.dart index d0486c5..143ce89 100644 --- a/lib/apps/group_chat/add.dart +++ b/lib/apps/group_chat/add.dart @@ -18,6 +18,7 @@ import 'package:esse/rpc.dart'; import 'package:esse/provider.dart'; import 'package:esse/apps/group_chat/models.dart'; +import 'package:esse/apps/group_chat/list.dart'; import 'package:esse/apps/group_chat/provider.dart'; class GroupAddPage extends StatefulWidget { @@ -220,26 +221,28 @@ class _GroupAddPageState extends State { final requests = provider.requests; final requestKeys = requests.keys.toList().reversed.toList(); - return SafeArea( - child: DefaultTabController( + return DefaultTabController( initialIndex: 0, length: 2, child: Scaffold( appBar: AppBar( - title: Row( - children: [ - Expanded( - child: Text(lang.groupChatAdd, - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0)), - ), - TextButton( - onPressed: () => Navigator.push(context, - MaterialPageRoute(builder: (context) => QRScan(callback: _scanCallback)) - ), - child: Text(lang.scanQr, style: TextStyle(fontSize: 16.0)), + title: Text(lang.addFriend), + leading: isDesktop + ? IconButton( + onPressed: () { + context.read().requestClear(); + context.read().updateActivedWidget(GroupChatList()); + }, + icon: Icon(Icons.arrow_back, color: color.primary), + ) : null, + actions: [ + TextButton( + onPressed: () => Navigator.push(context, + MaterialPageRoute(builder: (context) => QRScan(callback: _scanCallback)) ), - ], - ), + child: Text(lang.scanQr, style: TextStyle(fontSize: 16.0)), + ), + ], bottom: TabBar( tabs: [ Tab( @@ -531,7 +534,7 @@ class _GroupAddPageState extends State { ), ), ], - ))) + )) ); } } diff --git a/lib/apps/group_chat/list.dart b/lib/apps/group_chat/list.dart index 2546bc2..75ffb3b 100644 --- a/lib/apps/group_chat/list.dart +++ b/lib/apps/group_chat/list.dart @@ -35,14 +35,12 @@ class _GroupChatListState extends State { preferredSize: Size.fromHeight(1.0) ), ), - body: SafeArea( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), - child: ListView.builder( - itemCount: orderKeys.length, - itemBuilder: (BuildContext ctx, int index) => ListChat(group: groups[orderKeys[index]]), - ) - ), + body: Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: ListView.builder( + itemCount: orderKeys.length, + itemBuilder: (BuildContext ctx, int index) => ListChat(group: groups[orderKeys[index]]), + ) ), floatingActionButton: FloatingActionButton( onPressed: () { diff --git a/lib/apps/group_chat/provider.dart b/lib/apps/group_chat/provider.dart index 1b783fd..e7bcc46 100644 --- a/lib/apps/group_chat/provider.dart +++ b/lib/apps/group_chat/provider.dart @@ -118,6 +118,10 @@ class GroupChatProvider extends ChangeNotifier { this.activedMembers.clear(); } + requestClear() { + this.requests.clear(); + } + join(GroupType gtype, String gid, String gaddr, String name, String remark, [String proof = '', String key = '']) { rpc.send('group-chat-join', [gtype.toInt(), gid, gaddr, name, remark, proof, key]); } diff --git a/lib/apps/service/list.dart b/lib/apps/service/list.dart index 1a973a4..11fd7d3 100644 --- a/lib/apps/service/list.dart +++ b/lib/apps/service/list.dart @@ -35,23 +35,21 @@ class _ServiceListState extends State { preferredSize: Size.fromHeight(1.0) ), ), - body: SafeArea( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), - child: ListView.builder( - itemCount: INNER_SERVICES.length, - itemBuilder: (BuildContext ctx, int index) { - final params = INNER_SERVICES[index].params(lang); - return ListInnerService( - name: params[0], - bio: params[1], - logo: params[2], - callback: () => INNER_SERVICES[index].callback(), - isDesktop: isDesktop, - ); - } - ) - ), + body: Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: ListView.builder( + itemCount: INNER_SERVICES.length, + itemBuilder: (BuildContext ctx, int index) { + final params = INNER_SERVICES[index].params(lang); + return ListInnerService( + name: params[0], + bio: params[1], + logo: params[2], + callback: () => INNER_SERVICES[index].callback(), + isDesktop: isDesktop, + ); + } + ) ), floatingActionButton: FloatingActionButton( onPressed: () { diff --git a/lib/pages/home.dart b/lib/pages/home.dart index d95cd4c..227953f 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -212,14 +212,12 @@ class _HomeListState extends State { ) ] ), - body: SafeArea( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0), - child: ListView.builder( - itemCount: allKeys.length, - itemBuilder: (BuildContext ctx, int index) => _SessionWidget( - session: sessions[allKeys[index]] - ), + body: Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: ListView.builder( + itemCount: allKeys.length, + itemBuilder: (BuildContext ctx, int index) => _SessionWidget( + session: sessions[allKeys[index]] ), ), ), diff --git a/src/apps/group_chat/layer.rs b/src/apps/group_chat/layer.rs index edf1258..70730b0 100644 --- a/src/apps/group_chat/layer.rs +++ b/src/apps/group_chat/layer.rs @@ -213,7 +213,7 @@ async fn handle_event( results.rpcs.push(rpc::member_offline(mgid, gid, mid)); } LayerEvent::Sync(gcd, height, event) => { - let (sid, gid) = layer.read().await.get_running_remote_id(&mgid, &gcd)?; + let (_sid, gid) = layer.read().await.get_running_remote_id(&mgid, &gcd)?; println!("Sync: height: {}", height); let base = layer.read().await.base().clone(); @@ -312,7 +312,7 @@ async fn handle_event( let (_sid, _gid) = layer.read().await.get_running_remote_id(&mgid, &gcd)?; let db = group_chat_db(layer.read().await.base(), &mgid)?; let id = Request::over_rid(&db, &gcd, &rid, ok)?; - results.rpcs.push(rpc::request_handle(mgid, id, ok)); + results.rpcs.push(rpc::request_handle(mgid, id, ok, false)); } LayerEvent::Request(..) => {} // nerver here. LayerEvent::Check => {} // nerver here.