setOnClickAsync( onClickAsync: function () { // Fetch data from API (example: JSON placeholder) $url = 'https://jsonplaceholder.typicode.com/todos/1'; $context = stream_context_create([ 'http' => [ 'timeout' => 10, 'method' => 'GET', ], ]); $response = file_get_contents($url, false, $context); if ($response === false) { throw new \Exception('Failed to fetch data'); } return json_decode($response, true); }, onComplete: function ($data) use ($container) { $statusLabel = new Label( text: 'Klicken Sie den Button, um Daten zu laden...', style: 'text-base text-gray-700', ); $resultLabel = new Label( text: '', style: 'text-sm text-blue-600', ); $statusLabel->setText('✓ Daten erfolgreich geladen!'); $formatted = 'ID: ' . ($data['id'] ?? 'N/A') . "\n"; $formatted .= 'Titel: ' . ($data['title'] ?? 'N/A') . "\n"; $formatted .= 'Erledigt: ' . (($data['completed'] ?? false) ? 'Ja' : 'Nein'); $resultLabel->setText($formatted); $container->addComponent($statusLabel); $container->addComponent($resultLabel); }, onError: function ($error) {}, ); $container->addComponent($button2); $app->setRoot($container); $app->run();