I am new to flutter and want to display the text widget after pressing the button.
import 'package:flutter/material.dart';
class dellecturer extends StatefulWidget {
@override
_dellecturerState createState() => _dellecturerState();
}
class _dellecturerState extends State<dellecturer> {
@override
Widget build(BuildContext context) {
return Card(
color: Colors.grey.shade300,
margin: EdgeInsets.all(10.0),
child: Container(
margin: EdgeInsets.all(20),
child: ListView(
children: <Widget>[
new Container(
margin: EdgeInsets.only(top:13,bottom: 25),
alignment: Alignment.topCenter,
child:Text("DELETE BY LECTURER ID",style: TextStyle(color: Colors.redAccent,fontWeight: FontWeight.bold,fontSize: 20.0),),
),
new TextField(
decoration:InputDecoration(border: OutlineInputBorder(borderSide: BorderSide(style: BorderStyle.solid),),labelText: "LECTURER ID",hintText: "Enter lecturer ID",prefixIcon: Icon(Icons.person)),
),
Padding(padding: EdgeInsets.only(top:20),),
new RaisedButton(child: Text("OK",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.white,fontSize: 15),),color: Colors.red,onPressed: (){Form(child: Search());},),//onclick search
],
),
),
);
}
Widget Search(){ //should display
setState(() {
return Scaffold(
body: Container(
child: ListView(
children: <Widget>[
new Text("ID :1234",style: TextStyle(color: Colors.redAccent),),
new Text("ID :1234",style: TextStyle(color: Colors.redAccent),),
new Text("ID :1234",style: TextStyle(color: Colors.redAccent),),
],
),
)
);
});
}
}
I don't understand what are you trying to do exactly in code , but if you need to display a Text widget after pressing button you can simply define a bool variable to detect button click as below :
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: MyApp(),
));
class MyApp extends StatefulWidget {
@override
MyAppState createState() {
return new MyAppState();
}
}
class MyAppState extends State<MyApp> {
bool pressed = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
pressed ? Text(" text is here ") : SizedBox(),
RaisedButton(
child: Text("show text"),
onPressed: () {
setState(() {
pressed = true;
});
},
)
],
),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With