Last active
October 7, 2022 23:08
-
-
Save faustobdls/368c9ebdf5add2beba188bd922897a3e to your computer and use it in GitHub Desktop.
3 RunApp in one app
This file contains 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 (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'; | |
void stamp(String s) => print('${DateTime.now()} | $s'); | |
void main() async { | |
AwaitState(); | |
stamp('MyApp2'); | |
runApp(MyApp2()); | |
stamp('WaitState.instance.hasPermissionsFinish'); | |
await AwaitState.instance.hasPermissionsFinish(); | |
stamp('MyApp2'); | |
runApp(MyApp2()); | |
stamp('WaitState.instance.hasTapumeSOFinish'); | |
await AwaitState.instance.hasTapumeSOFinish(); | |
stamp('MyApp'); | |
runApp(MyApp()); | |
} | |
class AwaitState { | |
static AwaitState instance = AwaitState(); | |
int _next = 0; | |
void setNext() { | |
_next++; | |
} | |
Future<void> hasPermissionsFinish() async { | |
while (!(_next == 1)) { | |
await Future.delayed(const Duration(milliseconds: 500)); | |
} | |
} | |
Future<void> hasTapumeSOFinish() async { | |
while (!(_next == 2)) { | |
await Future.delayed(const Duration(milliseconds: 500)); | |
} | |
} | |
} | |
class MyApp2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHome2Page(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHome2Page extends StatefulWidget { | |
final String title; | |
const MyHome2Page({ | |
Key? key, | |
required this.title, | |
}) : super(key: key); | |
@override | |
State<MyHome2Page> createState() => _MyHome2PageState(); | |
} | |
class _MyHome2PageState extends State<MyHome2Page> { | |
void _incrementCounter() { | |
AwaitState.instance.setNext(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: const [ | |
Text('Ao favoritar voce passa pra proxima tela em 5s:'), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _incrementCounter, | |
tooltip: 'Increment', | |
child: const Icon(Icons.favorite), | |
), | |
); | |
} | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
const MyHomePage({ | |
Key? key, | |
required this.title, | |
}) : super(key: key); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _counter = 0; | |
void _incrementCounter() { | |
setState(() { | |
_counter++; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
const Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'$_counter', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _incrementCounter, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment