123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:intl/intl.dart';
- import 'package:vitalapp/components/alert_dialog.dart';
- import 'package:vitalapp/components/cell.dart';
- import 'package:vitalapp/components/dialog_date.dart';
- import 'package:vitalapp/components/dialog_input.dart';
- class VProfileTimeInputModel {
- VProfileTimeInputModel({this.name, this.time});
- late String? name;
- late DateTime? time;
- factory VProfileTimeInputModel.fromJson(Map<String, dynamic> jsonMap) {
- return VProfileTimeInputModel(
- name: jsonMap["name"],
- time: DateTime.parse(jsonMap["time"]),
- );
- }
- Map<String, dynamic> toJson() {
- Map<String, dynamic> jsonMap = {
- "name": name,
- "time": time != null ? DateFormat('yyyy-MM-dd').format(time!) : "",
- };
- return jsonMap;
- }
- }
- class VDialogProfileTimeInput extends StatefulWidget {
- const VDialogProfileTimeInput({
- Key? key,
- this.title,
- this.initialValue,
- }) : super(key: key);
- final String? title;
- final VProfileTimeInputModel? initialValue;
- @override
- // ignore: library_private_types_in_public_api
- _VDialogProfileTimeInputState createState() =>
- _VDialogProfileTimeInputState();
- Future<VProfileTimeInputModel?> show<VProfileTimeInputModel>() =>
- VAlertDialog.showDialog<VProfileTimeInputModel>(this);
- }
- class _VDialogProfileTimeInputState extends State<VDialogProfileTimeInput> {
- late VProfileTimeInputModel initialValue;
- @override
- void initState() {
- super.initState();
- initialValue = widget.initialValue ?? VProfileTimeInputModel();
- }
- @override
- Widget build(BuildContext context) {
- return VAlertDialog(
- title: widget.title,
- width: 440,
- contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
- content: _buildContent(context),
- showCancel: true,
- onConfirm: () {
- Get.back(result: initialValue);
- },
- );
- }
- Widget _buildContent(BuildContext context) {
- final children = <Widget>[];
- children.add(_buildTimeWidget());
- return SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: children,
- ),
- );
- }
- Widget _buildTimeWidget() {
- return VListFormCellGroup(
- children: [
- VListFormCell(
- label: '名称',
- content: initialValue.name,
- onTap: () async {
- var result = await VDialogInput(
- initialValue: initialValue.name,
- ).show();
- if (result != null) {
- setState(() {
- initialValue.name = result;
- });
- }
- },
- ),
- VListFormCell(
- label: '时间',
- content: initialValue.time != null
- ? DateFormat('yyyy-MM-dd').format(initialValue.time!)
- : '',
- onTap: () async {
- var result = await VDialogDate(
- initialValue: initialValue.time,
- maxValue: DateTime.now(),
- ).show();
- if (result != null) {
- setState(() {
- initialValue.time = result;
- });
- }
- },
- )
- ],
- );
- }
- }
|