TF-235 Add presentation for rename a mailbox
This commit is contained in:
@@ -42,12 +42,14 @@ export 'presentation/views/context_menu/simple_context_menu_action_builder.dart'
|
||||
export 'presentation/views/dialog/loading_dialog_builder.dart';
|
||||
export 'presentation/views/dialog/downloading_file_dialog_builder.dart';
|
||||
export 'presentation/views/dialog/confirmation_dialog_builder.dart';
|
||||
export 'presentation/views/dialog/edit_text_dialog_builder.dart';
|
||||
export 'presentation/views/background/background_widget_builder.dart';
|
||||
export 'presentation/views/html_viewer/html_content_viewer_widget.dart';
|
||||
export 'presentation/views/floating_button/scrolling_floating_button_animated.dart';
|
||||
export 'presentation/views/bottom_popup/cupertino_action_sheet_action_builder.dart';
|
||||
export 'presentation/views/bottom_popup/cupertino_action_sheet_builder.dart';
|
||||
export 'presentation/views/bottom_popup/confirmation_dialog_action_sheet_builder.dart';
|
||||
export 'presentation/views/modal_sheets/edit_text_modal_sheet_builder.dart';
|
||||
|
||||
// Resources
|
||||
export 'presentation/resources/assets_paths.dart';
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
typedef OnConfirmButtonEditDialogAction = void Function(String);
|
||||
typedef SetErrorStringEditDialog = String? Function(String);
|
||||
|
||||
class EditTextDialogBuilder {
|
||||
late TextEditingController _textController;
|
||||
|
||||
Key? _key;
|
||||
String _title = '';
|
||||
String _hintText = '';
|
||||
String _confirmText = '';
|
||||
String _cancelText = '';
|
||||
|
||||
OnConfirmButtonEditDialogAction? _onConfirmButtonAction;
|
||||
|
||||
SetErrorStringEditDialog? _setErrorString;
|
||||
String? _error;
|
||||
Timer? _debounce;
|
||||
|
||||
EditTextDialogBuilder();
|
||||
|
||||
void key(Key key) {
|
||||
_key = key;
|
||||
}
|
||||
|
||||
void title(String title) {
|
||||
_title = title;
|
||||
}
|
||||
|
||||
void hintText(String hintText) {
|
||||
_hintText = hintText;
|
||||
}
|
||||
|
||||
void cancelText(String cancelText) {
|
||||
_cancelText = cancelText;
|
||||
}
|
||||
|
||||
void onConfirmButtonAction(String confirmText, OnConfirmButtonEditDialogAction? onConfirmButtonAction) {
|
||||
_confirmText = confirmText;
|
||||
_onConfirmButtonAction = onConfirmButtonAction;
|
||||
}
|
||||
|
||||
void setTextController(TextEditingController textEditingController) {
|
||||
_textController = textEditingController;
|
||||
}
|
||||
|
||||
void setTextSelection(TextSelection textSelection, {required String value}) {
|
||||
_textController = TextEditingController.fromValue(TextEditingValue(text: value, selection: textSelection));
|
||||
}
|
||||
|
||||
void setErrorString(SetErrorStringModelSheets setErrorString) {
|
||||
_setErrorString = setErrorString;
|
||||
}
|
||||
|
||||
void _onTextChanged(String name, StateSetter setState) {
|
||||
if (_debounce?.isActive ?? false) _debounce?.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
setState(() {
|
||||
_error = (_setErrorString != null) ? _setErrorString!(name) : '';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _onConfirmButtonPress(BuildContext context) {
|
||||
if (_error == null || (_error != null && _error!.isEmpty)) {
|
||||
Get.back();
|
||||
_onConfirmButtonAction?.call(_textController.text);
|
||||
}
|
||||
}
|
||||
|
||||
void _onCancelButtonPress(BuildContext context) {
|
||||
Get.back();
|
||||
_debounce?.cancel();
|
||||
}
|
||||
|
||||
Widget build() {
|
||||
return Dialog(
|
||||
key: _key,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
|
||||
insetPadding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
|
||||
child: Container(
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.zero,
|
||||
width: 400,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.all(Radius.circular(20))),
|
||||
child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 30, right: 30, top: 30, bottom: 24),
|
||||
child: Wrap(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
_title,
|
||||
style: TextStyle(fontSize: 20, color: AppColor.colorNameEmail, fontWeight: FontWeight.w700),
|
||||
textAlign: TextAlign.center),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: TextFormField(
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
onChanged: (value) => _onTextChanged(value, setState),
|
||||
autofocus: true,
|
||||
controller: _textController,
|
||||
decoration: InputDecoration(
|
||||
errorText: _error,
|
||||
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: AppColor.colorDividerMailbox)),
|
||||
hintText: _hintText),
|
||||
)
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 16, right: 16, top: 24),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildButton(
|
||||
name: _cancelText,
|
||||
bgColor: AppColor.colorContentEmail,
|
||||
action: () => _onCancelButtonPress(context))
|
||||
),
|
||||
SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: _buildButton(
|
||||
name: _confirmText,
|
||||
bgColor: (_error == null || (_error != null && _error!.isEmpty))
|
||||
? AppColor.colorTextButton
|
||||
: AppColor.colorDisableMailboxCreateButton,
|
||||
nameColor: (_error == null || (_error != null && _error!.isEmpty))
|
||||
? Colors.white
|
||||
: AppColor.colorDisableMailboxCreateButton,
|
||||
action: () => _onConfirmButtonPress(context))
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
})
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildButton({
|
||||
String? name, Color? nameColor, Color? bgColor, Function? action
|
||||
}) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => action?.call(),
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||
(Set<MaterialState> states) => bgColor ?? AppColor.colorTextButton),
|
||||
backgroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||
(Set<MaterialState> states) => bgColor ?? AppColor.colorTextButton),
|
||||
shape: MaterialStateProperty.all(RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(width: 0, color: bgColor ?? AppColor.colorTextButton),
|
||||
)),
|
||||
padding: MaterialStateProperty.resolveWith<EdgeInsets>(
|
||||
(Set<MaterialState> states) => EdgeInsets.symmetric(horizontal: 16)),
|
||||
elevation: MaterialStateProperty.resolveWith<double>((Set<MaterialState> states) => 0)),
|
||||
child: Text(name ?? '',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: nameColor ?? Colors.white)),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
typedef OnConfirmModelSheetsActionClick = void Function(String);
|
||||
typedef SetErrorStringModelSheets = String? Function(String);
|
||||
|
||||
class EditTextModalSheetBuilder {
|
||||
@protected
|
||||
late TextEditingController _textController;
|
||||
|
||||
@protected
|
||||
late Key _key;
|
||||
|
||||
@protected
|
||||
String _title = '';
|
||||
|
||||
@protected
|
||||
String _cancelText = '';
|
||||
|
||||
@protected
|
||||
String _confirmText = '';
|
||||
|
||||
@protected
|
||||
String _hintText = '';
|
||||
|
||||
@protected
|
||||
OnConfirmModelSheetsActionClick? _onConfirmActionClick;
|
||||
|
||||
@protected
|
||||
SetErrorStringModelSheets? _setErrorString;
|
||||
|
||||
@protected
|
||||
String? _error;
|
||||
|
||||
@protected
|
||||
Timer? _debounce;
|
||||
|
||||
@protected
|
||||
BoxConstraints? _constraints;
|
||||
|
||||
EditTextModalSheetBuilder();
|
||||
|
||||
void key(Key key) {
|
||||
_key = key;
|
||||
}
|
||||
|
||||
void title(String title) {
|
||||
_title = title;
|
||||
}
|
||||
|
||||
void cancelText(String cancelText) {
|
||||
_cancelText = cancelText;
|
||||
}
|
||||
|
||||
void hintText(String hintText) {
|
||||
_hintText = hintText;
|
||||
}
|
||||
|
||||
void boxConstraints(BoxConstraints? constraints) {
|
||||
_constraints = constraints;
|
||||
}
|
||||
|
||||
void setTextController(TextEditingController textEditingController) {
|
||||
_textController = textEditingController;
|
||||
}
|
||||
|
||||
void setTextSelection(TextSelection textSelection, {required String value}) {
|
||||
_textController = TextEditingController.fromValue(TextEditingValue(text: value, selection: textSelection));
|
||||
}
|
||||
|
||||
void setErrorString(SetErrorStringModelSheets setErrorString) {
|
||||
_setErrorString = setErrorString;
|
||||
}
|
||||
|
||||
void onConfirmAction(String confirmText, OnConfirmModelSheetsActionClick onConfirmActionClick) {
|
||||
_onConfirmActionClick = onConfirmActionClick;
|
||||
_confirmText = confirmText;
|
||||
}
|
||||
|
||||
void _onTextChanged(String name, StateSetter setState) {
|
||||
if (_debounce?.isActive ?? false) _debounce?.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
setState(() {
|
||||
_error = (_setErrorString != null) ? _setErrorString!(name) : '';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _onConfirmButtonPress(BuildContext context) {
|
||||
if (_error == null || (_error != null && _error!.isEmpty)) {
|
||||
Get.back();
|
||||
_onConfirmActionClick?.call(_textController.text);
|
||||
}
|
||||
}
|
||||
|
||||
void _onCancelButtonPress(BuildContext context) {
|
||||
Get.back();
|
||||
_debounce?.cancel();
|
||||
}
|
||||
|
||||
void show(context) {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
constraints: _constraints,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20.0),
|
||||
topRight: Radius.circular(20.0))),
|
||||
builder: (BuildContext context) {
|
||||
return StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
return Padding(
|
||||
key: _key,
|
||||
padding: MediaQuery.of(context).viewInsets,
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 50, right: 50, top: 48, bottom: 20),
|
||||
child: Wrap(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
_title,
|
||||
style: TextStyle(fontSize: 20, color: AppColor.colorNameEmail, fontWeight: FontWeight.w700),
|
||||
textAlign: TextAlign.center),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: TextFormField(
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
onChanged: (value) => _onTextChanged(value, setState),
|
||||
autofocus: true,
|
||||
controller: _textController,
|
||||
decoration: InputDecoration(
|
||||
errorText: _error,
|
||||
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: AppColor.colorDividerMailbox)),
|
||||
hintText: _hintText),
|
||||
)
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () => _onCancelButtonPress(context),
|
||||
child: Text(_cancelText.toUpperCase(), style: TextStyle(color: AppColor.colorTextButton)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => _onConfirmButtonPress(context),
|
||||
child: Text(_confirmText.toUpperCase(),
|
||||
style: TextStyle(
|
||||
color: (_error == null || (_error != null && _error!.isEmpty))
|
||||
? AppColor.colorTextButton
|
||||
: AppColor.colorDisableMailboxCreateButton)),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user