Like class

Like

The Master Coordinator & Root Wrapper Widget that powers the entire LIKE network engine.

Why is the Like widget necessary?

In a standard Flutter application, bootstrapping offline storage, network reachability observers, auth interceptors, and contextless popup notifications involves a massive amount of scattered, fragile boilerplate code.

The Like widget unifies all of this under a single declarative root wrapper:

  1. Bootstrap Coordinator: Automatically initializes offline cache (Hive), encryption systems, and client network pipelines asynchronously before letting the app render.
  2. Network Connection Tracker: Dynamically observes real-time internet connectivity, showing interactive online/offline warning toasts automatically.
  3. Authentication Hub: Handles secure header JWT token injection, automatic silent 401 token refresh replays, and force logouts.
  4. Progress Sync Overlay: Renders a gorgeous full-screen modal blocking user interactions while important offline tasks are actively syncing to the server on recovery.
  5. Contextless Toasts Provider: Configures overlays so notifications can be shown from any file (even in raw background services) without needing a BuildContext reference.

Where to Place It:

Always wrap your primary MaterialApp with the Like widget inside main.dart:

void main() {
  runApp(
    Like(
      getToken: () async => secureStorage.read('jwt'),
      refreshToken: () async => api.refreshToken(),
      child: const MyApp(),
    ),
  );
}
Inheritance

Constructors

Like({Key? key, required Widget child, ValueNotifier<bool>? isSyncing, Widget? syncOverlay, Widget? loadingWidget, bool showConnectivityToasts = true, Future<String?> getToken()?, Future<String?> refreshToken()?, Future<void> onLogout({bool force, int? statusCode})?, Future<String?> getApiKey()?, Widget syncProgressBuilder(String title, String message, double progress)?, LikeToastConfig? toastConfig, LikeToastDelegate? toastDelegate, Widget devTool(Widget child)?})
const

Properties

child Widget
The main application widget tree (typically your MaterialApp).
final
devTool Widget Function(Widget child)?
Optional debug-only wrapper used to inject developer dashboards or HUD overlays.
final
getApiKey Future<String?> Function()?
A secure callback that retrieves the server API key to append to headers or query parameters.
final
getToken Future<String?> Function()?
A secure callback function that retrieves the current user's JWT/session token.
final
hashCode int
The hash code for this object.
no setterinherited
isSyncing ValueNotifier<bool>?
A custom ValueNotifier used to programmatically trigger or listen to the global syncing overlay.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingWidget Widget?
A custom loading screen displayed while the LIKE engine initializes Hive database files, loads encryption keys, and checks initial internet connectivity.
final
onLogout Future<void> Function({bool force, int? statusCode})?
A callback triggered when a session is unrecoverable (e.g. token refresh fails).
final
refreshToken Future<String?> Function()?
A secure callback function that performs token refreshing when the backend reports an expired token (401 Unauthorized).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showConnectivityToasts bool
Whether to automatically show gorgeous animated popup alerts whenever internet connection drops or restores.
final
syncOverlay Widget?
The custom widget overlay shown when the app is performing background data synchronization (isSyncing is true).
final
syncProgressBuilder Widget Function(String title, String message, double progress)?
A custom builder to customize the appearance of the background synchronization progress toast.
final
toastConfig LikeToastConfig?
Custom design configuration for the network-related toasts.
final
toastDelegate LikeToastDelegate?
A delegate that controls exactly how toasts are triggered, designed, and presented throughout the app lifecycle. Takes precedence over custom configuration widgets if provided.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<Like>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

A global navigator key that can be linked to your MaterialApp.navigatorKey.
no setter

Static Methods

help() → void
Prints a beautiful quickstart and help cheatsheet listing all widgets, methods, classes, and mixins of the LIKE package in the terminal, complete with colored headings and copy-pasteable snippets.
printRandomSuggestion() → void
Prints a random, bite-sized tip or code snippet in the developer terminal.