floating_logger 0.0.2
floating_logger: ^0.0.2 copied to clipboard
floating_logger is a Flutter library that provides a floating widget for real-time API request logs.
floating_logger π #
floating_logger
is a Flutter library designed to help developers debug and test API calls with ease. It provides a floating widget that allows you to monitor API requests in real-time and even copy the curl command for quick testing. Perfect for anyone who wants to streamline the development and debugging process! β‘
π Features #
- π¨ Beautify Debugger Console - Improved readability for logs
- π Beautify JSON Response Item - Better JSON formatting
- π Copy cURL (Long Tap) - Easily copy API requests
- π Floating Button (Flexible Logger) - Moveable debugging widget
- π Preferences for Global Hide/Show - Toggle visibility globally
- π§ Custom Item List - Customize how log items are displayed
Installation π§ #
To get started, add floating_logger
to your pubspec.yaml
:
dependencies:
floating_logger: ^latest_version
package import :
import 'package:floating_logger/floating_logger.dart';
Demo π₯ #
Preview Debug #
Here is the preview of the debug console log for the HTTP request:
Above: Example of the HTTP request.
Middle: HTTP response log.
Below: HTTP error log.
π Usage #
π Wrapping Your App with FloatingLoggerControl
#
To activate the floating logger, wrap your main widget inside FloatingLoggerControl
.
return FloatingLoggerControl(
child: Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text("Floating Logger Test"),
),
),
);
π Logging API Calls with DioLogger
#
Replace your Dio
instance with DioLogger
to ensure API logs appear in the floating logger.
Future<void> fetchData() async {
try {
final response = await DioLogger.instance.get(
'https://api.genderize.io',
queryParameters: { "name": "james" },
);
if (response.statusCode == 200) {
// Handle API response
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('API request failed')),
);
}
}
π Toggle Floating Logger Visibility Using Preferences #
Use ValueNotifier
to toggle the logger visibility dynamically. This allows you to enable or disable the logger and persist the setting across app sessions.
π Define the Visibility Notifier #
final ValueNotifier<bool> isLoggerVisible = ValueNotifier<bool>(true);
@override
void initState() {
loadLoggerSettings();
super.initState();
}
Future<void> loadLoggerSettings() async {
try {
bool pref = await getStoredPreference();
setState(() {
isLoggerVisible.value = pref;
});
} catch (e) {
print(e);
}
}
Future<bool> getStoredPreference() async {
return await CustomSharedPreferences.getDebugger();
}
π Apply Preferences in FloatingLoggerControl
#
return FloatingLoggerControl(
getPreference: getStoredPreference,
isShow: isLoggerVisible,
child: Scaffold(
appBar: AppBar(title: Text("Logger Toggle Test")),
body: Switch(
activeTrackColor: Colors.blue,
value: isLoggerVisible.value,
onChanged: (value) {
setState(() {
isLoggerVisible.value = value;
CustomSharedPreferences.saveDebugger(value);
});
},
),
),
);
π¨ Customizing Floating Logger UI #
You can modify the floating loggerβs UI using widgetItemBuilder
to create a custom log display format.
return FloatingLoggerControl(
widgetItemBuilder: (index, data) {
final item = data[index];
return Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Card(
child: ListTile(
title: Text('${item.type!} [${item.response}]', style: TextStyle(fontSize: 12.0)),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("URL : ${item.path}", style: TextStyle(fontSize: 12.0)),
Text("Data : ${item.data}", style: TextStyle(fontSize: 12.0)),
Text("cURL : ${item.curl}", style: TextStyle(fontSize: 12.0)),
],
),
),
),
);
},
child: child,
);
π― Conclusion #
floating_logger
is a powerful tool that simplifies debugging API calls in Flutter applications. Whether you need to inspect responses, copy cURL commands, or customize the UI, this package provides a seamless experience for developers. Integrate it today and streamline your debugging process! π
π For more details, visit the GitHub Repository.