Created
July 28, 2018 21:41
-
-
Save jonahwilliams/bb280d523bebf01fcc5415bbf2610b0a to your computer and use it in GitHub Desktop.
example
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
| // Copyright 2015 The Chromium Authors. 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/widgets.dart'; | |
| import 'package:flutter/material.dart'; | |
| import 'dart:async'; | |
| //void main() => runApp(const Center(child: const Text('Hello, world!', textDirection: TextDirection.ltr))); | |
| void main() { | |
| runApp(new MaterialApp(home: new EditProfileInformation())); | |
| } | |
| class EditProfileInformation extends StatefulWidget { | |
| @override | |
| EditProfileInformationState createState() { | |
| return new EditProfileInformationState(); | |
| } | |
| } | |
| class EditProfileInformationState extends State<EditProfileInformation> { | |
| Stream<int> dbCall; | |
| final StreamController _controller = new StreamController<int>(); | |
| final myController = TextEditingController(); | |
| @override | |
| void initState() { | |
| super.initState(); | |
| dbCall = _controller.stream; | |
| myController.addListener(_printLatestValue); | |
| new Future<void>.delayed(const Duration(seconds: 1)).then((_) { | |
| _controller.add(1); | |
| }); | |
| } | |
| void _printLatestValue() { | |
| print("Second text field: ${myController.text}"); | |
| } | |
| @override | |
| void dispose() { | |
| myController.removeListener(_printLatestValue); | |
| myController.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: new AppBar( | |
| title: const Text( | |
| 'Edit profile', | |
| ), | |
| ), | |
| body: new StreamBuilder<int>( | |
| stream: dbCall, | |
| builder: (BuildContext context, AsyncSnapshot<int> snapshot) { | |
| if (snapshot.connectionState == ConnectionState.active) { | |
| return new Container( | |
| child: new Column( | |
| children: <Widget>[ | |
| Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: TextField( | |
| controller: myController, | |
| ), | |
| ), | |
| new Text(snapshot.data.toString()), | |
| ], | |
| ), | |
| ); | |
| } else if (snapshot.connectionState == ConnectionState.waiting) { | |
| return const Center(child: const CircularProgressIndicator()); | |
| } else { | |
| return Center( | |
| child: Row( | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: const <Widget>[ | |
| Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: const Icon(Icons.error), | |
| ), | |
| Text('Error loading data') | |
| ], | |
| ), | |
| ); | |
| } | |
| }), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: () { | |
| _controller.add(1); | |
| }, | |
| child: const Icon(Icons.done), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, I figured this out. When I do this on the first page, it works fine. But, when I navigate to another page and perform the same operation, I'm able to reproduce it. Can you please look into this ?