Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: MyHomePage(title: 'Flutter Demo Home Page'),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
- final String title;
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(widget.title),
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Padding(
- child: TheItem(),
- padding: EdgeInsets.all(40),
- ),
- RaisedButton(
- child: Text("Press me!"),
- onPressed: () {
- Navigator.of(context)
- .push(MaterialPageRoute(builder: (context) {
- return ChildPage();
- }));
- },
- )
- ],
- ),
- ), // This trailing comma makes auto-formatting nicer for build methods.
- );
- }
- }
- class ChildPage extends StatefulWidget {
- @override
- _ChildPageState createState() => _ChildPageState();
- }
- class _ChildPageState extends State<ChildPage> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("Child Page"),
- ),
- body: Center(
- child:
- TheItem()), // This trailing comma makes auto-formatting nicer for build methods.
- );
- }
- }
- class TheItem extends StatelessWidget {
- final TextEditingController textController = TextEditingController();
- FocusNode focusNode = FocusNode();
- TheItem() {
- focusNode.addListener(() {
- if (focusNode.hasFocus) {
- textController.selection =
- TextSelection(baseOffset: 0, extentOffset: textController.text.length);
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- textController.text = "Hola";
- return Dismissible(
- key: Key("potatoes"),
- onDismissed: (direction) {},
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Padding(
- child: TextField(
- focusNode: focusNode,
- controller: textController,
- ),
- padding: EdgeInsets.all(40),
- ),
- ],
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement