From c02a3979ef4a59a0b241c0668dd868f826857674 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 2 Nov 2020 15:29:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90application=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=9E=B6=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/provider/app_provider.dart | 10 ++- .../home/application/applications_page.dart | 80 ++++++++++++++++--- lib/ui/home/home_page.dart | 5 +- 3 files changed, 81 insertions(+), 14 deletions(-) diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index 7c36ee2..5617444 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -7,8 +7,14 @@ class AppProvider extends ChangeNotifier { ///添加最近使用的应用 addRecentApp(AppApplication app) { - if (-recentUsedApp.length >= 4) _recentUsedApp.removeLast(); - _recentUsedApp.insert(0, app); + if (_recentUsedApp.indexWhere((element) => element.name == app.name) == + -1) { + if (_recentUsedApp.length >= 4) _recentUsedApp.removeLast(); + _recentUsedApp.insert(0, app); + } else { + _recentUsedApp.removeWhere((element) => element.name == app.name); + _recentUsedApp.insert(0, app); + } notifyListeners(); } diff --git a/lib/ui/home/application/applications_page.dart b/lib/ui/home/application/applications_page.dart index 5955f7e..f7af5bf 100644 --- a/lib/ui/home/application/applications_page.dart +++ b/lib/ui/home/application/applications_page.dart @@ -1,17 +1,24 @@ +import 'package:aku_ui/common_widgets/aku_material_button.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + import 'package:aku_community_manager/const/resource.dart'; import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; +import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_back_button.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; -import 'package:aku_ui/common_widgets/aku_material_button.dart'; -import 'package:flutter/material.dart'; -import 'package:aku_community_manager/tools/screen_tool.dart'; -import 'package:provider/provider.dart'; class AppApplication { String name; String assetPath; + Widget page; + AppApplication( + this.name, + this.assetPath, + this.page, + ); } class ApplicationPage extends StatefulWidget { @@ -27,8 +34,20 @@ class _ApplicationPageState extends State int _nowSelectedIndex = 0; + List _recommandApplications = [ + AppApplication('活动管理', '', Scaffold()), + AppApplication('访客管理', '', Scaffold()), + AppApplication('便民电话', '', Scaffold()), + AppApplication('借还管理', '', Scaffold()), + AppApplication('工单管理', '', Scaffold()), + AppApplication('语音管家', '', Scaffold()), + AppApplication('一键报警', '', Scaffold()), + AppApplication('问卷调查', '', Scaffold()), + ]; + @override Widget build(BuildContext context) { + final appProvider = Provider.of(context); return AkuScaffold( appBar: AppBar( brightness: Brightness.light, @@ -70,6 +89,7 @@ class _ApplicationPageState extends State children: [ AkuBox.h(16), _buildRecentUsed(), + appProvider.recentUsedApp.isEmpty ? SizedBox() : AkuBox.h(16), _buildBottomApps(), ], ), @@ -88,10 +108,7 @@ class _ApplicationPageState extends State children: [ Row( children: [ - AkuMaterialButton( - onPressed: () { - appProvider.clearRecentApp(); - }, + Padding( child: Text( '最近使用', style: TextStyle( @@ -107,7 +124,9 @@ class _ApplicationPageState extends State ), Spacer(), AkuMaterialButton( - onPressed: () {}, + onPressed: () { + appProvider.clearRecentApp(); + }, child: Text( '清除', style: TextStyle( @@ -123,6 +142,16 @@ class _ApplicationPageState extends State ), ], ), + GridView( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, + ), + children: appProvider.recentUsedApp + .map((e) => _buildBottomAppCard(e)) + .toList(), + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + ), ], ), ); @@ -155,7 +184,17 @@ class _ApplicationPageState extends State }); }, children: [ - Text('12'), + GridView.builder( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 3, + ), + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + final application = _recommandApplications[index]; + return _buildBottomAppCard(application); + }, + itemCount: _recommandApplications.length, + ), Text('23'), ], ), @@ -193,4 +232,25 @@ class _ApplicationPageState extends State ), ); } + + Widget _buildBottomAppCard(AppApplication application) { + final appProvider = Provider.of(context); + return AkuMaterialButton( + onPressed: () { + appProvider.addRecentApp(application); + }, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + height: 75.w, + width: 75.w, + child: Placeholder(), + ), + AkuBox.h(8), + Text(application.name), + ], + ), + ); + } } diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 2d53f2f..46294d6 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -1,4 +1,3 @@ - import 'package:aku_community_manager/const/resource.dart'; import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; @@ -227,7 +226,9 @@ class _HomePageState extends State { minWidth: 78.w, //消息按钮 height: double.infinity, - onPressed: () {}, + onPressed: () { + Get.to(Message()); + }, child: Column(children: [ Image.asset( R.ASSETS_HOME_IC_NEWS_PNG,