mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Improve ui api
This commit is contained in:
@@ -1227,6 +1227,7 @@ let UI = {
|
|||||||
* @param title {string}
|
* @param title {string}
|
||||||
* @param content {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.
|
* @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
|
* @since 1.2.1
|
||||||
*/
|
*/
|
||||||
showDialog: (title, content, actions) => {
|
showDialog: (title, content, actions) => {
|
||||||
@@ -1282,7 +1283,7 @@ let UI = {
|
|||||||
* Show an input dialog
|
* Show an input dialog
|
||||||
* @param title {string}
|
* @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.
|
* @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) => {
|
showInputDialog: (title, validator) => {
|
||||||
return sendMessage({
|
return sendMessage({
|
||||||
@@ -1298,7 +1299,7 @@ let UI = {
|
|||||||
* @param title {string}
|
* @param title {string}
|
||||||
* @param options {string[]}
|
* @param options {string[]}
|
||||||
* @param initialIndex {number?}
|
* @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) => {
|
showSelectDialog: (title, options, initialIndex) => {
|
||||||
return sendMessage({
|
return sendMessage({
|
||||||
|
@@ -17,7 +17,7 @@ mixin class JsUiApi {
|
|||||||
App.rootContext.showMessage(message: m.toString());
|
App.rootContext.showMessage(message: m.toString());
|
||||||
}
|
}
|
||||||
case 'showDialog':
|
case 'showDialog':
|
||||||
_showDialog(message);
|
return _showDialog(message);
|
||||||
case 'launchUrl':
|
case 'launchUrl':
|
||||||
var url = message['url'];
|
var url = message['url'];
|
||||||
if (url.toString().isNotEmpty) {
|
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;
|
BuildContext? dialogContext;
|
||||||
var title = message['title'];
|
var title = message['title'];
|
||||||
var content = message['content'];
|
var content = message['content'];
|
||||||
@@ -84,7 +84,7 @@ mixin class JsUiApi {
|
|||||||
child: Text('OK'),
|
child: Text('OK'),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
showDialog(
|
return showDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
dialogContext = context;
|
dialogContext = context;
|
||||||
|
Reference in New Issue
Block a user