Created
February 22, 2024 13:22
-
-
Save felipecastrosales/c6a058223eac6f3523b76b5dd1af0d59 to your computer and use it in GitHub Desktop.
BASE 1
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
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'HomePage'), | |
); | |
} | |
} | |
class MyHomePage extends BasePage { | |
const MyHomePage({ | |
super.key, | |
required this.title, | |
}); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends BasePageState<MyHomePage> { | |
@override | |
void initState() { | |
debugPrint('BASE WORKER: INICIALIZOU A PAGINA 1'); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
TextButton( | |
child: const Text('Open main2'), | |
onPressed: () => Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => const MyHomePage2(title: 'Homepage 2'), | |
), | |
), | |
), | |
const Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'$counter', | |
style: Theme.of(context).textTheme.headlineMedium, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: incrementCounter, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
} | |
class MyHomePage2 extends BasePage { | |
const MyHomePage2({ | |
super.key, | |
required this.title, | |
}); | |
final String title; | |
@override | |
_MyHomePageState2 createState() => _MyHomePageState2(); | |
} | |
class _MyHomePageState2 extends BasePageState<MyHomePage2> { | |
@override | |
void initState() { | |
debugPrint('BASE WORKER: INICIALIZOU A PAGINA 2'); | |
super.initState(); | |
} | |
@override | |
void incrementCounter() { | |
setState(() { | |
counter += 2; | |
}); | |
} | |
@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.headlineMedium, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: incrementCounter, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
} | |
class BasePage extends StatefulWidget { | |
const BasePage({Key? key}) : super(key: key); | |
@override | |
BasePageState createState() => BasePageState(); | |
} | |
class BasePageState<T extends BasePage> extends State<T> { | |
int counter = 0; | |
@override | |
void initState() { | |
debugPrint('BASE WORKER: INICIALIZOU A BASE PAGE'); | |
super.initState(); | |
} | |
void incrementCounter() { | |
setState(() { | |
counter++; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment