fluttools 0.1.3
A collection of tools for Flutter development, simplifying usage and some interesting stuff!
Fluttools
Help with some things in flutter
Usage shortcuts with context
There's no secret, just an extension to make it easier to get the theme, screen size, scope functions, among others...
Something like this is usually used within the build:
final theme = Theme.of(context);
This can be made easier by looking like this:
Example:
class ThemeExample extends StatelessWidget {
const ThemeExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: context.colorScheme.background,
child: Center(
child: Text(
"Easy",
style: context.textTheme.bodyMedium,
),
),
);
}
}
Obviously it will only return correctly if you correctly fill in the theme in the Material App!
Something similar happens when getting the screen size:
final sizeScreen = MediaQuery.of(context).size;
final screenHeight = screen.height;
Example:
class Example extends StatelessWidget {
const Example({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: context.screenHeight,
color: context.colorScheme.background,
child: Center(
child: Text(
"Easy",
style: context.textTheme.bodyMedium,
),
),
);
}
}
Usage DateTimeField
You can easily create DateTimeField with your decoration, for example:
First, you should know that you'll need a DateTimeController, which will be in charge of storing and doing some extra functions.
So, in a StatefulWidget, use something similar to this:
final _dateController = DateTimeController(
labelToday: "Today!",
format: "dd/MM/yyyy",
);
The format is the same used in other packages!
The controller should be disposed correctly!
Example:
import 'package:fluttools/fluttools.dart';
class MyDatepicker extends StatefulWidget {
const MyDatepicker({Key? key}) : super(key: key);
@override
State<MyDatepicker> createState() => _MyDatepickerState();
}
class _MyDatepickerState extends State<MyDatepicker> {
final _dateController = DateTimeController(
labelToday: "Today!",
format: "dd/MM/yyyy",
);
@override
void dispose() {
_datecontroller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Fluttools Example"),
),
body: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 40,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
DateTimeField(
controller: _dateController,
alignment: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
),
decoration: const InputDecoration(
filled: true,
fillColor: Colors.blueAccent,
prefixIcon: Icon(
Icons.edit_calendar,
color: Colors.white,
size: 24,
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10),
),
borderSide: BorderSide(
color: Colors.blueAccent,
width: 1,
),
),
),
),
],
),
),
);
}
}