Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(App());
- }
- class App extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: Text('My fun app'),
- ),
- body: TextWidget()),
- );
- }
- }
- class TextWidget extends StatefulWidget {
- @override
- _TextWidgetState createState() => _TextWidgetState();
- }
- class _TextWidgetState extends State<TextWidget> {
- var _text = 'Hello';
- void _changeText() {
- setState(() {
- _text = 'How are you ?';
- });
- }
- @override
- Widget build(BuildContext context) {
- return Column(children: <Widget>[
- Text(_text),
- TextController('Change text', _changeText)
- ]);
- }
- }
- class TextController extends StatelessWidget {
- final String _label;
- final Function _changeHandler;
- TextController(this._label, this._changeHandler);
- @override
- Widget build(BuildContext context) {
- return RaisedButton(onPressed: _changeHandler, child: Text(_label),);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement