### Installation Bundle Configuration Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Configures the installation process to create a relocatable bundle. It ensures a clean bundle directory on each install and sets up destinations for data and libraries. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Installs the Flutter assets directory, ensuring it's copied fresh on each build to avoid stale files. The assets are placed in the data directory of the installation bundle. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installation Configuration for Runtime Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Configures installation rules for the application executable, ICU data, Flutter library, and bundled plugin libraries. It ensures files are placed correctly for runtime execution. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Application Target and Data Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Installs the main application executable to the bundle's root and copies ICU data files to the data directory. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Library and Bundled Libraries Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Installs the main Flutter library and any bundled plugin libraries to the bundle's library directory. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Sets up the minimum CMake version, project name, executable name, and application ID. It also enforces modern CMake behaviors and configures the installation RPATH. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "fluttertoast_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.example.fluttertoast_example") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Install AOT Library Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the bundle's library directory, but only for non-Debug build configurations. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Project and CMake Version Setup Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Sets the minimum required CMake version and project name. It's good practice to explicitly opt into modern CMake behaviors. ```cmake cmake_minimum_required(VERSION 3.14) project(fluttertoast_example LANGUAGES CXX) set(BINARY_NAME "fluttertoast_example") cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Install Native Assets Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Installs native assets provided by build.dart from all packages into the application bundle's library directory. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library for Profile and Release builds, typically placed in the data directory. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Ensures Flutter assets are copied correctly by first removing any existing assets and then copying the new ones from the build directory to the bundle's data directory. ```cmake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Copies native assets provided by build.dart from all packages into the bundle's library directory. ```cmake # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Configure Flutter library and headers Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/flutter/CMakeLists.txt Defines the Flutter library path and headers, setting them to be available in the parent scope for installation steps. It also sets the project build directory and AOT library path. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### FToastBuilder() Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt A `TransitionBuilder` factory function that injects the required `Overlay` into the widget tree by wrapping `MaterialApp`'s `builder`. This is essential for `FToast` to display overlay toasts and must be called at app setup. ```APIDOC ## FToastBuilder() ### Description A `TransitionBuilder` factory function that injects the required `Overlay` into the widget tree by wrapping `MaterialApp`'s `builder`. Must be called at app setup before `FToast` can display overlay toasts. Also accepts an optional `navigatorKey` for accessing context globally. ### Method `FToastBuilder()` ### Parameters - **navigatorKey** (GlobalKey) - Optional - A global key for accessing the navigator state, allowing for context-free `FToast` usage. ### Request Example ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; // Define a global navigator key for context-independent access GlobalKey navigatorKey = GlobalKey(); void main() { runApp( MaterialApp( title: 'My App', builder: FToastBuilder(), // Required: injects Overlay for FToast navigatorKey: navigatorKey, // Optional: allows context-free FToast usage home: MyHomePage(), ), ); } ``` ### Response This is a builder function and does not return a direct response in the traditional sense. Its effect is to enable `FToast` functionality within the application. ``` -------------------------------- ### FToast.init() Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Initializes the FToast singleton with a BuildContext. This must be called before any showToast calls. It allows subsequent toasts to know which widget tree to overlay on. It can also be initialized globally using a navigatorKey. ```APIDOC ## `FToast.init()` — Initialize FToast with a BuildContext Stores a `BuildContext` in the `FToast` singleton so subsequent `showToast` calls know which widget tree to overlay on. Must be called before any `showToast` call. Returns the `FToast` instance for chaining. Use `navigatorKey.currentContext!` for global (context-independent) initialization. ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; class MyWidget extends StatefulWidget { @override _MyWidgetState createState() => _MyWidgetState(); } class _MyWidgetState extends State { late FToast fToast; @override void initState() { super.initState(); fToast = FToast(); fToast.init(context); // Initialize with local context // OR: fToast.init(navigatorKey.currentContext!); // global context } @override Widget build(BuildContext context) => Container(); } ``` ``` -------------------------------- ### Initialize FToast with BuildContext Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Must be called before any showToast call. Stores a BuildContext in the FToast singleton. Use navigatorKey.currentContext! for global initialization. ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; class MyWidget extends StatefulWidget { @override _MyWidgetState createState() => _MyWidgetState(); } class _MyWidgetState extends State { late FToast fToast; @override void initState() { super.initState(); fToast = FToast(); fToast.init(context); // Initialize with local context // OR: fToast.init(navigatorKey.currentContext!); // global context } @override Widget build(BuildContext context) => Container(); } ``` -------------------------------- ### Add Dependency Libraries and Include Directories Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and adds the source directory to include paths. Add any other application-specific dependencies here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) ``` ```cmake target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Find and check PkgConfig modules for GTK, GLIB, and GIO Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/flutter/CMakeLists.txt This section uses PkgConfig to find and check for the required GTK, GLIB, and GIO libraries. These are system-level dependencies for Flutter on Linux. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the application target. This can be removed if the application requires custom build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Show Toast (No BuildContext) Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Displays a toast message with customizable properties. This method is suitable for platforms like Android and iOS and has limited UI control. ```APIDOC ## Fluttertoast.showToast ### Description Displays a toast message with customizable properties. This method is suitable for platforms like Android and iOS and has limited UI control. ### Method `Fluttertoast.showToast()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **msg** (String) - Required - The message to display in the toast. - **toastLength** (Toast.LENGTH_SHORT or Toast.LENGTH_LONG) - Optional - The duration for which the toast should be visible. Defaults to `Toast.LENGTH_SHORT`. - **gravity** (ToastGravity.TOP, ToastGravity.CENTER, or ToastGravity.BOTTOM) - Optional - The position of the toast on the screen. For Web, only `TOP` and `BOTTOM` are supported. Defaults to `ToastGravity.BOTTOM`. - **timeInSecForIosWeb** (int) - Optional - The time in seconds for the toast to be visible on iOS and Web. Defaults to `1`. - **backgroundColor** (Color) - Optional - The background color of the toast. Defaults to `null`. - **textColor** (Color) - Optional - The text color of the toast. Defaults to `null`. - **fontSize** (double) - Optional - The font size of the toast message. Defaults to `null`. - **fontAsset** (String) - Optional - Path to a font file in the Flutter app assets folder. Defaults to `null`. - **webShowClose** (bool) - Optional - Whether to show a close button on the web toast. Defaults to `false`. - **webBgColor** (String) - Optional - The background color of the web toast in hex format. Defaults to `linear-gradient(to right, #00b09b, #96c93d)`. - **webPosition** (String) - Optional - The position of the web toast (`left`, `center`, or `right`). Defaults to `right`. ### Request Example ```dart Fluttertoast.showToast( msg: "This is Center Short Toast", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: Colors.red, textColor: Colors.white, fontSize: 16.0 ); ``` ### Response #### Success Response (200) No specific response body is defined for success, the toast is displayed on the UI. #### Response Example None ``` -------------------------------- ### Initialize MaterialApp with FToastBuilder Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Update your MaterialApp with the FToastBuilder to enable global context for toasts. Ensure navigatorKey is also set. ```dart MaterialApp( builder: FToastBuilder(), home: MyApp(), navigatorKey: navigatorKey, ) ``` -------------------------------- ### Flutter and System Dependencies Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Includes the Flutter subdirectory and finds necessary system libraries using PkgConfig, specifically gtk+-3.0. ```cmake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Include Generated Plugins Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Includes the CMake script that manages the building and integration of generated plugins into the application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Custom command to build Flutter library and headers Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/flutter/CMakeLists.txt This custom command uses the Flutter tool backend script to generate the Flutter library and its headers. It's designed to run every time by using a phony output file, as direct input/output tracking is not available. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Initialize FToast with Global NavigatorKey Context Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md When initializing FToast, use the context from the globally defined navigatorKey to ensure it can be accessed from anywhere. ```dart FToast fToast = FToast(); fToast.init(yourNavKey.currentContext!); ``` -------------------------------- ### Unicode and Standard Compilation Settings Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Enables Unicode support and applies standard compilation features and options like C++17, warning levels, and exception handling. ```cmake add_definitions(-DUNICODE -D_UNICODE) function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Show a web-specific styled native toast Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Customize native toasts on the web using `webBgColor`, `webPosition`, and `webShowClose` parameters. These are web-only options. ```dart await Fluttertoast.showToast( msg: "Upload complete!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.TOP, timeInSecForIosWeb: 3, webBgColor: "#2ecc71", // Hex color string (web only) webPosition: "right", // "left", "center", "right" (web only) webShowClose: true, // Show a close button (web only) ); ``` -------------------------------- ### Wire FToast into MaterialApp using FToastBuilder Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Use `FToastBuilder()` as the `builder` for your `MaterialApp` to inject the necessary `Overlay` for `FToast` to function. An optional `navigatorKey` can be provided for context-independent access. ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; // Define a global navigator key for context-independent access GlobalKey navigatorKey = GlobalKey(); void main() { runApp( MaterialApp( title: 'My App', builder: FToastBuilder(), // Required: injects Overlay for FToast navigatorKey: navigatorKey, // Optional: allows context-free FToast usage home: MyHomePage(), ), ); } ``` -------------------------------- ### Profile Build Mode Settings Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Defines linker and compiler flags for the Profile build mode, typically mirroring Release settings for performance consistency. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Executable Output Directory Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Sets the runtime output directory for the main executable to a subdirectory to prevent accidental execution of unbundled copies. ```cmake # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Add Flutter library headers and link dependencies Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/flutter/CMakeLists.txt Appends Flutter library headers to a list and then uses the custom `list_prepend` function to add a prefix. An interface library `flutter` is created and configured with include directories and link libraries. ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Define Executable Target Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/runner/CMakeLists.txt Defines the main executable for the Windows application. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` to function correctly. Add any new source files for the application here. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### FToast.showToast() Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Displays a fully custom Widget toast. This method queues and displays any Flutter Widget as an overlay toast. It supports precise positioning via ToastGravity or a custom positionedToastBuilder callback. Toasts are shown sequentially, and gravity automatically adjusts when the software keyboard is visible. ```APIDOC ## `FToast.showToast()` — Display a fully custom Widget toast Queues and displays any Flutter `Widget` as an overlay toast. Supports precise positioning via `ToastGravity` or a fully custom `positionedToastBuilder` callback. Multiple calls are enqueued and shown sequentially. Automatically adjusts gravity from BOTTOM to CENTER when the software keyboard is visible. ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; late FToast fToast; // initialized in initState() // Basic custom toast void showSuccessToast() { Widget toast = Container( padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(25.0), color: Colors.greenAccent, ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.check, color: Colors.white), SizedBox(width: 12.0), Text("Saved!", style: TextStyle(color: Colors.white)), ], ), ); fToast.showToast( child: toast, gravity: ToastGravity.BOTTOM, toastDuration: Duration(seconds: 3), fadeDuration: Duration(milliseconds: 500), // Fade in/out duration ignorePointer: false, // Allow touch-through isDismissible: true, // Tap to dismiss ); } // Toast with fully custom pixel-precise position void showCustomPositionedToast() { Widget toast = Container( padding: EdgeInsets.all(12), color: Colors.blue, child: Text("Top-left toast!", style: TextStyle(color: Colors.white)), ); fToast.showToast( child: toast, toastDuration: Duration(seconds: 2), positionedToastBuilder: (context, child, gravity) { return Positioned( top: 60.0, left: 16.0, child: child, ); }, ); } // Queue multiple toasts — shown one after another void queueToasts() { for (final label in ["First", "Second", "Third"]) { fToast.showToast( child: Container( padding: EdgeInsets.all(12), color: Colors.orange, child: Text(label), ), gravity: ToastGravity.TOP, toastDuration: Duration(seconds: 2), ); } } ``` ``` -------------------------------- ### Initialize and Show Custom Toast Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Initialize FToast in your stateful widget and define a function to show custom toast messages with various configurations like gravity and duration. ```dart FToast fToast; @override void initState() { super.initState(); fToast = FToast(); // if you want to use context from globally instead of content we need to pass navigatorKey.currentContext! fToast.init(context); } _showToast() { Widget toast = Container( padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(25.0), color: Colors.greenAccent, ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.check), SizedBox( width: 12.0, ), Text("This is a Custom Toast"), ], ), ); fToast.showToast( child: toast, gravity: ToastGravity.BOTTOM, toastDuration: Duration(seconds: 2), ); // Custom Toast Position fToast.showToast( child: toast, toastDuration: Duration(seconds: 2), positionedToastBuilder: (context, child) { return Positioned( child: child, top: 16.0, left: 16.0, ); }); } ``` -------------------------------- ### Display a Fully Custom Widget Toast Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Queues and displays any Flutter Widget as an overlay toast. Supports precise positioning and automatically adjusts gravity when the software keyboard is visible. Multiple calls are enqueued and shown sequentially. ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; late FToast fToast; // initialized in initState() // Basic custom toast void showSuccessToast() { Widget toast = Container( padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(25.0), color: Colors.greenAccent, ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.check, color: Colors.white), SizedBox(width: 12.0), Text("Saved!", style: TextStyle(color: Colors.white)), ], ), ); fToast.showToast( child: toast, gravity: ToastGravity.BOTTOM, toastDuration: Duration(seconds: 3), fadeDuration: Duration(milliseconds: 500), // Fade in/out duration ignorePointer: false, // Allow touch-through isDismissible: true, // Tap to dismiss ); } ``` ```dart // Toast with fully custom pixel-precise position void showCustomPositionedToast() { Widget toast = Container( padding: EdgeInsets.all(12), color: Colors.blue, child: Text("Top-left toast!", style: TextStyle(color: Colors.white)), ); fToast.showToast( child: toast, toastDuration: Duration(seconds: 2), positionedToastBuilder: (context, child, gravity) { return Positioned( top: 60.0, left: 16.0, child: child, ); }, ); } ``` ```dart // Queue multiple toasts — shown one after another void queueToasts() { for (final label in ["First", "Second", "Third"]) { fToast.showToast( child: Container( padding: EdgeInsets.all(12), color: Colors.orange, child: Text(label), ), gravity: ToastGravity.TOP, toastDuration: Duration(seconds: 2), ); } } ``` -------------------------------- ### Define list_prepend function for CMake < 3.10 Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a list. It is a workaround for versions of CMake older than 3.10, which do not support the list(TRANSFORM ... PREPEND ...) command. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Build Type Configuration Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already defined, and restricts it to 'Debug', 'Profile', or 'Release'. ```cmake # Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Add Build Version Preprocessor Definitions Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/runner/CMakeLists.txt Adds preprocessor definitions for the build version, including major, minor, patch, and build numbers. These are useful for embedding version information into the application. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Cross-Building Configuration Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Configures CMake for cross-building by setting the sysroot and adjusting find root path modes when FLUTTER_TARGET_PLATFORM_SYSROOT is defined. ```cmake # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Import Fluttertoast Package Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Import the fluttertoast package into your Dart file to use its functionalities. ```dart import 'package:fluttertoast/fluttertoast.dart'; ``` -------------------------------- ### Runner Subdirectory and Dependencies Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Includes the runner subdirectory for application build rules and adds a dependency on the flutter_assemble target for the main binary. ```cmake # Application build; see runner/CMakeLists.txt. add_subdirectory("runner") # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Show a basic native platform toast Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Use `Fluttertoast.showToast()` to display a simple native toast message. All parameters except `msg` are optional. Note that on Android 11+, styling properties are ignored. ```dart await Fluttertoast.showToast( msg: "File saved successfully", toastLength: Toast.LENGTH_SHORT, // Toast.LENGTH_SHORT (1s) or Toast.LENGTH_LONG (5s) gravity: ToastGravity.BOTTOM, // TOP, CENTER, BOTTOM timeInSecForIosWeb: 2, // Display duration on iOS and web backgroundColor: Colors.black87, textColor: Colors.white, fontSize: 16.0, ); ``` -------------------------------- ### Show Toast with No BuildContext (Android & iOS) Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Display a toast message without requiring a BuildContext. This method has limited features and UI control. Note that custom toast styling is ignored on Android 11+. ```dart Fluttertoast.showToast( msg: "This is Center Short Toast", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, backgroundColor: Colors.red, textColor: Colors.white, fontSize: 16.0 ); ``` -------------------------------- ### Subdirectory Inclusion for Flutter and Runner Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Includes the Flutter managed directory and the application runner subdirectory, essential for building the Flutter application. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) add_subdirectory("runner") ``` -------------------------------- ### Add fluttertoast Dependency Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Add this line to your pubspec.yaml file to include the fluttertoast package in your project. ```yaml fluttertoast: ^9.0.0 ``` -------------------------------- ### Build Configuration for Multi-Config Generators Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/CMakeLists.txt Configures the CMAKE_CONFIGURATION_TYPES for multi-config generators like Visual Studio. This ensures Debug, Profile, and Release build modes are available. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Custom Toast Layout for Android Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Define a custom layout for toasts in Android by creating a `toast_custom.xml` file in your `app/res/layout` directory. This allows for custom styling. ```xml ``` -------------------------------- ### Standard Compilation Settings Function Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/linux/CMakeLists.txt Defines a function to apply standard compilation settings like C++ standard, warning options, optimization levels, and debug definitions to a target. ```cmake # Compilation settings that should be applied to most targets. # # Be cautious about adding new options here, as plugins use this function by # default. In most cases, you should add new options to specific targets instead # of modifying this function. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Add Flutter Assemble Dependency Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/example/windows/runner/CMakeLists.txt Ensures that the Flutter tool's assembly process is completed before the application target is built. This is a required step for Flutter builds. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Fluttertoast.showToast() Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Displays a native toast message using the platform's own toast mechanism. Supports various customization options for text, color, gravity, and duration. Note that on Android 11+, only `msg` and `toastLength` are respected. ```APIDOC ## Fluttertoast.showToast() ### Description Displays a native toast message using the platform's own toast mechanism (Android `Toast`, iOS Toast-Swift, or Toastify-JS on web). Requires only the `msg` parameter; all others are optional. Returns `Future` indicating success. On Android 11+, only `msg` and `toastLength` are respected — styling properties are ignored. ### Method `Fluttertoast.showToast()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters (showToast) - **msg** (String) - Required - The message to display in the toast. - **toastLength** (Toast.LENGTH_SHORT or Toast.LENGTH_LONG) - Optional - The duration for which the toast should be visible. - **gravity** (ToastGravity) - Optional - The position of the toast on the screen (e.g., TOP, CENTER, BOTTOM). - **timeInSecForIosWeb** (int) - Optional - Display duration in seconds for iOS and web platforms. - **backgroundColor** (Color) - Optional - Background color of the toast. - **textColor** (Color) - Optional - Text color of the toast. - **fontSize** (double) - Optional - Font size of the toast text. - **fontAsset** (String) - Optional - Path to a custom font asset for the toast text (Android & iOS). - **webBgColor** (String) - Optional - Background color for web toasts in hex format (e.g., "#2ecc71"). - **webPosition** (String) - Optional - Position for web toasts ("left", "center", "right"). - **webShowClose** (bool) - Optional - Whether to show a close button for web toasts. ### Request Example ```dart // Basic toast await Fluttertoast.showToast( msg: "File saved successfully", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 2, backgroundColor: Colors.black87, textColor: Colors.white, fontSize: 16.0, ); // Web-specific styled toast await Fluttertoast.showToast( msg: "Upload complete!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.TOP, timeInSecForIosWeb: 3, webBgColor: "#2ecc71", webPosition: "right", webShowClose: true, ); // Toast with custom font asset (Android & iOS) await Fluttertoast.showToast( msg: "Custom font toast", fontAsset: "assets/fonts/Roboto-Bold.ttf", fontSize: 18.0, backgroundColor: Colors.indigo, textColor: Colors.white, ); ``` ### Response #### Success Response (Future) Returns `true` if the toast was displayed successfully, `false` otherwise, or `null` if the operation was cancelled or not applicable. #### Response Example ```dart // Example of handling the future result bool? success = await Fluttertoast.showToast(...); if (success == true) { print('Toast shown successfully'); } else { print('Failed to show toast or operation cancelled'); } ``` ``` -------------------------------- ### Define Global NavigatorKey Source: https://github.com/ponnamkarthik/fluttertoast/blob/master/README.md Define a GlobalKey for your NavigatorState at the top level of your main.dart file to access the navigator context globally. ```dart GlobalKey navigatorKey = GlobalKey(); ``` -------------------------------- ### Show a native toast with a custom font asset Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Apply a custom font to native toasts on Android and iOS using the `fontAsset` parameter. Ensure the font file is correctly placed in your project's assets. ```dart await Fluttertoast.showToast( msg: "Custom font toast", fontAsset: "assets/fonts/Roboto-Bold.ttf", fontSize: 18.0, backgroundColor: Colors.indigo, textColor: Colors.white, ); ``` -------------------------------- ### ToastGravity Enum Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Defines the possible positions for toasts on the screen. The FToast overlay API supports all listed positions, while the native Fluttertoast API is limited to TOP, CENTER, and BOTTOM. ```APIDOC ## `ToastGravity` — Toast position enum Enum defining all supported screen positions for both `Fluttertoast.showToast()` and `FToast.showToast()`. Note: `Fluttertoast` (native) only supports `TOP`, `CENTER`, and `BOTTOM`; `FToast` supports all values including corner positions, `SNACKBAR` (above keyboard), and `NONE` (full-screen fill). ### Available Values - `ToastGravity.TOP` - `ToastGravity.TOP_LEFT` - `ToastGravity.TOP_RIGHT` - `ToastGravity.CENTER` - `ToastGravity.CENTER_LEFT` - `ToastGravity.CENTER_RIGHT` - `ToastGravity.BOTTOM` (auto-switches to CENTER when keyboard is open) - `ToastGravity.BOTTOM_LEFT` - `ToastGravity.BOTTOM_RIGHT` - `ToastGravity.SNACKBAR` (positioned just above the software keyboard) - `ToastGravity.NONE` (fills the entire screen as an overlay) ### Usage Example ```dart import 'package:fluttertoast/fluttertoast.dart'; // Example using FToast // fToast.showToast( // child: Text("Snackbar-style toast"), // gravity: ToastGravity.SNACKBAR, // Sits just above keyboard when open // toastDuration: Duration(seconds: 3), // ); // Example using Fluttertoast (native) // Fluttertoast.showToast( // msg: "Top toast", // gravity: ToastGravity.TOP, // Native only supports TOP, CENTER, BOTTOM // ); ``` ``` -------------------------------- ### Dismiss the Current Overlay Toast Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Immediately removes the currently visible FToast overlay entry, cancels its timers, and triggers the next toast in the queue. Use inside dismissible toast content (e.g., a close button). ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; late FToast fToast; void showDismissibleToast() { late Widget toast; // Forward reference for the close button callback toast = Container( padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(12.0), color: Colors.redAccent, ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Expanded( child: Text( "Network error. Please retry.", style: TextStyle(color: Colors.white), ), ), IconButton( icon: Icon(Icons.close, color: Colors.white), onPressed: () { fToast.removeCustomToast(); // Dismiss immediately on tap }, ), ], ), ); fToast.showToast( child: toast, gravity: ToastGravity.CENTER, toastDuration: Duration(seconds: 30), // Long duration; user dismisses manually ); } ``` -------------------------------- ### Android Custom Toast Layout (toast_custom.xml) Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt For Android pre-API 30, you can override the native toast appearance by placing a `toast_custom.xml` in `res/layout/`. Note that custom views for toasts are deprecated and ignored on Android 11 (API 30) and above. ```xml ``` -------------------------------- ### FToast.removeQueuedCustomToasts() Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Clears all pending toasts from the queue, removes the current overlay entry, and cancels any active timers. This is useful for cleaning up notifications when navigating away from a screen or when they are no longer relevant. ```APIDOC ## `FToast.removeQueuedCustomToasts()` — Clear the entire toast queue Cancels all timers, removes the current overlay entry, and empties the internal toast queue entirely. Use when navigating away from a screen or when all pending notifications become irrelevant. ### Method ```dart void removeQueuedCustomToasts(); ``` ### Usage Example ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; late FToast fToast; // Clear all toasts on page navigation or logout void onUserLogout() { fToast.removeQueuedCustomToasts(); // Clears current + queued toasts // Navigator.of(context).pushReplacementNamed('/login'); // Example navigation } // Or in a button // ElevatedButton( // onPressed: () { // fToast.removeQueuedCustomToasts(); // print("All toasts cleared"); // }, // child: Text("Clear All Toasts"), // ); ``` ``` -------------------------------- ### Clear Queued Toasts with FToast Source: https://context7.com/ponnamkarthik/fluttertoast/llms.txt Use `removeQueuedCustomToasts()` to clear all pending toasts and dismiss the current overlay. This is useful when navigating away from a screen or when notifications become irrelevant. ```dart import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; late FToast fToast; // Clear all toasts on page navigation or logout void onUserLogout() { fToast.removeQueuedCustomToasts(); // Clears current + queued toasts Navigator.of(context).pushReplacementNamed('/login'); } // Or in a button ElevatedButton( onPressed: () { fToast.removeQueuedCustomToasts(); print("All toasts cleared"); }, child: Text("Clear All Toasts"), ); ```