### Installation Rules for Application Bundle Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Defines the installation process for creating a relocatable application bundle. It specifies the installation prefix, clears the bundle directory before installation, and installs the executable, Flutter ICU data, Flutter library, and bundled plugin libraries. ```cmake 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() 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(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) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### CMake Installation Rules for Windows Executable and Assets Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/CMakeLists.txt Configures the installation process for the Windows build. It sets the installation prefix to be adjacent to the executable for 'run in place' functionality, installs the main executable, ICU data file, Flutter library, bundled plugin libraries, and native assets. It also ensures the Flutter assets directory is correctly copied. ```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() set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) 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(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Installation of Native Assets Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Installs native assets provided by the build process into the application bundle's library directory. This ensures that any platform-specific assets required by plugins or the application are correctly placed. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### CMake Project Setup and Build Configuration Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/CMakeLists.txt Initializes CMake, defines project name and languages, sets the executable binary name, and configures build types (Debug, Profile, Release) based on generator capabilities. It also sets up specific linker and compiler flags for the Profile build mode. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(VERSION 3.14...3.25) 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() 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}") ``` -------------------------------- ### Install Flutter Assets using CMake Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt This CMake code installs Flutter assets from the build directory to the application bundle's data directory. It first removes any existing assets directory to ensure a clean installation. This is typically used in build systems for Flutter applications. ```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) ``` -------------------------------- ### Create a Dynamic Poll with Options and Date Source: https://github.com/swanflutter/dynamic_polls/blob/main/README.md This snippet shows how to create a dynamic poll with selectable options, start and end dates, and a callback for when an option is selected. It utilizes the `DynamicPoll.polls` widget. Debug mode printing is included. ```dart DynamicPoll.polls( options: const ['Reddfdfd', 'Bluefdfdfd', 'Greendfdfdfd sd sad sadadsadadsadsa s adas wdwdawd aw', 'Yellowfdfdfd'], startDate: DateTime.now().add(const Duration(seconds: 7)), endDate: DateTime.now().add(const Duration(minutes: 4)), onOptionSelected: (int selectedOption) { if (kDebugMode) { print('Selected option: $selectedOption'); } }, ) ``` -------------------------------- ### Install AOT Library Conditionally with CMake Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt This CMake code installs the AOT (Ahead-Of-Time compilation) library to the application bundle's library directory. The installation is conditional and only occurs for non-Debug build types to optimize performance in release builds. It requires the AOT_LIBRARY variable to be defined. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Flutter CustomPoll Widget Usage Example Source: https://github.com/swanflutter/dynamic_polls/blob/main/README.md This example demonstrates how to use the CustomPoll widget in a Flutter application. It includes setting up a StreamController for vote updates, initializing a ValueNotifier for vote data, and configuring the CustomPoll widget with various parameters like title, options, dates, and callbacks. It also shows how to send vote data to a server and display vote information using ValueListenableBuilder. ```dart class MyPage extends StatefulWidget { @override State createState() => _MyPageState(); } class _MyPageState extends State { final voteStreamController = StreamController.broadcast(); final voteNotifier = ValueNotifier( VoteData( totalVotes: 0, optionVotes: {}, percentages: {}, ) ); @override void initState() { super.initState(); voteStreamController.stream.listen((voteData) { // Send vote data to the server _sendToServer(voteData); }); } @override Widget build(BuildContext context) { voteNotifier.addListener(() { final voteData = voteNotifier.value; print('all votes: ${voteData.totalVotes}'); print('votes for each option: ${voteData.optionVotes}'); print('percentages for each option: ${voteData.percentages}'); }); return Scaffold( body: CustomPoll( title: 'What is your favorite color?', options: ['Red', 'Blue', 'Green', 'Yellow'], startDate: DateTime.now(), endDate: DateTime.now().add(Duration(hours: 24)), onOptionSelected: (index) { print('Selected option: $index'); }, voteStream: voteStreamController, voteNotifier: voteNotifier, // Other parameters ), ); } // یا با ValueListenableBuilder ValueListenableBuilder( valueListenable: voteNotifier, builder: (context, voteData, child) { return Column( children: [ Text('all votes: ${voteData.totalVotes}'), ], ); }, ) @override void dispose() { voteStreamController.dispose(); super.dispose(); } Future _sendToServer(VoteData voteData) async { try { final response = await http.post( Uri.parse('YOUR_API_ENDPOINT'), headers: {'Content-Type': 'application/json'}, body: jsonEncode(voteData.toJson()), ); if (response.statusCode == 200) { print('Vote data sent successfully'); } else { print('Failed to send vote data'); } } catch (e) { print('Error sending vote data: $e'); } } } ``` -------------------------------- ### Create Customizable Poll with Dart Source: https://github.com/swanflutter/dynamic_polls/blob/main/README.md Demonstrates how to create a customizable poll using the `DynamicPoll` widget in Dart. It allows setting titles, options, styles, and handling user selections. This example includes configuration for private polls, reselection, timers, and detailed styling for titles, options, and votes. ```dart DynamicPoll( title: 'کدام زبان برنامه‌نویسی محبوب‌تر است؟', private: false, allowReselection: false, showPercentages: false, showTimer: false, options: const [ 'فلاتر', 'جاوااسکریپت', 'پایتون', 'سی‌شارپ', ], totalVotes: 0, startDate: DateTime.now().add(const Duration(seconds: 5)), endDate: DateTime.now().add(const Duration(seconds: 10)), maximumOptions: 20, backgroundDecoration: BoxDecoration( borderRadius: BorderRadius.circular(12.0), color: Colors.grey.shade100, ), heightBetweenTitleAndOptions: 20, votesText: 'رای‌ها', createdBy: 'نام خلق کننده', userToVote: 'نام کاربر', loadingWidget: const CircularProgressIndicator(), voteStream: StreamController(), allStyle: Styles( titleStyle: TitleStyle( alignment: Alignment.center, maxLines: 2, minLines: 1, textAlign: TextAlign.center, textDirection: TextDirection.rtl, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), optionStyle: OptionStyle( borderRadius: BorderRadius.circular(12), selectedBorderColor: Colors.blue, unselectedBorderColor: Colors.grey, borderWidth: 2.0, fillColor: Colors.white, votedCheckmark: const Icon(Icons.check, color: Colors.green), textSelectColor: Colors.blue, otherTextPercentColor: Colors.black, leadingVotedProgessColor: Colors.blue, opacityLeadingVotedProgessColor: 0.5, votedBackgroundColor: Colors.blue, voteBorderProgressColor: Colors.blue, progressBorderWidth: 1.0, ), votesTextStyle: VotesTextStyle( alignment: Alignment.center, paddingTop: 10, paddingBottom: 10, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), dateStyle: DateStyle( mainAxisAlignment: MainAxisAlignment.spaceEvenly, textStart: 'شروع شده در: ', textStyle: const TextStyle(fontWeight: FontWeight.bold, color: Colors.black), ), ), onOptionSelected: (index) { print('رای داده شد به گزینه $index'); }, ) ``` ```dart DynamicPoll( private: false, allowReselection: true, showPercentages: false, showTimer: true, allStyle: Styles( titleStyle: TitleStyle(textDirection: TextDirection.ltr, alignment: Alignment.centerLeft), optionStyle: OptionStyle( unselectedBorderColor: Colors.teal, votedBackgroundColor: Colors.blue.withOpacity(0.5), borderRadius: BorderRadius.circular(8), borderColor: Colors.purple, leadingVotedProgessColor: Colors.purple, height: 45, voteBorderProgressColor: Colors.purple, fillColor: Colors.white, ), ), title: 'What is your favorite color? ef ewf wewerwetwerwrweret t t wtwetrw t 4twtrw4 ttttetertt 4tetree t ertert et ert e 543eter te t ert ter te4 t rret54e te tre te ert 4 3tertert', ``` -------------------------------- ### Install and Import custom_poll Package in Flutter Source: https://github.com/swanflutter/dynamic_polls/blob/main/README.md This snippet shows how to add the custom_poll package as a dependency in your Flutter project's pubspec.yaml file and how to import it into your Dart code. ```yaml dependencies: custom_poll: ^0.0.5+1 ``` ```dart import 'package:custom_poll/custom_poll.dart'; ``` -------------------------------- ### Display a View-Only Poll Widget Source: https://github.com/swanflutter/dynamic_polls/blob/main/README.md This example shows how to render a poll that is only for viewing results. It takes title, options, votes, total votes, and date information, along with various styling parameters for percentages, text styles, and colors. Uses `CustomPoll.viewOnlyPollWidget`. ```dart Padding( padding: const EdgeInsets.all(16.0), child: CustomPoll.viewOnlyPollWidget( title: title, options: options, votes: votes, totalVotes: totalVotes, startDate: startDate, endDate: endDate, showPercentages: true, votesText: "آرا", heightBetweenTitleAndOptions: 12, heightBetweenOptions: 16, pollOptionsHeight: 50, pollOptionsWidth: double.infinity, pollOptionsBorderRadius: BorderRadius.circular(12), pollOptionsFillColor: Colors.white, pollOptionsSplashColor: Colors.grey[300]!, votedProgressColor: Colors.blue, leadingVotedProgessColor: Colors.blueAccent, votedBackgroundColor: const Color(0xffEEF0EB), votedPercentageTextStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold), votesTextStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500), ), ) ``` -------------------------------- ### Flutter Tool Backend Integration Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/flutter/CMakeLists.txt This section defines a custom command to run the Flutter tool backend script. It's configured to run every time by using a dummy output file (`_phony_`) because determining precise input/output dependencies for the flutter tool is complex. This ensures the Flutter library and headers are generated. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. 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} ) ``` -------------------------------- ### Flutter C++ Wrapper Configuration (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/flutter/CMakeLists.txt Defines static libraries for the Flutter C++ wrapper, used for both plugins and the application runner. It includes core implementations and platform-specific source files. Dependencies include the main Flutter library and flutter_assemble. ```cmake # === Wrapper === list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") # Wrapper sources needed for a plugin. add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) # Wrapper sources needed for the runner. add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Flutter Library Configuration (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/flutter/CMakeLists.txt Configures the Flutter library, including its DLL, header files, and ICU data. It sets up an INTERFACE library target that other targets can link against. Dependencies include flutter_assemble. ```cmake set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") # 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/windows/app.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Create a Simple Dynamic Poll Source: https://github.com/swanflutter/dynamic_polls/blob/main/README.md This code demonstrates the creation of a simple dynamic poll with a title and a list of string options. The `onOptionSelected` callback is provided but left empty. It uses the `DynamicPoll.polls` widget. ```dart DynamicPoll.polls( title: 'How old are you?', options: ['18-25', '26-30', '31-35', '36-40', '41-45', '46-50', '51-55', '56-60', '61-65', '66-70'], onOptionSelected: (int index) {}, allowReselection: false, ) ``` -------------------------------- ### Configure Flutter Linux GTK Build Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/flutter/CMakeLists.txt This CMake script configures the build for a Flutter Linux GTK application. It finds necessary packages like PkgConfig, GTK, GLIB, and GIO, defines paths to the Flutter library and ICU data, and sets up interface libraries for Flutter and its dependencies. ```cmake cmake_minimum_required(VERSION 3.10) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. # Serves the same purpose as list(TRANSFORM ... PREPEND ...), # which isn't available in 3.10. 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() # === Flutter Library === # System-level dependencies. 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) 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) 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) ``` -------------------------------- ### Apply Standard Build Settings (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/runner/CMakeLists.txt Applies a standard set of build settings to the application target. This simplifies configuration for applications that do not require custom build flags or options. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Executable Target Definition Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Defines the main executable target for the application, including its source files and the application's binary name. It also applies the standard build settings defined by the `APPLY_STANDARD_SETTINGS` function. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Sets up the minimum CMake version, project name, and executable name. It also defines the application ID, which is crucial for GTK applications. Modern CMake behaviors are explicitly enabled to avoid warnings. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "com.example.example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Apply Standard Compilation Settings Function Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/CMakeLists.txt Defines a CMake function `APPLY_STANDARD_SETTINGS` to apply common compilation features and options to a specified target. This includes setting the C++ standard to C++17, configuring warning levels, and defining preprocessor macros for Unicode support and debug builds. ```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() ``` -------------------------------- ### Cross-Building Configuration Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Configures the build environment for cross-compilation by setting the sysroot and related search paths. This ensures that the correct system libraries and headers are used when building for a different target platform. ```cmake 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() ``` -------------------------------- ### Flutter Tool Backend Integration (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/flutter/CMakeLists.txt Integrates with the Flutter tool backend to generate build artifacts like DLLs and headers. It uses a custom command with a dummy output file to ensure execution. The `flutter_assemble` custom target depends on these artifacts. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### Define Executable Target and Source Files (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/runner/CMakeLists.txt Defines the main executable target for the application and lists all associated source files, including C++ files, resource files, and generated Flutter plugin registration files. This is crucial for linking the application together. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer # work. # # Any new source files that you add to the application should be added here. 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" ) ``` -------------------------------- ### Custom Function for Standard Settings Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Defines a reusable CMake function `APPLY_STANDARD_SETTINGS` that applies common compilation features, warnings, optimization levels, and preprocessor definitions to a given target. This promotes code consistency across different build targets. ```cmake 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() ``` -------------------------------- ### Linking Dependencies Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Links the application executable against the Flutter library and the PkgConfig-imported GTK+ target. This ensures that all necessary libraries are available during the linking phase. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Flutter Integration and System Dependencies Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Integrates the Flutter build system by adding the Flutter managed directory as a subdirectory and finding system-level dependencies like PkgConfig and GTK+. It also defines the application ID as a preprocessor macro. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Link Libraries and Include Directories (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/runner/CMakeLists.txt Specifies the libraries that the application executable depends on and the directories where header files can be found. This includes Flutter-specific libraries and Windows system libraries. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Runtime Output Directory Configuration Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Configures the runtime output directory for the application executable to a subdirectory within the build directory. This is done to ensure that the executable can locate its resources correctly when run from the build environment. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Flutter Project Integration and Subdirectory Builds Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/CMakeLists.txt Includes the Flutter managed directory and the application runner subdirectory. It also includes generated plugin build rules, which are essential for integrating native plugins into the Flutter application. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) add_subdirectory("runner") include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define CMake List Prepend Functionality Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/flutter/CMakeLists.txt This function emulates `list(TRANSFORM ... PREPEND ...)` for CMake versions prior to 3.10. It prepends a given prefix to each element in a list, modifying the list in place. ```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() ``` -------------------------------- ### Add Flutter Version Preprocessor Definitions (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/runner/CMakeLists.txt Adds preprocessor definitions to the compile command for the application target, embedding Flutter version information directly into the build. This allows the application to access version details at compile time. ```cmake # Add preprocessor definitions for the build version. target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"" target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Create a Radio Button Poll with Reselection Source: https://github.com/swanflutter/dynamic_polls/blob/main/README.md This snippet illustrates how to create a poll using radio buttons with reselection enabled. It includes a title, a list of options, and an `onOptionSelected` callback. The `CustomPoll.radioBottomPolls` widget is used. ```dart CustomPoll.radioBottomPolls( title: 'How old are you?', options: const ['18-25', '26-30', '31-35', '36-40', '41-45', '46-50', '51-55', '56-60', '61-65', '66-70'], onOptionSelected: (int index) {}, allowReselection: true, ) ``` -------------------------------- ### Dart: Styles Configuration for Dynamic Polls Widgets Source: https://context7.com/swanflutter/dynamic_polls/llms.txt Configures a comprehensive styling system for customizing poll widgets using Dart. It defines a `Styles` object with various sub-styles for title, options, vote text, dates, and show time. This configuration can be applied to `DynamicPolls` widgets to alter their visual appearance. Dependencies include package:dynamic_polls and package:flutter/material.dart. ```dart import 'package:dynamic_polls/dynamic_polls.dart'; import 'package:flutter/material.dart'; // Complete style configuration Styles customStyles = Styles( titleStyle: TitleStyle( alignment: Alignment.centerLeft, maxLines: 3, minLines: 1, textAlign: TextAlign.left, textDirection: TextDirection.ltr, style: TextStyle( fontSize: 22, fontWeight: FontWeight.w700, color: Colors.black87, ), ), optionStyle: OptionStyle( height: 55, borderRadius: BorderRadius.circular(16), borderWidth: 2.0, borderColor: Colors.purple, selectedBorderColor: Colors.deepPurple, unselectedBorderColor: Colors.grey.shade400, fillColor: Colors.white, votedBackgroundColor: Colors.purple.withOpacity(0.1), votedCheckmark: Icon(Icons.check_circle, color: Colors.green, size: 24), textSelectColor: Colors.deepPurple, otherTextPercentColor: Colors.black54, leadingVotedProgessColor: Colors.deepPurple, opacityLeadingVotedProgessColor: 0.7, voteBorderProgressColor: Colors.deepPurple, progressBorderWidth: 2.0, heightBetweenOptions: 12, animationDuration: Duration(milliseconds: 800), ), votesTextStyle: VotesTextStyle( alignment: Alignment.centerRight, paddingTop: 16, paddingBottom: 8, style: TextStyle( fontSize: 14, fontWeight: FontWeight.w600, color: Colors.grey.shade700, ), ), dateStyle: DateStyle( mainAxisAlignment: MainAxisAlignment.spaceBetween, textStart: 'Started: ', textStyle: TextStyle( fontWeight: FontWeight.w500, fontSize: 12, color: Colors.black54, ), ), showTimeStyle: ShowTimeStyle( alignment: Alignment.center, height: 80, width: 200, text: 'Time remaining: ', style: TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold, ), decoration: BoxDecoration( color: Colors.black.withOpacity(0.8), borderRadius: BorderRadius.circular(12), ), ), ); // Apply styles to poll DynamicPolls( title: 'Styled Poll', options: ['Option A', 'Option B', 'Option C'], startDate: DateTime.now(), endDate: DateTime.now().add(Duration(days: 1)), allStyle: customStyles, onOptionSelected: (index) {}, ) ``` -------------------------------- ### Generated Plugin Inclusion Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Includes the CMake script for handling generated Flutter plugin build rules. This script is responsible for compiling and integrating any native plugins used by the Flutter application. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### DynamicPolls Widget: Interactive Polls with Timer and Customization (Dart) Source: https://context7.com/swanflutter/dynamic_polls/llms.txt Demonstrates the usage of the DynamicPolls widget for creating interactive polls with timer support, vote tracking, and extensive customization options. It includes setting up streams and notifiers for real-time vote updates and defines various styling properties. ```dart import 'dart:async'; import 'package:dynamic_polls/dynamic_polls.dart'; import 'package:flutter/material.dart'; // Basic implementation with timer and vote stream final voteStreamController = StreamController.broadcast(); final voteNotifier = ValueNotifier( VoteData( totalVotes: 0, optionVotes: {}, percentages: {}, ) ); // Listen to vote data changes voteNotifier.addListener(() { final voteData = voteNotifier.value; print('Total votes: ${voteData.totalVotes}'); print('Option votes: ${voteData.optionVotes}'); print('Percentages: ${voteData.percentages}'); }); // Create poll with full customization DynamicPolls( title: 'What is your favorite programming language?', options: const ['Flutter', 'JavaScript', 'Python', 'C#'], startDate: DateTime.now().add(Duration(seconds: 5)), endDate: DateTime.now().add(Duration(minutes: 10)), allowReselection: false, showPercentages: true, showTimer: true, totalVotes: 0, maximumOptions: 20, private: false, backgroundDecoration: BoxDecoration( borderRadius: BorderRadius.circular(12.0), color: Colors.grey.shade100, ), heightBetweenTitleAndOptions: 20, votesText: 'votes', userData: UserDataModel( userToVote: 'John Doe', userId: '12345', country: 'USA', gender: 'Male', age: 25, phone: 1234567890, ), voteStream: voteStreamController, voteNotifier: voteNotifier, loadingWidget: CircularProgressIndicator(), allStyle: Styles( titleStyle: TitleStyle( alignment: Alignment.center, maxLines: 2, minLines: 1, textAlign: TextAlign.center, textDirection: TextDirection.ltr, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), optionStyle: OptionStyle( borderRadius: BorderRadius.circular(12), selectedBorderColor: Colors.blue, unselectedBorderColor: Colors.grey, borderWidth: 2.0, fillColor: Colors.white, votedCheckmark: Icon(Icons.check, color: Colors.green), textSelectColor: Colors.blue, otherTextPercentColor: Colors.black, leadingVotedProgessColor: Colors.blue, opacityLeadingVotedProgessColor: 0.5, votedBackgroundColor: Colors.blue, voteBorderProgressColor: Colors.blue, progressBorderWidth: 1.0, ), votesTextStyle: VotesTextStyle( alignment: Alignment.center, paddingTop: 10, paddingBottom: 10, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), ), onOptionSelected: (index) { print('Selected option: $index'); }, ) // Cleanup voteStreamController.dispose(); ``` -------------------------------- ### Flutter Build Dependencies Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Adds a dependency on the `flutter_assemble` target, ensuring that the Flutter toolchain's assembly process is completed before the application executable is built. This is essential for Flutter applications. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Build Type Configuration Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already specified, and restricts the allowed build types to 'Debug', 'Profile', and 'Release'. This ensures consistent build configurations for the application. ```cmake 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 Flutter Assemble Dependency (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/runner/CMakeLists.txt Ensures that the Flutter build system has completed its assembly process before the main application target is built. This is a mandatory step for Flutter projects using CMake. ```cmake # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Dart: Server Integration for Real-time Vote Streaming Source: https://context7.com/swanflutter/dynamic_polls/llms.txt Integrates real-time vote synchronization with backend services using Dart. It sets up a stream controller to listen for vote data and sends it to a specified API endpoint via HTTP POST requests. Dependencies include dart:async, dart:convert, package:dynamic_polls, and package:http. It handles sending VoteData to a server and updating UI based on vote changes. ```dart import 'dart:async'; import 'dart:convert'; import 'package:dynamic_polls/dynamic_polls.dart'; import 'package:http/http.dart' as http; class PollPage extends StatefulWidget { @override State createState() => _PollPageState(); } class _PollPageState extends State { final voteStreamController = StreamController.broadcast(); final voteNotifier = ValueNotifier( VoteData( totalVotes: 0, optionVotes: {}, percentages: {}, ) ); @override void initState() { super.initState(); // Listen to vote stream and send to server voteStreamController.stream.listen((voteData) { _sendToServer(voteData); }); // Listen to notifier for UI updates voteNotifier.addListener(() { final voteData = voteNotifier.value; print('Total votes: ${voteData.totalVotes}'); print('Option votes: ${voteData.optionVotes}'); print('Percentages: ${voteData.percentages}'); }); } Future _sendToServer(VoteData voteData) async { try { final response = await http.post( Uri.parse('https://api.example.com/polls/vote'), headers: {'Content-Type': 'application/json'}, body: jsonEncode(voteData.toJson()), ); if (response.statusCode == 200) { print('Vote data sent successfully'); } else { print('Failed to send vote data: ${response.statusCode}'); } } catch (e) { print('Error sending vote data: $e'); } } @override Widget build(BuildContext context) { return Scaffold( body: DynamicPolls( title: 'What is your favorite color?', options: ['Red', 'Blue', 'Green', 'Yellow'], startDate: DateTime.now(), endDate: DateTime.now().add(Duration(hours: 24)), voteStream: voteStreamController, voteNotifier: voteNotifier, onOptionSelected: (index) { print('Selected option: $index'); }, ), ); } @override void dispose() { voteStreamController.close(); voteNotifier.dispose(); super.dispose(); } } ``` -------------------------------- ### DynamicPolls.polls Static Factory: Simplified Polls (Dart) Source: https://context7.com/swanflutter/dynamic_polls/llms.txt Illustrates the use of the static `polls` factory method for creating simplified poll widgets without timer functionality. This is suitable for basic voting scenarios where timers are not required. It allows for basic customization of options and styling. ```dart import 'package:dynamic_polls/dynamic_polls.dart'; import 'package:flutter/material.dart'; // Simple poll implementation DynamicPolls.polls( title: 'How old are you?', options: [ '18-25', '26-30', '31-35', '36-40', '41-45', '46-50', '51-55', '56-60', '61-65', '66-70' ], allowReselection: true, showPercentages: true, totalVotes: 0, maximumOptions: 20, votesText: 'votes', private: false, allStyle: Styles( titleStyle: TitleStyle( textDirection: TextDirection.ltr, alignment: Alignment.centerLeft, ), optionStyle: OptionStyle( progressBorderWidth: 2, animationDuration: Duration(seconds: 1), borderColor: Colors.amber, votedBackgroundColor: Colors.blue.withOpacity(0.3), ), ), onOptionSelected: (int index) { print('User selected option at index: $index'); }, ) ``` -------------------------------- ### Disable Windows Max/Min Macros (CMake) Source: https://github.com/swanflutter/dynamic_polls/blob/main/example/windows/runner/CMakeLists.txt Disables Windows-specific macros `max` and `min` to prevent naming collisions with standard C++ library functions. This ensures cleaner C++ code and avoids potential compilation errors. ```cmake # Disable Windows macros that collide with C++ standard library functions. target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### UserDataModel for User Information (Dart) Source: https://context7.com/swanflutter/dynamic_polls/llms.txt Introduces the `UserDataModel` for storing user metadata relevant to poll participation. This includes user identifiers, demographic information such as country, gender, and age, and contact details like phone number. The model can be directly used within `DynamicPolls` widgets to associate user data with poll interactions. ```dart import 'package:dynamic_polls/dynamic_polls.dart'; // Create user data model UserDataModel userData = UserDataModel( userToVote: 'Jane Smith', userId: 'user-67890', country: 'Canada', gender: 'Female', age: 30, phone: 9876543210, ); // Use in poll widget DynamicPolls( title: 'Poll Title', options: ['Option 1', 'Option 2'], startDate: DateTime.now(), endDate: DateTime.now().add(Duration(days: 1)), userData: userData, onOptionSelected: (index) { print('${userData.userToVote} selected option $index'); }, ) ```