👨‍🏫0.5 TextFormField() controller

import 'package:flutter/material.dart';

class Lesson18 extends StatefulWidget {
  const Lesson18({super.key});

  @override
  State<Lesson18> createState() => _Lesson18State();
}

class _Lesson18State extends State<Lesson18> {
  TextEditingController titleController = TextEditingController();

  String title = 'Hello';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: .start,
          children: [
            Text(title, style: TextStyle(fontSize: 40),),
            TextFormField(
              controller: titleController,
              decoration: InputDecoration(
                border: OutlineInputBorder()
              ),
            ),

            ElevatedButton(onPressed: (){
              setState(() {
                title = titleController.text!;
              });
            }, child: Text('Apply'))
          ],
        ),
      ),
    );
  }
}

Last updated