Widgets in Flutter
Flutter's building blocks are called widgets, which are UI components that represent a part of the application's user interface. Widgets can be combined and nested to create complex UI designs.
Example Code
Here's an example of a simple Flutter widget that displays a text message:
dart
import 'package:flutter/material.dart';
class MyTextWidget extends StatelessWidget {
final String message;
MyTextWidget(this.message);
@override
Widget build(BuildContext context) {
return Text(message);
}
}
In this code, we define a new class called MyTextWidget that extends the StatelessWidget class. The StatelessWidget class is a basic Flutter widget that doesn't have any mutable state.
The MyTextWidget class takes a message parameter in its constructor and uses it to display a text message using the Text widget.
No comments:
Post a Comment