inputBoxContent static method

Widget inputBoxContent({
  1. required BuildContext context,
  2. required String title,
  3. String? tips,
  4. required dynamic onSubmitted(
    1. String text
    ),
  5. required TUITheme theme,
  6. bool isShowCancel = false,
  7. Offset? initOffset,
  8. String? initText,
  9. required TextEditingController selectionController,
})

Implementation

static Widget inputBoxContent(
    {required BuildContext context,
    required String title,
      String? tips,
    required Function(String text) onSubmitted,
    required TUITheme theme,
    bool isShowCancel = false,
      Offset? initOffset,
      String? initText,
    required TextEditingController selectionController}) {
  final isDesktopScreen = TUIKitScreenUtils.getFormFactor(context) == DeviceType.Desktop;
  selectionController.text = initText ?? "";
  return SingleChildScrollView(
      child: Container(
    padding: EdgeInsets.only(
      top: 16,
      left: 16,
      right: 16,
      bottom:
          isDesktopScreen ? 16 : MediaQuery.of(context).viewInsets.bottom + 30,
    ),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.only(bottom: 16),
          child: Text(title,
              style:
                  const TextStyle(fontWeight: FontWeight.w500, fontSize: 16)),
        ),
        Divider(height: 2, color: theme.weakDividerColor),
        TextField(

          onSubmitted: (text) {
            onSubmitted(text);
            if (entry != null) {
              entry?.remove();
              entry = null;
            } else {
              Navigator.pop(context);
            }
          },
          autofocus: true,
          controller: selectionController,
        ),
        if(tips != null) Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              padding: const EdgeInsets.symmetric(vertical: 5),
              height: 40,
              child: Text(
                tips,
                style: const TextStyle(color: Colors.grey, fontSize: 12),
              ),
            )
          ],
        ),
        if (isDesktopScreen)
          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              if (isShowCancel)
                Container(
                    margin: const EdgeInsets.only(right: 20),
                    child: SizedBox(
                      width: 84,
                      child: ElevatedButton(
                          style: ButtonStyle(
                            backgroundColor: MaterialStateProperty.all(
                                theme.wideBackgroundColor),
                            shape: MaterialStateProperty.all(
                                RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(5))),
                          ),
                          onPressed: () {
                            if (entry != null) {
                              entry?.remove();
                              entry = null;
                            } else {
                              Navigator.pop(context);
                            }
                          },
                          child: Text(
                            TIM_t("取消"),
                            style: TextStyle(color: theme.darkTextColor),
                          )),
                    )),
              SizedBox(
                width: 84,
                child: ElevatedButton(
                    style: ButtonStyle(
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5))),
                    ),
                    onPressed: () {
                      String text = selectionController.text;
                      onSubmitted(text);
                      if (entry != null) {
                        entry?.remove();
                        entry = null;
                      } else {
                        Navigator.pop(context);
                      }
                    },
                    child: Text(TIM_t("保存"))),
              ),
            ],
          ),
        if (!isDesktopScreen)
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              if (isShowCancel)
                Expanded(
                    child: Container(
                  margin: const EdgeInsets.only(right: 20),
                  child: ElevatedButton(
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(
                            theme.wideBackgroundColor),
                        shape: MaterialStateProperty.all(
                            RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(5))),
                      ),
                      onPressed: () {
                        if (entry != null) {
                          entry?.remove();
                          entry = null;
                        } else {
                          Navigator.pop(context);
                        }
                      },
                      child: Text(
                        TIM_t("取消"),
                        style: TextStyle(color: theme.darkTextColor),
                      )),
                )),
              Expanded(
                  child: SizedBox(
                child: ElevatedButton(
                    style: ButtonStyle(
                      shape: MaterialStateProperty.all(RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5))),
                    ),
                    onPressed: () {
                      String text = selectionController.text;
                      onSubmitted(text);
                      if (entry != null) {
                        entry?.remove();
                        entry = null;
                      } else {
                        Navigator.pop(context);
                      }
                    },
                    child: Text(TIM_t("确定"))),
              )),
            ],
          ),
      ],
    ),
  ));
}