Advertisement
Guest User

Untitled

a guest
Jul 10th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.79 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6.   // This widget is the root of your application.
  7.   @override
  8.   Widget build(BuildContext context) {
  9.     return MaterialApp(
  10.       title: 'Flutter Demo',
  11.       theme: ThemeData(
  12.         primarySwatch: Colors.blue,
  13.       ),
  14.       home: MyHomePage(title: 'Flutter Demo Home Page'),
  15.     );
  16.   }
  17. }
  18.  
  19. class MyHomePage extends StatefulWidget {
  20.   MyHomePage({Key key, this.title}) : super(key: key);
  21.   final String title;
  22.  
  23.   @override
  24.   _MyHomePageState createState() => _MyHomePageState();
  25. }
  26.  
  27. class _MyHomePageState extends State<MyHomePage> {
  28.   @override
  29.   Widget build(BuildContext context) {
  30.     return Scaffold(
  31.       appBar: AppBar(
  32.         title: Text(widget.title),
  33.       ),
  34.       body: Center(
  35.         child: Column(
  36.           mainAxisAlignment: MainAxisAlignment.center,
  37.           children: <Widget>[
  38.             Padding(
  39.               child: TheItem(),
  40.               padding: EdgeInsets.all(40),
  41.             ),
  42.             RaisedButton(
  43.               child: Text("Press me!"),
  44.               onPressed: () {
  45.                 Navigator.of(context)
  46.                     .push(MaterialPageRoute(builder: (context) {
  47.                   return ChildPage();
  48.                 }));
  49.               },
  50.             )
  51.           ],
  52.         ),
  53.       ), // This trailing comma makes auto-formatting nicer for build methods.
  54.     );
  55.   }
  56. }
  57.  
  58. class ChildPage extends StatefulWidget {
  59.   @override
  60.   _ChildPageState createState() => _ChildPageState();
  61. }
  62.  
  63. class _ChildPageState extends State<ChildPage> {
  64.   @override
  65.   Widget build(BuildContext context) {
  66.     return Scaffold(
  67.       appBar: AppBar(
  68.         title: Text("Child Page"),
  69.       ),
  70.       body: Center(
  71.           child:
  72.               TheItem()), // This trailing comma makes auto-formatting nicer for build methods.
  73.     );
  74.   }
  75. }
  76.  
  77. class TheItem extends StatelessWidget {
  78.   final TextEditingController textController = TextEditingController();
  79.   FocusNode focusNode = FocusNode();
  80.  
  81.   TheItem() {
  82.     focusNode.addListener(() {
  83.       if (focusNode.hasFocus) {
  84.         textController.selection =
  85.             TextSelection(baseOffset: 0, extentOffset: textController.text.length);
  86.       }
  87.     });
  88.   }
  89.  
  90.   @override
  91.   Widget build(BuildContext context) {
  92.     textController.text = "Hola";
  93.     return Dismissible(
  94.       key: Key("potatoes"),
  95.       onDismissed: (direction) {},
  96.       child: Column(
  97.         mainAxisAlignment: MainAxisAlignment.center,
  98.         children: <Widget>[
  99.           Padding(
  100.             child: TextField(
  101.               focusNode: focusNode,
  102.               controller: textController,
  103.             ),
  104.             padding: EdgeInsets.all(40),
  105.           ),
  106.         ],
  107.       ),
  108.     );
  109.   }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement