Created
October 6, 2022 14:36
-
-
Save felipecastrosales/d2ed393b6896c726b64075de025f5e6a to your computer and use it in GitHub Desktop.
context_draft
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 'package:flutter/material.dart'; | |
import 'package:context_ext/context_ext.dart'; | |
class HomePage extends StatefulWidget { | |
const HomePage({super.key}); | |
@override | |
State<HomePage> createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
void resetTF() { | |
formKey.currentState?.reset(); | |
// context.form.saveForm(); | |
print('reset'); | |
print('reset3'); | |
print('reset2'); | |
} | |
final formKey = GlobalKey<FormState>(); | |
@override | |
Widget build(BuildContext context) { | |
var args1 = ModalRoute.of(context)?.settings.arguments; | |
var args2 = context.routeSettings?.arguments; | |
var size = MediaQuery.of(context).size; | |
debugPrint('args1: $args1'); | |
debugPrint('args2: $args2'); | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Context Extension'), | |
centerTitle: true, | |
), | |
drawer: const Drawer(), | |
body: SingleChildScrollView( | |
child: Column( | |
children: [ | |
GridView( | |
shrinkWrap: true, | |
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: 3, | |
), | |
children: [ | |
Container( | |
width: MediaQuery.of(context).size.width, | |
height: MediaQuery.of(context).size.height, | |
color: Colors.red, | |
alignment: Alignment.center, | |
child: const Text('mediaquery'), | |
), | |
Container( | |
width: size.width, | |
height: size.height, | |
color: Colors.yellow, | |
alignment: Alignment.center, | |
child: const Text('size'), | |
), | |
Container( | |
width: context.width, | |
height: context.height, | |
color: Colors.green, | |
alignment: Alignment.center, | |
child: const Text('context'), | |
), | |
TextButton( | |
onPressed: () { | |
context.pushNamed('/'); | |
}, | |
child: const Text('context'), | |
), | |
const SizedBox.shrink(), | |
TextButton( | |
onPressed: () { | |
Navigator.of(context).pushNamed('/'); | |
}, | |
child: const Text('Navigator'), | |
), | |
Text( | |
'Theme', | |
style: Theme.of(context).textTheme.headline5, | |
), | |
const SizedBox.shrink(), | |
Text( | |
'context', | |
style: context.textTheme.headline5, | |
), | |
], | |
), | |
Column( | |
children: [ | |
Form( | |
key: formKey, | |
child: Column( | |
children: <Widget>[ | |
TextFormField(), | |
TextFormField(), | |
TextFormField(), | |
TextButton( | |
child: const Text('Submit data'), | |
onPressed: () => resetTF(), | |
) | |
], | |
), | |
), | |
Text( | |
'You have pushed the button this many times:', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
Text( | |
'You have pushed the button this many times:', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
Text( | |
'You have pushed the button this many times:', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
], | |
), | |
], | |
), | |
), | |
floatingActionButton: Builder( | |
builder: (context) => Column( | |
mainAxisAlignment: MainAxisAlignment.end, | |
children: [ | |
FloatingActionButton( | |
child: const Icon(Icons.add), | |
onPressed: () => Scaffold.of(context).openDrawer(), | |
), | |
FloatingActionButton( | |
child: const Icon(Icons.more), | |
onPressed: () => context.openDrawer(), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment