main_widgets 0.0.2 main_widgets: ^0.0.2 copied to clipboard
A Flutter package for efficient UI state management, handling loading, empty views, content display, caching, and pull-to-refresh with customizable widgets.
SmartUIComponents Widget #
The SmartUIComponents
A Flutter package for efficient UI state management, handling loading, empty views, content display, caching, and pull-to-refresh with customizable widgets.
Table of Contents #
Features #
- Displays loading indicator when data is being fetched.
- Shows a custom or default empty screen when there is no data.
- Wraps the main content in a pull-to-refresh functionality.
Installation #
To use the MainScreen
widget in your Flutter project, follow these steps:
- Add the following to your
pubspec.yaml
:
dependencies:
main_widgets: <latest_version>
Usage #
You can use the MainScreen
widget as follows:
MainScreen(
isLoading: true, // Set to true while data is being loaded
isEmpty: false, // Set to true if there is no data to display
child: YourMainContentWidget(), // The main content to display
onRefresh: () async {
// Add your refresh logic here
},
);
Widgets Usage #
Here is an example demonstrating how to use these parameters in the MainScreen
widget:
SmartScreen #
Example Code
SmartScreen(
isLoading: true, // Data is being loaded
isEmpty: false, // Data is available
child: YourMainContentWidget(), // Main content to display
onRefresh: () async {
// Logic for refreshing data
},
emptyWidget: CustomEmptyWidget(message: "No data available"), // Optional empty widget
message: "Please check back later.", // Optional message for empty state
);
EmptyWidget #
Example Code
EmptyWidget(
message: 'The message of EmptyWidget',
),
SmartLoadingWidget #
Example Code
const SmartLoadingWidget(),
SmartLoadingWidget(
path: 'assets/animation.gif',
loadingType: LoadingType.gif,
),
const SmartLoadingWidget(
path: 'assets/animation1.json',
loadingType: LoadingType.lottie,
),
ShowToast #
Example Code
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return StyledToast(
backgroundColor: Colors.red,
textStyle: const TextStyle(
color: Colors.black,
fontSize: 16,
),
locale: const Locale('en', 'US'),
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: false,
),
home: const MyHomePage(),
),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('home'),
),
body: Column(
children: [
TextButton(
onPressed: () => showToastError(msg: 'show Toast Error'),
child: const Text('show Toast Error'),
),
TextButton(
onPressed: () => showToastSuccess(msg: 'show Toast Success'),
child: const Text('Show Toast Success'),
),
],
),
);
}
}
Contributions #
Feel free to contribute to this project.
If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.
Made with contrib.rocks.