Created
October 16, 2021 12:28
-
-
Save IsmailAlamKhan/9478bef22c43119e2ca356a4a0b06588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp(title: 'Material App', home: Home()); | |
} | |
} | |
class Home extends StatefulWidget { | |
const Home({ | |
Key? key, | |
}) : super(key: key); | |
@override | |
State<Home> createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> { | |
final tec1 = TextEditingController(); | |
final tec2 = TextEditingController(); | |
late final Listenable listenable; | |
@override | |
void initState() { | |
super.initState(); | |
listenable = Listenable.merge([tec1, tec2]); | |
} | |
@override | |
void dispose() { | |
tec1.dispose(); | |
tec2.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('Material App Bar')), | |
body: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Center( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
TextField( | |
controller: tec1, | |
decoration: const InputDecoration( | |
hintText: 'TEC1', | |
border: OutlineInputBorder(), | |
), | |
), | |
const SizedBox(height: 10), | |
TextField( | |
controller: tec2, | |
decoration: const InputDecoration( | |
hintText: 'TEC2', | |
border: OutlineInputBorder(), | |
), | |
), | |
const SizedBox(height: 10), | |
AnimatedBuilder( | |
animation: listenable, | |
builder: (context, child) { | |
debugPrint("TEXT REBUILD"); | |
return Text('tec1: ${tec1.text}\ntec2: ${tec2.text}'); | |
}, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment