import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_svg/svg.dart'; import 'package:get/get.dart'; import 'package:sk_base_mobile/app_theme.dart'; import 'package:sk_base_mobile/models/sale_quotation_template.model.dart'; import 'package:sk_base_mobile/router/router.util.dart'; import 'package:sk_base_mobile/screens/sale_quotation/sale_quotation.controller.dart'; import 'package:sk_base_mobile/util/modal.util.dart'; import 'package:sk_base_mobile/util/screen_adaper_util.dart'; import 'package:sk_base_mobile/util/snack_bar.util.dart'; import 'package:sk_base_mobile/widgets/core/sk_flat_button.dart'; import 'package:sk_base_mobile/widgets/core/sk_ink.dart'; import 'package:sk_base_mobile/widgets/empty.dart'; import 'package:sk_base_mobile/widgets/form_item/sk_text_input.dart'; import 'package:sk_base_mobile/widgets/core/sk_appbar.dart'; class SaleQuotationEndDrawer extends StatelessWidget { final controller = Get.find(); SaleQuotationEndDrawer({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: const SkAppbar(title: '', hideLeading: true), body: buildBody() // Only render the body if '_isRendered' is true ); } Widget buildBody() { return Column( children: [ buildToolbar(), Expanded( child: buildTemplatePicker(), ), buildAction() ], ); } Widget buildAction() { return Row( children: [ Expanded( child: SkFlatButton( color: Colors.green, onPressed: () async { // ModalUtil.alert( // title: '请注意', // content: Text( // '之前的模板保存了吗?不保存会丢失。', // style: TextStyle(fontSize: ScreenAdaper.height(30)), // ), // onConfirm: () async { controller.clearWorkbench(); RouterUtil.back(); // }); }, icon: Icon( Icons.add, color: AppTheme.nearlyWhite, size: ScreenAdaper.height(35), ), buttonText: '新建模板', )), Expanded( child: SkFlatButton( color: AppTheme.nearlyWhite, textColor: AppTheme.nearlyBlack, onPressed: () async { controller.openTemplateNameEditPopup( title: '', onConfirm: (name) async { controller.templateName.value = name; await controller.saveToLocal(); await controller.saveToDatabase(isSaveAs: true); await controller.getTemplates(); }); }, icon: Icon( Icons.save_as, color: AppTheme.nearlyBlack, size: ScreenAdaper.height(35), ), buttonText: '另存为', )), Expanded( child: SkFlatButton( onPressed: () async { if (!controller.checkIsValid()) { return; } if (controller.templateName.value != '默认') { final isSuccessed = await controller.saveToDatabase(); if (isSuccessed) await RouterUtil.back(); } else { controller.openTemplateNameEditPopup(onConfirm: (name) async { controller.templateName.value = name; await controller.saveToLocal(); await controller.saveToDatabase(); await controller.getTemplates(); }); } }, icon: Icon( Icons.save, color: AppTheme.nearlyWhite, size: ScreenAdaper.height(35), ), buttonText: '保存模板', )), ], ); } Widget buildToolbar() { return Container( decoration: BoxDecoration( color: AppTheme.nearlyWhite, borderRadius: BorderRadius.circular(ScreenAdaper.sp(20))), margin: EdgeInsets.symmetric( horizontal: ScreenAdaper.height(20), vertical: ScreenAdaper.height(20)), child: Column( children: [ buildGroupHeader('工具栏'), Row( children: controller.menus .mapIndexed( (index, item) => Expanded(child: buildItem(index))) .toList()) ], ), ); } Widget buildGroupHeader(String text) { return Container( padding: EdgeInsets.only( right: ScreenAdaper.width(20), left: ScreenAdaper.width(20), top: ScreenAdaper.height(20)), alignment: Alignment.centerLeft, child: Text( text, style: TextStyle( fontSize: ScreenAdaper.height(25), color: Colors.grey[600]), ), ); } Widget buildItem(int index) { return SkInk( onTap: controller.menus[index].onTap ?? () {}, child: Container( alignment: Alignment.center, padding: EdgeInsets.only( top: ScreenAdaper.height(20), bottom: ScreenAdaper.height(20)), child: Column( children: [ SvgPicture.asset( 'assets/icons/${controller.menus[index].icon}', width: ScreenAdaper.width(75), height: ScreenAdaper.width(75), ), SizedBox( height: ScreenAdaper.height(10), ), Text( controller.menus[index].title, style: TextStyle( fontSize: ScreenAdaper.height(22), ), ) ], ), ), ); } Widget buildTemplatePicker() { return Obx(() => Container( decoration: BoxDecoration( color: AppTheme.nearlyWhite, borderRadius: BorderRadius.circular(ScreenAdaper.sp(20))), margin: EdgeInsets.only( left: ScreenAdaper.height(20), right: ScreenAdaper.height(20), bottom: ScreenAdaper.height(20)), child: Column( children: [ buildGroupHeader('请选择模板'), SizedBox( height: ScreenAdaper.height(10), ), Expanded( child: controller.templates.isEmpty ? Empty( onTap: () { Get.back(); controller.addGroup(); }, text: '暂无模板,点我开始创建') : ListView( padding: EdgeInsets.symmetric( horizontal: ScreenAdaper.height(20)), children: controller.templates .mapIndexed((int index, element) => buildTemplateItem(element, index)) .toList(), )) ], ), )); } Widget buildTemplateItem(SaleQuotationTemplateModel element, int index) { return Obx(() => SkInk( color: controller.templateId.value == element.id ? AppTheme.primaryColorLight : Colors.transparent, onTap: () async { controller.changeTemplate(element); await RouterUtil.back(); }, margin: EdgeInsets.symmetric( horizontal: ScreenAdaper.width(10), vertical: ScreenAdaper.height(10)), border: Border.all(color: AppTheme.dividerColor), borderRadius: BorderRadius.circular(ScreenAdaper.sp(15)), child: Container( padding: EdgeInsets.symmetric( vertical: ScreenAdaper.height(20), horizontal: ScreenAdaper.width(20)), child: Row(children: [ Expanded( child: Text( '${element.name}', style: TextStyle(fontSize: ScreenAdaper.height(25)), )), SkInk( onTap: () { controller.openTemplateNameEditPopup( title: element.name, onConfirm: (name) async { controller.templateName.value = name; await controller.saveToLocal(); await controller.saveToDatabase(); await controller.getTemplates(); }); }, child: Icon( Icons.edit, color: Colors.grey[600], size: ScreenAdaper.height(40), ), ), SizedBox( width: ScreenAdaper.width(10), ), SkInk( color: Colors.transparent, onTap: () { ModalUtil.alert( title: '删除模板', content: Text( '确定删除模板${element.name}吗?', style: TextStyle(fontSize: ScreenAdaper.height(30)), ), onConfirm: () async { await controller.deleteTemplate(element.id!); controller.templates.removeAt(index); }); }, child: Icon( Icons.delete, color: Colors.grey[600], size: ScreenAdaper.height(40), ), ), ]), ), )); } } // class SaleQuotationDrawerController extends GetxController{ // }