import 'package:flutter/material.dart'; class UIDialogs { static Future showTextInput(BuildContext context, String title, String hintText) { var _textFieldController = TextEditingController(); return showDialog( context: context, builder: (context) => AlertDialog( title: Text(title), content: TextField( autofocus: true, controller: _textFieldController, decoration: InputDecoration(hintText: hintText), ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: Text('Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(_textFieldController.text), child: Text('OK'), ), ], ), ); } static Future showUsernameRequiredDialog(BuildContext context) { var _textFieldController = TextEditingController(); return showDialog( context: context, builder: (context) => AlertDialog( title: Text('Username Required'), content: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Please set a public username to subscribe to channels from other users.'), SizedBox(height: 16), TextField( autofocus: true, controller: _textFieldController, decoration: InputDecoration(hintText: 'Enter username'), ), ], ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: Text('Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(_textFieldController.text), child: Text('OK'), ), ], ), ); } static Future showConfirmDialog(BuildContext context, String title, {String? text, String? okText, String? cancelText}) { return showDialog( context: context, builder: (context) => AlertDialog( title: Text(title), content: (text != null) ? Text(text) : null, actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), child: Text(cancelText ?? 'Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(true), child: Text(okText ?? 'OK'), ), ], ), ).then((value) => value ?? false); } }