at this time i'm working a project and i'm tryping to update the "code" from dart pad widget using setState method but it won't update i dont know what's the issue here so this is my code below:
import 'package:flutter/material.dart';
import 'package:dart_pad_widget/dart_pad_widget.dart';
import 'package:flutter/foundation.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final keyValue = Key('codeOne');
TextEditingController promptController = new TextEditingController();
TextEditingController tokenController = new TextEditingController();
String response;
int token = 50;
@override
void initState() {
super.initState();
promptController = TextEditingController();
tokenController = TextEditingController();
}
@override
void dispose() {
super.dispose();
promptController.dispose();
tokenController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.only(top: 30),
width: 600,
child: TextField(
controller: promptController,
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration(
hintText: 'Enter your request.',
border: OutlineInputBorder(),
),
),
),
Container(
margin: EdgeInsets.only(top: 10, bottom: 10),
width: 600,
child: TextField(
controller: tokenController,
decoration: InputDecoration(
hintText: 'Enter max tokens (default is 50)',
border: OutlineInputBorder(),
),
onChanged: (tokenValue) {
token = int.parse(tokenValue);
},
),
),
Container(
width: 600,
child: FlatButton(
key: keyValue,
child: Text('DONE'),
textColor: Colors.white,
color: Colors.blue,
onPressed: () {
setState(() {
response = 'Hello'; //
});
},
),
),
SizedBox(height: 20),
DartPad(
//dart output not showing after set state.
key: keyValue,
flutter: true,
width: 1024,
height: 600,
code: response,
),
SizedBox(height: 15),
],
),
],
),
),
);
}
}