Created
February 13, 2020 09:44
-
-
Save kuhnroyal/1aed87c97b55145807879c10a919d11d to your computer and use it in GitHub Desktop.
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
| import 'dart:async'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/cupertino.dart'; | |
| final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| DataStream stream = DataStream(); | |
| class MyApp extends StatelessWidget { | |
| // This widget is the root of your application. | |
| @override | |
| Widget build(BuildContext context) { | |
| return CupertinoApp( | |
| title: 'Splash Test', | |
| theme: CupertinoThemeData( | |
| primaryColor: Color.fromARGB(255, 0, 0, 255), | |
| ), | |
| home: MyHomePage(title: 'Splash Test 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> { | |
| bool textBool = false; | |
| int counter = 0; | |
| void changeTest(context) async { | |
| int counter = 0; | |
| Timer.periodic(Duration (seconds: 2), (Timer t) { | |
| counter++; | |
| stream.dataSink.add(true); | |
| if (counter >= 3) { | |
| t.cancel(); | |
| stream.dispose(); | |
| Navigator.pop(context); | |
| } | |
| },); | |
| Navigator.push(context, CupertinoPageRoute(builder: (context) => Page2(stream: stream))); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return CupertinoPageScaffold( | |
| child: Center( | |
| child: CupertinoButton( | |
| child: Text('To Splash'), | |
| onPressed: () => changeTest(context), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class DataStream { | |
| StreamController _streamController; | |
| StreamSink<bool> get dataSink => | |
| _streamController.sink; | |
| Stream<bool> get dataStream => | |
| _streamController.stream; | |
| DataStream() { | |
| _streamController = StreamController<bool>(); | |
| } | |
| dispose() { | |
| _streamController?.close(); | |
| } | |
| } | |
| class Page2 extends StatefulWidget { | |
| final DataStream stream; | |
| Page2({this.stream}); | |
| @override | |
| State<StatefulWidget> createState() => new PageState(); | |
| } | |
| class PageState extends State<Page2> { | |
| bool textChanger = false; | |
| bool firstText = true; | |
| Text myText() { | |
| if (textChanger) { | |
| Text text1 = new Text('Text One', | |
| style: TextStyle(color: Color.fromARGB(255, 0, 0, 0))); | |
| return text1; | |
| } else { | |
| Text text1 = new Text('Text Two', | |
| style: TextStyle(color: Color.fromARGB(255, 0, 0, 0))); | |
| return text1; | |
| } | |
| } | |
| void changeText() { | |
| if (!firstText) { | |
| if (textChanger) { | |
| print('Change One'); | |
| setState(() { | |
| textChanger = false; | |
| }); | |
| } else { | |
| print('Change Two'); | |
| setState(() { | |
| textChanger = true; | |
| }); | |
| } | |
| } else { | |
| firstText = false; | |
| } | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return new Scaffold( | |
| body: new Container( | |
| child: Center( | |
| child: myText() | |
| ) | |
| ),); | |
| } | |
| @override | |
| void initState() { | |
| super.initState(); | |
| widget.stream.dataStream.listen((onData) { | |
| changeText(); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment