Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
StatelessWidget - Recommended for immutable widgets. These are widgets that do not have an internal state, depend only on the configuration parameters and on the parent widgets.
Here are some widgets that inherit from StatelessWidget:
The simplest construct to create a widget from the superclass StatelessWidget is:
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Text('my text');
}
}
class MyWidget extends StatefulWidget {
@override
createState() => new MyWidgetState();
}
class MyWidgetState extends State<MyWidget> {
@override
initState() {
super.initState();
// ...
}
@override
Widget build(BuildContext context) {
return new Text('my text');
}
}
void main (){
Person bob = Person("324", "Bob");
print(bob.id.runtimeType); // String
Person sam = Person(123, "Sam");
print(sam.id.runtimeType); // int
}
// T это Generic, если его не было,
//нам пришлось-бы использовать несколько классов для определения идентификатора пользователя,
//но в данном случае он Generic и мы можем передавать в него любой тип данных.
class Person<T>{
T id; // идентификатор пользователя
String name; // имя пользователя
Person(this.id, this.name);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question