mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
Improve ui api
This commit is contained in:
@@ -1227,6 +1227,7 @@ let UI = {
|
||||
* @param title {string}
|
||||
* @param content {string}
|
||||
* @param actions {{text:string, callback: () => void | Promise<void>, style: "text"|"filled"|"danger"}[]} - If callback returns a promise, the button will show a loading indicator until the promise is resolved.
|
||||
* @returns {Promise<void>} - Resolved when the dialog is closed.
|
||||
* @since 1.2.1
|
||||
*/
|
||||
showDialog: (title, content, actions) => {
|
||||
@@ -1282,7 +1283,7 @@ let UI = {
|
||||
* Show an input dialog
|
||||
* @param title {string}
|
||||
* @param validator {(string) => string | null | undefined} - A function that validates the input. If the function returns a string, the dialog will show the error message.
|
||||
* @returns {string | null} - The input value. If the dialog is canceled, return null.
|
||||
* @returns {Promise<string | null>} - The input value. If the dialog is canceled, return null.
|
||||
*/
|
||||
showInputDialog: (title, validator) => {
|
||||
return sendMessage({
|
||||
@@ -1298,7 +1299,7 @@ let UI = {
|
||||
* @param title {string}
|
||||
* @param options {string[]}
|
||||
* @param initialIndex {number?}
|
||||
* @returns {number | null} - The selected index. If the dialog is canceled, return null.
|
||||
* @returns {Promise<number | null>} - The selected index. If the dialog is canceled, return null.
|
||||
*/
|
||||
showSelectDialog: (title, options, initialIndex) => {
|
||||
return sendMessage({
|
||||
|
@@ -17,7 +17,7 @@ mixin class JsUiApi {
|
||||
App.rootContext.showMessage(message: m.toString());
|
||||
}
|
||||
case 'showDialog':
|
||||
_showDialog(message);
|
||||
return _showDialog(message);
|
||||
case 'launchUrl':
|
||||
var url = message['url'];
|
||||
if (url.toString().isNotEmpty) {
|
||||
@@ -55,7 +55,7 @@ mixin class JsUiApi {
|
||||
}
|
||||
}
|
||||
|
||||
void _showDialog(Map<String, dynamic> message) {
|
||||
Future<void> _showDialog(Map<String, dynamic> message) {
|
||||
BuildContext? dialogContext;
|
||||
var title = message['title'];
|
||||
var content = message['content'];
|
||||
@@ -84,7 +84,7 @@ mixin class JsUiApi {
|
||||
child: Text('OK'),
|
||||
));
|
||||
}
|
||||
showDialog(
|
||||
return showDialog(
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
dialogContext = context;
|
||||
|
Reference in New Issue
Block a user