You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/widget/views/application_view.dart

85 lines
2.4 KiB

3 years ago
import 'package:aku_new_community/constants/application_objects.dart';
import 'package:aku_new_community/provider/app_provider.dart';
import 'package:aku_new_community/utils/headers.dart';
import 'package:aku_new_community/utils/login_util.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
3 years ago
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
class ApplicationView extends StatefulWidget {
4 years ago
final List<AO>? items;
final bool needAllApp;
final bool unComplete;
3 years ago
ApplicationView({Key? key, this.needAllApp = true, this.unComplete = false})
: items = null,
super(key: key);
ApplicationView.custom(
{Key? key,
required List<AO> this.items,
this.needAllApp = true,
this.unComplete = false})
: super(key: key);
@override
_ApplicationViewState createState() => _ApplicationViewState();
}
class _ApplicationViewState extends State<ApplicationView> {
_buildTile(AO object) {
return MaterialButton(
shape: StadiumBorder(),
padding: EdgeInsets.zero,
onPressed: () {
if (LoginUtil.isNotLogin) return;
if (!LoginUtil.haveRoom(object.title)) return;
if (widget.unComplete) {
BotToast.showText(text: '该功能正在准备上线中,敬请期待', align: Alignment(0, 0.5));
} else {
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(),
],
),
);
}
bool get _isCustom => widget.items != null;
3 years ago
4 years ago
List<AO>? get _items {
final appProvider = Provider.of<AppProvider>(context);
return _isCustom ? widget.items : appProvider.myApplications;
}
@override
Widget build(BuildContext context) {
return GridView.builder(
padding: EdgeInsets.zero,
physics: NeverScrollableScrollPhysics(),
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
itemBuilder: (context, index) {
4 years ago
if (index == _items!.length && widget.needAllApp)
return _buildTile(allApp);
4 years ago
return _buildTile(_items![index]);
},
4 years ago
itemCount: widget.needAllApp ? _items!.length + 1 : _items!.length,
shrinkWrap: true,
);
}
}