AdaptiveSpacing
A lightweight Flutter package that provides responsive spacing widgets that automatically adapt to different screen sizes. Stop wrestling with manual spacing calculations and create beautiful, responsive layouts effortlessly.
Features
- ð Automatic Screen-Based Scaling - Spacing adjusts dynamically based on screen dimensions
- ðą Cross-Device Consistency - Maintain visual harmony across phones, tablets, and desktops
- ðŊ Simple API - Intuitive widget names like
Oneh()
,Twow()
for quick implementation - ðĻ Design-Friendly - Perfect for implementing precise spacing from design specifications
- ðŠķ Lightweight - Minimal impact on your app's size
Installation
Add this to your package's pubspec.yaml
file:
dependencies:
adaptive_spacing: ^1.0.1
Then run:
flutter pub get
Usage
Import the package:
import 'package:adaptive_spacing/adaptive_spacing.dart';
Vertical Spacing
Column(
children: [
const Text('Profile Picture'),
Oneh(), // Adds 1% of screen height
const CircleAvatar(
radius: 50,
backgroundImage: AssetImage('assets/profile.jpg'),
),
Twoh(), // Adds 2% of screen height
const Text('John Doe'),
],
)
Available vertical spacers:
Halfh()
- 0.5% of screen heightOneh()
- 1% of screen heightTwoh()
- 2% of screen heightThreeh()
- 3% of screen heightFiveh()
- 5% of screen heightSevenh()
- 7% of screen height
Horizontal Spacing
Row(
children: [
const Icon(Icons.star),
Onew(), // Adds 1% of screen width
const Text('4.9'),
Twow(), // Adds 2% of screen width
const Text('(123 reviews)'),
],
)
Available horizontal spacers:
Onew()
- 1% of screen widthTwow()
- 2% of screen widthThreew()
- 3% of screen widthFivew()
- 5% of screen width
Example
Here's a complete example showing how AdaptiveSpacing can improve your layout code:
class ProfileCard extends StatelessWidget {
const ProfileCard({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
child: Column(
children: [
Oneh(),
const CircleAvatar(radius: 40),
Oneh(),
const Text('John Doe', style: TextStyle(fontSize: 24)),
Halfh(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.location_on),
Onew(),
const Text('New York, USA'),
],
),
Twoh(),
],
),
);
}
}
ð License
This project is licensed under the MIT License - see the LICENSE file for details.
ð Show your support
Give a âïļ if this project helped you!