ax_responsive 0.0.6
ax_responsive: ^0.0.6 copied to clipboard
A Flutter package for creating adaptive and responsive layouts across devices easily.
π± ax_responsive #
A powerful and minimal Flutter package for building responsive UIs easily.
It provides helpers like AxConsumer, AxResponsive, and context extensions to make adaptive layouts effortless.
π Installation #
Add to your pubspec.yaml:
dependencies:
ax_responsive: ^latest_version
Then run:
flutter pub get
βοΈ Setup #
Wrap your app with AxResponsive and ProviderScope (for Riverpod):
import 'package:ax_responsive/ax_responsive.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(
ProviderScope(
child: AxResponsive(const MyApp()),
),
);
}
π§© Components Overview #
πΉ AxResponsive #
This widget initializes the responsive engine and listens for size/orientation changes.
Wrap it around your root widget (usually your MaterialApp).
AxResponsive(const MyApp())
πΉ AxConsumer #
A widget that rebuilds in real time whenever the screen size, orientation, or platform changes.
Perfect for live responsive updates without manual setState calls.
AxConsumer(
builder: (context) {
final width = 0.5.sw;
final height = 0.3.sh;
return Container(width: width, height: height);
},
)
πΉ Screen Size Extensions #
Easily get responsive dimensions using .sw and .sh (screen width/height):
| Expression | Description | Example |
|---|---|---|
0.5.sw |
50% of screen width | Container(width: 0.5.sw) |
0.3.sh |
30% of screen height | Container(height: 0.3.sh) |
πΉ Responsive Builders #
Use context.res() to define different widgets for each device type:
context.res(
orElse: () => Text("Default View"),
mobile: (v) => Text("π± Mobile"),
tabletLow: (v) => Text("π» Tablet Low"),
tabletPortrait: (v) => Text("π Tablet Portrait"),
large: (v) => Text("π₯οΈ Large Screen"),
desktop: (v) => Text("π₯οΈ Desktop"),
);
πΉ context.resMaybe() #
Same as res, but returns a widget directly instead of a function.
Simplifies usage when you donβt need the parameter.
context.resMaybe(
orElse: Text("Default View"),
mobile: Text("π± Mobile View"),
desktop: Text("π₯οΈ Desktop View"),
);
πΉ Orientation Builder #
Detect orientation changes easily:
context.orien(
portrait: "π² Portrait Mode",
landscape: "π Landscape Mode",
);
πΉ Platform Checks #
Quick checks for platform type:
context.isMobile // true if mobile
context.isTablet // true if tablet
context.isDesktop // true if desktop
context.isPortrait // true if portrait
...
π‘ Key Features #
β
Real-time responsive rebuilds
β
Simple .sw and .sh extensions for sizing
β
Orientation and platform detection
β
Works perfectly with Riverpod
β
Lightweight and production-ready
π§° Example Folder #
For a full working demo, check out the example/ folder in the repository.
β€οΈ Made with Flutter #
If you find this package helpful, donβt forget to β the repo!