fl_sdp 0.0.1
fl_sdp: ^0.0.1 copied to clipboard
A Flutter package to easily scale dimensions and fonts based on screen size, providing a responsive UI design.
fl_sdp #
fl_sdp is a Flutter package for managing scalable dimensions (SDP), fonts, and utilities like padding and margin. It ensures consistent UI appearance across devices with varying screen sizes and resolutions.
Features #
- Responsive Dimensions: Scale dimensions (sdp) proportionally to the screen size.
- Font Scaling: Adjust text sizes dynamically using (fontSdp).
- Advanced Padding and Margin Utilities:
- Simplified all, horizontal, and vertical configuration.
- Fine-grained control with left, top, right, and bottom.
- Global Initialization: Initialize once and use throughout the app.
Installation #
Add the package to your pubspec.yaml file:
dependencies:
fl_sdp: ^0.0.1
Install the package: #
flutter pub get
I'll create a README.md file for the fl_sdp package using Markdown format. Here's the content:
# fl_sdp
fl_sdp is a Flutter package for managing scalable dimensions (SDP), fonts, and utilities like padding and margin. It ensures consistent UI appearance across devices with varying screen sizes and resolutions.
## Features
- **Responsive Dimensions**: Scale dimensions (sdp) proportionally to the screen size.
- **Font Scaling**: Adjust text sizes dynamically using (fontSdp).
- **Advanced Padding and Margin Utilities**:
- Simplified all, horizontal, and vertical configuration.
- Fine-grained control with left, top, right, and bottom.
- **Global Initialization**: Initialize once and use throughout the app.
## Installation
Add the package to your `pubspec.yaml` file:
```yaml
dependencies:
fl_sdp: ^0.0.1
Install the package:
flutter pub get
Usage #
1. Initialize SDP #
Initialize fl_sdp once in your main.dart file:
import 'package:flutter/material.dart';
import 'package:fl_sdp/sdp.dart'; // Import the package
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static final GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
// Initialize SDP using the app's root context
SDP.init(navigatorKey.currentContext!);
});
return MaterialApp(
navigatorKey: navigatorKey, // Set the global navigator key
home: HomeScreen(),
);
}
}
2. Use SDP in Widgets #
After initialization, you can use the following features across your app:
2.1 Scalable Dimensions
Scale any dimension using SDP.sdp():
Container(
width: SDP.sdp(150),
height: SDP.sdp(100),
color: Colors.blue,
);
2.2 Scalable Fonts
Adjust font sizes dynamically with SDP.fontSdp():
Text(
"Responsive Font",
style: TextStyle(fontSize: SDP.fontSdp(16)),
);
2.3 Padding and Margins
Simplify padding and margin configuration with utilities:
Container(
padding: SDP.padding(all: 16), // Uniform padding
margin: SDP.margin(horizontal: 16, vertical: 8), // Symmetric margin
color: Colors.green,
);
For more control:
SDP.padding(left: 16, top: 8, right: 16, bottom: 8);
Example #
Here's a complete example of how to use fl_sdp in your app:
import 'package:flutter/material.dart';
import 'package:fl_sdp/sdp.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static final GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
SDP.init(navigatorKey.currentContext!);
});
return MaterialApp(
navigatorKey: navigatorKey,
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("SDP Example")),
body: Center(
child: Container(
padding: SDP.padding(all: 16),
margin: SDP.margin(horizontal: 16, vertical: 8),
width: SDP.sdp(150),
height: SDP.sdp(100),
color: Colors.blue,
child: Text(
"Responsive UI",
style: TextStyle(fontSize: SDP.fontSdp(16), color: Colors.white),
),
),
),
);
}
}
API Reference #
-
Scalable Dimensions
-
SDP.sdp(double dp): Scales the provided dimension proportionally to the screen width.(Use for basic ui and font both) -
Scalable Fonts
-
SDP.fontSdp(double fontSize): Scales text size based on screen width. -
Padding Utilities
-
SDP.padding({double all, double horizontal, double vertical, double left, double top, double right, double bottom}): Simplifies the creation of responsive padding. -
Margin Utilities
-
SDP.margin({double all, double horizontal, double vertical, double left, double top, double right, double bottom}): Simplifies the creation of responsive margins.
Why Use fl_sdp? #
- Consistency: Maintain a uniform UI across devices of varying screen sizes and resolutions.
- Ease of Use: Initialize once globally and use throughout your app.
- Flexibility: Customize scaling with predefined methods and utilities.
- Time-Saving: Reduces boilerplate code for managing responsive layouts.
Contributions #
Contributions are welcome! If you have ideas for improvements or additional features, feel free to open a pull request or file an issue.
License #
fl_sdp is licensed under the MIT License. See the LICENSE file for details.