el_responsive 0.0.2 el_responsive: ^0.0.2 copied to clipboard
MediaQuery alternative that triggers rebuild only at the breakpoints that you provided to the package instead of triggering it on every screen change (pixel by pixel)
ElResponsive #
Flutter package for Responsive Layout. MediaQuery alternative that triggers rebuild only when the screen type changes, You set list of the screens for the package and the rebuild get trigges only when certain breakpoint of the screens reached instead of triggering it on every screen change (pixel by pixel)
Usage #
- Add the latest version of package to your pubspec.yaml (and run
dart pub get
):
dependencies:
el_responsive: ^0.0.1
- Import the package and use it in your Flutter App.
import 'package:el_responsive/el_responsive.dart';
How to use #
- Add
ElResponsiveContainer
widget to top level of your app, and specify list of screensList<ElScreen>
you want to listen to.ElScreen
has name and breakpoint value
ElResponsiveContainer(
screens: [
ElScreen(name: "mobile", breakpoint: 480),
ElScreen(name: "tablet", breakpoint: 768),
ElScreen(name: "desktop", breakpoint: 1024),
],
child: const MyHomePage(),
),
- Listen to
ElResponsive
insidebuild
method the same way you useMediaQuery
Notice that we castedElResponsive.of(context)!.screen
toString
in this example because the type of thename
we gave toElScreen
isString
@override
Widget build(BuildContext context) {
final String screenType = ElResponsive.of(context)!.screen as String;
return .......
This widget
now will get rebuilt only when the screen type we provided changes instead of rebuilding on every single pixel change when using MediaQuery
.