refactor all application page and just RTFSC.

hmxc
小赖 4 years ago
parent 6a6cecac38
commit dcfa4e7b8f

@ -5,6 +5,7 @@ import 'package:akuCommunity/pages/goods_deto_page/goods_deto_page.dart';
import 'package:akuCommunity/pages/goods_manage_page/goods_manage_page.dart';
import 'package:akuCommunity/pages/industry_committee/industry_committee_page.dart';
import 'package:akuCommunity/pages/life_pay/life_pay_page.dart';
import 'package:akuCommunity/pages/one_alarm/widget/alarm_page.dart';
import 'package:akuCommunity/pages/open_door_page/open_door_page.dart';
import 'package:akuCommunity/pages/opening_code_page/opening_code_page.dart';
import 'package:akuCommunity/pages/questionnaire_page/questionnaire_details_page/questionnaire_details_page.dart';
@ -40,13 +41,13 @@ class AO {
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is AO && runtimeType == other.runtimeType && title == other.title;
@override
int get hashCode => title.hashCode;
}
///
List<AO> appObjects = [
AO('一键开门', R.ASSETS_APPLICATIONS_OEPN_DOOR_PNG, OpenDoorPage()),
AO('开门码', R.ASSETS_APPLICATIONS_DOOR_CODE_PNG, OpeningCodePage()),
@ -64,6 +65,43 @@ List<AO> appObjects = [
AO('问卷调查', R.ASSETS_APPLICATIONS_QUESTION_PNG, QuestionnaireDetailsPage()),
AO('装修管理', R.ASSETS_APPLICATIONS_DECORATION_PNG, FitupManagePage()),
AO('借还管理', R.ASSETS_APPLICATIONS_BORROW_PNG, GoodsManagePage()),
AO('一键报警', R.ASSETS_APPLICATIONS_POLICE_PNG, AlarmPage()),
];
///
AO allApp = AO('全部应用', R.ASSETS_APPLICATIONS_ALL_APP_PNG, AllApplicationPage());
/// original value
List<String> _recommendApp = [
'一键开门',
'访客邀请',
'报事报修',
'建议咨询',
'一键报警',
];
///
List<AO> get recommendApp => _recommendApp.map((e) => AO.fromRaw(e)).toList();
/// original value
List<String> _smartManagerApp = [
'一键开门',
'开门码',
'访客邀请',
'报事报修',
'生活缴费',
'业委会',
'建议咨询',
'便民电话',
'活动投票',
'物品出门',
'投诉表扬',
'问卷调查',
'装修管理',
'借还管理',
'一键报警',
];
///
List<AO> get smartManagerApp =>
_smartManagerApp.map((e) => AO.fromRaw(e)).toList();

@ -1,4 +1,5 @@
import 'package:akuCommunity/constants/application_objects.dart';
import 'package:akuCommunity/utils/hive_store.dart';
import 'package:flutter/material.dart';
class AppProvider extends ChangeNotifier {
@ -28,10 +29,24 @@ class AppProvider extends ChangeNotifier {
return _myApplications;
}
///
initApplications() {
if (HiveStore.appBox.containsKey('app'))
_myApplications = (HiveStore.appBox.get('app') as List<String>)
.map((e) => AO.fromRaw(e))
.toList();
notifyListeners();
}
///
insertApplication(AO app) {
if (!_myApplications.contains(app) && _myApplications.length < 7)
_myApplications.insert(0, app);
if (!_myApplications.contains(app) && _myApplications.length >= 7) {
_myApplications.insert(0, app);
_myApplications.removeLast();
}
HiveStore.appBox.put('app', _myApplications.map((e) => e.title).toList());
notifyListeners();
}

@ -1,7 +1,12 @@
import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/constants/application_objects.dart';
import 'package:akuCommunity/provider/app_provider.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:akuCommunity/widget/bee_back_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
class AllApplicationPage extends StatefulWidget {
@ -12,6 +17,203 @@ class AllApplicationPage extends StatefulWidget {
}
class _AllApplicationPageState extends State<AllApplicationPage> {
bool _editMode = false;
int _index = 0;
PageController _pageController = PageController();
_buildTile(AO object, {bool editMode = false}) {
return MaterialButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.w)),
padding: EdgeInsets.zero,
onPressed: editMode ? null : () => Get.to(object.page),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
object.path,
height: 75.w,
width: 75.w,
),
8.hb,
object.title.text.size(24.sp).make(),
],
),
);
}
_buildEditTile() {
return Row(
children: [
74.hb,
'我的应用'.text.make(),
Spacer(),
MaterialButton(
padding: EdgeInsets.zero,
elevation: 0,
height: 52.w,
minWidth: 90.w,
onPressed: () {
_editMode = !_editMode;
setState(() {});
},
color: kPrimaryColor,
child: (_editMode ? '完成' : '编辑').text.bold.size(28.sp).make(),
),
],
).pSymmetric(h: 32.w).material(color: Colors.white);
}
_buildMyApp() {
final appProvider = Provider.of<AppProvider>(context);
return GridView.builder(
padding: EdgeInsets.symmetric(horizontal: 32.w),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
itemBuilder: (context, index) {
return Stack(
children: [
_buildTile(
appProvider.myApplications[index],
editMode: _editMode,
),
Positioned(
right: 0,
top: 0,
child: AnimatedOpacity(
duration: Duration(milliseconds: 300),
curve: Curves.easeInOutCubic,
opacity: _editMode ? 1 : 0,
child: CupertinoButton(
minSize: 60.w,
padding: EdgeInsets.zero,
onPressed: _editMode
? () {
appProvider.removeApplication(
appProvider.myApplications[index],
);
}
: null,
child: Image.asset(
R.ASSETS_ICONS_APP_REDUCE_PNG,
height: 24.w,
width: 24.w,
),
),
),
),
],
);
},
itemCount: appProvider.myApplications.length,
).material(color: Colors.white);
}
_buildListTile(String title, int index) {
bool sameIndex = _index == index;
return Stack(
fit: StackFit.passthrough,
children: [
MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero,
color: sameIndex ? Colors.white : Color(0xFFEFEFEF),
elevation: 0,
height: 88.w,
onPressed: () {
setState(() {
_index = index;
});
_pageController.animateToPage(
index,
duration: Duration(milliseconds: 300),
curve: Curves.easeInOutCubic,
);
},
child: title.text.size(28.sp).make(),
),
Positioned(
left: 0,
top: 24.w,
bottom: 24.w,
child: AnimatedContainer(
duration: Duration(milliseconds: 300),
curve: Curves.easeInOutCubic,
width: sameIndex ? 3.w : 10.w,
color: sameIndex ? kPrimaryColor : kPrimaryColor.withOpacity(0),
),
),
],
);
}
Widget _buildView(List<AO> objects) {
final appProvider = Provider.of<AppProvider>(context);
return GridView.builder(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (context, index) {
return Stack(
children: [
_buildTile(objects[index], editMode: _editMode),
Positioned(
right: 0,
top: 0,
child: AnimatedOpacity(
duration: Duration(milliseconds: 300),
curve: Curves.easeInOutCubic,
opacity: _editMode ? 1 : 0,
child: CupertinoButton(
minSize: 60.w,
padding: EdgeInsets.zero,
onPressed: _editMode
? () => appProvider.insertApplication(objects[index])
: null,
child: Image.asset(
R.ASSETS_ICONS_APP_ADD_PNG,
height: 24.w,
width: 24.w,
),
),
),
),
],
);
},
itemCount: objects.length,
);
}
Widget _buildAppList() {
return Row(
children: [
SizedBox(
width: 172.w,
child: ListView(
padding: EdgeInsets.zero,
children: [
_buildListTile('为您推荐', 0),
_buildListTile('智慧管家', 1),
// _buildListTile('商城购物', 2),
],
),
).material(color: Color(0xFFEFEFEF)),
PageView(
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
controller: _pageController,
children: [
_buildView(recommendApp),
_buildView(smartManagerApp),
],
).expand(),
],
).material(color: Colors.white);
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -46,7 +248,19 @@ class _AllApplicationPageState extends State<AllApplicationPage> {
),
),
),
// body: ,
body: Column(
children: [
_buildEditTile(),
Divider(
indent: 32.w,
endIndent: 32.w,
height: 1.w,
).material(color: Colors.white),
_buildMyApp(),
32.hb,
_buildAppList().expand(),
],
),
);
}
}

Loading…
Cancel
Save