Last active
June 10, 2020 16:24
-
-
Save oshibka404/b22bb6657016adccd015340327b17818 to your computer and use it in GitHub Desktop.
Copy value from one `Text` to another on
This file contains 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
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
class TextWidget extends StatefulWidget { | |
_TextWidgetState createState() => _TextWidgetState(); | |
} | |
class _TextWidgetState extends State<TextWidget> { | |
String _text = ""; | |
@override | |
Widget build(BuildContext context) { | |
Text _textSource = Text( | |
"Value to be copied", | |
key: Key('text1') | |
); | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
_textSource, | |
RaisedButton( | |
onPressed: (){ | |
setState(() { | |
_text = _textSource.data; | |
}); | |
}, | |
child: Text("Copy value"), | |
), | |
SizedBox(height: 40), | |
Text( | |
_text, | |
key: Key('text2') | |
) | |
], | |
), | |
), | |
); | |
} | |
} | |
// End of the meaningful part | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: TextWidget(), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment