contextions 0.2.0
contextions: ^0.2.0 copied to clipboard
A Flutter package that adds extension methods on BuildContext for easy access to Navigator, Theme, and MediaQuery functions.
import 'package:contextions/contextions.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Material App',
home: Home(),
);
}
}
class Home extends StatelessWidget {
const Home({
super.key,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Material App Bar'),
),
body: Center(
child: Column(
children: [
TextButton(
onPressed: () {
context.to(const ScreenTwo());
},
child: const Text('Go to Screen Two'),
),
const SizedBox(
height: 20,
),
TextButton(
onPressed: () {
context.showSnackbar('Hello World');
},
child: const Text('Show Snackbar'),
),
const SizedBox(
height: 20,
),
],
),
),
);
}
}
class ScreenTwo extends StatelessWidget {
const ScreenTwo({
super.key,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Material App Bar'),
),
body: Center(
child: Column(
children: [
const Text('Hello World'),
const SizedBox(
height: 20,
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Go Back'),
),
],
),
),
);
}
}