Skip to content

Instantly share code, notes, and snippets.

@oshibka404
Last active June 10, 2020 16:24
Show Gist options
  • Save oshibka404/b22bb6657016adccd015340327b17818 to your computer and use it in GitHub Desktop.
Save oshibka404/b22bb6657016adccd015340327b17818 to your computer and use it in GitHub Desktop.
Copy value from one `Text` to another on
// 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