showDialog with TextField

PHOTO EMBED

Wed Feb 09 2022 08:26:10 GMT+0000 (UTC)

Saved by @zbahadir #dart #flutter

        showDialog<dynamic>(
            useRootNavigator: false,
            barrierDismissible: false,
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: Text(
                  Utils.getString(context, 'report_item'),
                ),
                content: TextField(
                  controller: showdialogText,
                  keyboardType: TextInputType.multiline,
                  textInputAction: TextInputAction.newline,
                  minLines: 1,
                  maxLines: 5,
                  onChanged: (value) {
                    setState(() {
                      valueText = value;
                    });
                  },
                ),
                actions: <Widget>[
                  Container(
                    padding: EdgeInsets.all(5),
                    child: Row(
                      children: <Widget>[
                        Expanded(
                          flex: 1,
                          child: ElevatedButton.icon(
                            icon: const Icon(Icons.cancel),
                            label: Text(
                              Utils.getString(context, 'cancel'),
                            ),
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                            style: ElevatedButton.styleFrom(
                              primary: Colors.red,
                              onPrimary: Colors.white,
                            ),
                          ),
                        ),
                        const SizedBox(width: 5),
                        Expanded(
                            flex: 1,
                            child: ElevatedButton.icon(
                              icon: const Icon(Icons.save),
                              label: Text(
                                Utils.getString(context, 'save'),
                              ),
                              onPressed: () async {
                                await PsProgressDialog.showDialog(context);
                                final UserReportItemParameterHolder userReportItemParameterHolder = UserReportItemParameterHolder(
                                  itemId: widget.itemId,
                                  reportedUserId: widget.reportedUserId,
                                  message: valueText,
                                );
                                final PsResource<ApiStatus> _apiStatus = await widget.userProvider!.userReportItem(userReportItemParameterHolder.toMap());

                                if (_apiStatus.data != null && _apiStatus.data!.status != null) {
                                  await widget.itemDetailProvider.deleteLocalProductCacheById(widget.itemId, widget.reportedUserId);
                                }

                                PsProgressDialog.dismissDialog();
                                Navigator.pushReplacementNamed(
                                  context,
                                  RoutePaths.home,
                                );
                              },
                              style: ElevatedButton.styleFrom(
                                primary: Colors.green,
                                onPrimary: Colors.white,
                              ),
                            )),
                      ],
                    ),
                  ),
                ],
              );
            });
content_copyCOPY