sz_core 1.0.4
sz_core: ^1.0.4 copied to clipboard
SZ Core Package
SZ Core #
A lightweight Flutter package that provides reusable widgets, responsive sizing, utility methods, dialogs, navigation helpers, and a simple API caller to speed up Flutter application development.
Features #
- ✅ Responsive UI scaling (
.w,.h,.r,.sp) - ✅ Base Activity & Fragment architecture
- ✅ Built-in API caller (GET & POST)
- ✅ Toasts, dialogs & pickers
- ✅ Navigation helper
- ✅ Phone, Website & WhatsApp launcher
- ✅ Keyboard helper
- ✅ Date & Time formatting
- ✅ Random Dark Color generator
- ✅ Hex Color extension
Included Classes #
SZCoreSZActivitySZFragmentSZApiCallerSZApiSettingSZShowSZTextSZButtonSZIconButtonSZTextField
Installation #
Add the package to your pubspec.yaml.
dependencies:
sz_core: ^1.0.0
Then run
flutter pub get
Import #
import 'package:sz_core/sz_core.dart';
Initialization #
Initialize SZCore before runApp().
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SZCore.init();
runApp(const MyApp());
}
With Base URL #
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SZCore.init(
baseURL: "https://example.com/api/",
);
runApp(const MyApp());
}
Custom API Settings #
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SZApiSetting.init(
"https://example.com/api/",
keyStatus: "status",
keyMessage: "message",
keyData: "data",
keyInternet: "internet",
defaultHeader: {
"Authorization": "Bearer TOKEN"
}
);
await SZCore.init();
runApp(const MyApp());
}
You can update custom setting directly from anywhere like
SZApiSetting.defaultHeader = {
"Authorization": "Bearer UPDATED TOKEN"
};
Responsive Size #
SZCore.init() automatically calculates the screen scale.
Use the extensions anywhere.
Container(
width: 120.w,
height: 60.h,
padding: EdgeInsets.all(12.r),
child: SZText(
"Hello",
fontSize: 16.sp,
),
)
| Extension | Description |
|---|---|
.w |
Width scaling |
.h |
Height scaling |
.r |
Radius scaling |
.sp |
Responsive font size |
SZActivity #
Replace State with SZActivity.
Replace build() with buildContent().
class HomeActivity extends StatefulWidget {
const HomeActivity({super.key});
@override
State<HomeActivity> createState() => _HomeActivityState();
}
class _HomeActivityState extends SZActivity<HomeActivity> {
@override
Widget buildContent(BuildContext context) {
return const SizedBox();
}
}
Available Methods #
showDialog("Loading...");
hideDialog();
open(const SecondActivity());
onResume();
onPaused();
SZFragment #
Replace State with SZFragment.
Replace build() with buildContent().
class HomeFragment extends StatefulWidget {
const HomeFragment({super.key});
@override
State<HomeFragment> createState() => _HomeFragmentState();
}
class _HomeFragmentState extends SZFragment<HomeFragment> {
@override
Widget buildContent(BuildContext context) {
return const SizedBox();
}
}
Available Methods #
showDialog("Loading...");
hideDialog();
open(const SecondActivity());
onResume();
onPaused();
SZCore #
Open Activity #
await SZCore.open(
context,
const HomeActivity(),
);
Hide Keyboard #
SZCore.hideKeyboard(context);
Screen Size #
final size = await SZCore.getScreenSize();
print(size.width);
print(size.height);
Date Formatting #
Server format
SZCore.formattedDate(DateTime.now());
Output
2026-07-07
Display format
SZCore.formattedDate(
DateTime.now(),
server: false,
);
Output
7 Jul 2026
Time Formatting #
Server
SZCore.formattedTime(DateTime.now());
Output
14:30
Display
SZCore.formattedTime(
DateTime.now(),
server: false,
);
Output
2:30 PM
Random Dark Color #
Color color = SZCore.getRandomDarkColor();
Debug Log #
SZCore.printLog("Hello");
Prints only in Debug mode.
Open Phone Dialer #
SZCore.openCall("9876543210");
Open Website #
SZCore.openWebsite(
"https://flutter.dev",
);
Open WhatsApp #
SZCore.openWhatsApp(
"919876543210",
message: "Hello",
);
Hex Color Extension #
Color color = "#2196F3".toColor();
SZShow #
Toast #
SZShow.toast("Saved Successfully");
Custom
SZShow.toast(
"Error",
bg: Colors.red,
color: Colors.white,
size: 14,
);
Dialog #
SZShow.dialog(
context,
"Success",
"Data Saved Successfully",
);
Two Buttons
SZShow.dialog(
context,
"Delete",
"Delete this record?",
btn1: "Yes",
btn2: "No",
b1Click: () {
},
b2Click: () {
},
);
Custom Widget
SZShow.dialog(
context,
"",
"",
buildContent: (setState) {
return const Text("Custom Widget");
},
);
Date Picker #
SPair date = await SZShow.dateSelect(
context,
null,
);
Time Picker #
SPair time = await SZShow.timeSelect(
context,
null,
);
Year Picker #
int year = await SZShow.yearSelect(
context,
2025,
);
SZApiCaller #
Supports both GET and POST requests.
GET Request #
SZApiCaller(
context,
this,
1,
null,
"Loading...",
"users",
).then((response, key) {
});
POST Request #
SZApiCaller(
context,
this,
2,
jsonEncode(data),
"Please wait...",
"login",
).then((response, key) {
});
PUT,PATCH,DELETE Request #
You can use below enum
enum SZMethod { get, post, delete, put, patch }
SZApiCaller(
context,
this,
2,
jsonEncode(data),
"Please wait...",
"login",
method = SZMethod.put
).then((response, key) {
});
Custom Header #
SZApiCaller(
context,
this,
1,
null,
null,
"users",
customHeader: {
"Authorization": "Bearer TOKEN"
},
).then((response, key) {
});
Logout Callback #
SZCore.logoutCallback = () {
// Navigate to Login Screen
};
If the API response contains "session expire", the callback is automatically invoked.
Requirements #
- Flutter SDK >= 3.0.0
Contributing #
Contributions, issues, and feature requests are welcome.
License #
This project is licensed under the MIT License. See the LICENSE file for details.