CopyPastor

Detecting plagiarism made easy.

Score: 0.8004566699810433; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2022-10-07
by Sage

Original Post

Original - Posted on 2020-07-14
by Yeimer



            
Present in both answers; Present only in the new answer; Present only in the old answer;

The problem here is that you are using `runBlocking` at all.
The most straightforward solution for your case would be to replace your `runBlocking {}` with a coroutine scope. At the top of your App() function, create your scope: `val scope = rememberCoroutineScope()`, then instead of `runBlocking` you can say `scope.launch {}`.
New code would be:
@OptIn(ExperimentalComposeUiApi::class) @Composable @Preview fun App() { var text by remember { mutableStateOf("Test button") } val scope = rememberCoroutineScope() Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ) { Column( modifier = Modifier.padding(50.dp) ) { Button( onClick = { text = "Wait..."//How to refresh UI to display this text? scope.launch { delay(5000)//blocking test val response: HttpResponse = client.request("https://myapi.com/") { // Configure request parameters exposed by HttpRequestBuilder } if (response.status == HttpStatusCode.OK) { val body = response.body<String>() println(body) } else { println("Error has occurred") } } text = "Test button" }, modifier = Modifier.fillMaxWidth() ) { Text(text) } OutlinedTextField( value = "", singleLine = true, onValueChange = { text = it } ) } } }
This worked for me
use [this plugin][1]
import 'package:flutter/material.dart'; import 'dart:async'; import 'package:flutter/services.dart'; import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart'; void main() => runApp(new MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => new _MyAppState(); } class _MyAppState extends State<MyApp> { TextEditingController _numberCtrl = new TextEditingController(); @override void initState() { super.initState(); _numberCtrl.text = "085921191121"; } @override Widget build(BuildContext context) { return new MaterialApp( home: new Scaffold( appBar: new AppBar( title: const Text('Plugin example app'), ), body: new Column( children:<Widget>[ Padding( padding: EdgeInsets.all(8.0), child: TextField( controller: _numberCtrl, decoration: InputDecoration( labelText: "Phone Number" ), keyboardType: TextInputType.number, ), ), RaisedButton( child: Text("Test Call"), onPressed: () async{ FlutterPhoneDirectCaller.callNumber(_numberCtrl.text); }, ) ] ), ), ); } }
[1]: https://pub.dev/packages/flutter_phone_direct_caller#-readme-tab-

        
Present in both answers; Present only in the new answer; Present only in the old answer;