### Dart Basic Web Setup for Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Provides the fundamental `main` function and `MyApp` widget setup for a basic Flutter web application using the `rough_flutter` package. This serves as the entry point for web-based demonstrations. ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Rough Web Demo', home: RoughCanvas(), ); } } ``` -------------------------------- ### Dart Mobile-Optimized Setup for Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Demonstrates a mobile-optimized setup for Flutter Rough, including initialization of `RoughMobileWeb` and the structure for `RoughMobileLayout`. It showcases a canvas with mobile-specific controls like `RoughMobileSlider`. ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() { // Initialize mobile web optimizations RoughMobileWeb.initialize(); runApp(const MyApp()); } class MobileOptimizedCanvas extends StatelessWidget { @override Widget build(BuildContext context) { return RoughMobileLayout( child: Column( children: [ // Canvas Expanded( child: CustomPaint( painter: RoughPainter(), ), ), // Mobile-optimized controls RoughMobileSlider( label: 'Roughness', value: roughness, min: 0.0, max: 5.0, divisions: 50, onChanged: updateRoughness, ), ], ), ); } } ``` -------------------------------- ### Basic to Web-Optimized Migration (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Demonstrates the migration from a basic Rough Flutter setup to a web-optimized version. Key changes include initializing `RoughMobileWeb` and using `RoughMobileLayout` with `WebOptimizedRoughPainter`. ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() { runApp(MyApp()); } class MyCanvas extends StatelessWidget { @override Widget build(BuildContext context) { return CustomPaint( painter: BasicRoughPainter(), ); } } ``` ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() { RoughMobileWeb.initialize(); // ← Add mobile support runApp(MyApp()); } class MyCanvas extends StatelessWidget { @override Widget build(BuildContext context) { return RoughMobileLayout( // ← Add responsive layout child: CustomPaint( painter: WebOptimizedRoughPainter(), // ← Use optimized painter ), ); } } ``` -------------------------------- ### Enable Web Support and Run Example App (Bash) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_SUPPORT_PLAN.md This snippet shows the bash commands to enable web support for a Flutter project, create a web build for the example app, and then run it on Chrome. It's a crucial first step in assessing web compatibility. ```bash cd example flutter config --enable-web flutter create . --platforms web flutter run -d chrome ``` -------------------------------- ### Dart Performance Monitoring Best Practices Example Source: https://github.com/acyment/flutter_rough/blob/master/API_REFERENCE.md Demonstrates how to integrate performance monitoring into a Flutter application using `RoughMobilePerformance`. This example shows how to start monitoring in debug mode and periodically check the performance report to log FPS and potential issues. ```dart import 'dart:async'; import 'package:flutter/foundation.dart'; // Assuming RoughMobilePerformance is imported class MyApp extends StatefulWidget { @override State createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); // Start monitoring if in debug mode if (kDebugMode) { _startPerformanceMonitoring(); } } void _startPerformanceMonitoring() { Timer.periodic(Duration(seconds: 5), (timer) { final report = RoughMobilePerformance.getPerformanceReport(); if (report['frameCount'] > 30) { // Enough data print('Performance: ${report['estimatedFPS']} FPS avg'); if (!report['isGoodPerformance']) { print('⚠️ Performance below 60fps target'); } } }); } @override Widget build(BuildContext context) { // Your app content return Container(); } } ``` -------------------------------- ### Initialize Rough Mobile Web - Advanced Setup Source: https://github.com/acyment/flutter_rough/blob/master/README_WEB_FEATURES.md This Dart code shows an advanced setup for RoughMobileWeb, including initializing the WebOptimizedGenerator with a progressive loading strategy. This enables more sophisticated web optimizations. ```dart void main() async { WidgetsFlutterBinding.ensureInitialized(); // Full optimization suite RoughMobileWeb.initialize(); await WebOptimizedGenerator.initialize( strategy: LoadingStrategy.progressive, ); runApp(MyApp()); } ``` -------------------------------- ### RoughMobileWeb API Reference (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Provides static methods for mobile web detection and optimization utilities within the Flutter Rough library. Includes initialization, checking for mobile web, getting optimized canvas sizes, and configuration. ```dart class RoughMobileWeb { // Initialize mobile web detection static void initialize(); // Check if running on mobile web static bool get isMobileWeb; // Get optimized canvas size for mobile static Size getOptimizedCanvasSize(Size requestedSize); // Get mobile-optimized drawing configuration static Map getMobileOptimizedConfig(); } ``` -------------------------------- ### Basic Flutter Web Usage Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Standard usage of the rough_flutter library for drawing shapes on a canvas. This example demonstrates the basic integration and assumes the library is automatically web-optimized. It requires stroke and fill paint objects. ```dart import 'package:rough_flutter/rough_flutter.dart'; // Standard usage - automatically web-optimized final generator = Generator(); final drawable = generator.rectangle(10, 10, 100, 80); canvas.drawRough(drawable, strokePaint, fillPaint); ``` -------------------------------- ### Backward Compatible Drawing (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/MIGRATION_GUIDE.md Illustrates code that remains fully backward compatible across versions. This example shows how to use the Generator to create a rectangle and draw it on a canvas using existing methods. ```dart // This code from v1.x works exactly the same in v2.x final generator = Generator(); final drawable = generator.rectangle(10, 10, 100, 80); canvas.drawRough(drawable, strokePaint, fillPaint); ``` -------------------------------- ### Web-Optimized to Lazy Loading Migration (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Illustrates migrating from a standard web-optimized generator to a lazy-loaded approach. It shows both asynchronous and synchronous methods for initializing the generator with lazy fillers. ```dart final generator = Generator(drawConfig, HachureFiller(fillerConfig)); ``` ```dart // Async approach (recommended) final generator = await WebOptimizedGenerator.withLazyFiller( 'HachureFiller', fillerConfig, drawConfig, ); // Sync approach (with fallback) final generator = WebOptimizedGenerator.withLazyFillerSync( 'HachureFiller', fillerConfig, drawConfig, ); ``` -------------------------------- ### Initialize Rough Mobile Web - Basic Setup Source: https://github.com/acyment/flutter_rough/blob/master/README_WEB_FEATURES.md This Dart code demonstrates the basic initialization of RoughMobileWeb for mobile optimizations in a Flutter application. It's a prerequisite for leveraging mobile-specific features. ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() { // Initialize mobile optimizations RoughMobileWeb.initialize(); runApp(MyApp()); } ``` -------------------------------- ### RoughMobilePerformance API Reference (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Offers tools for performance monitoring on mobile web platforms using Flutter Rough. Includes methods to record frame times, retrieve average frame time, check performance against 60fps, and get detailed reports. ```dart class RoughMobilePerformance { // Record frame time static void recordFrame(); // Get average frame time static Duration getAverageFrameTime(); // Check if performance is good (60fps) static bool isPerformanceGood(); // Get detailed performance report static Map getPerformanceReport(); } ``` -------------------------------- ### Initialize Mobile-Aware Rough Flutter Source: https://github.com/acyment/flutter_rough/blob/master/MIGRATION_GUIDE.md This Dart code demonstrates initializing the mobile-aware features of flutter_rough. Add `RoughMobileWeb.initialize();` to your `main` function before `runApp` to enable mobile optimizations. ```dart // Before: Basic initialization void main() { runApp(MyApp()); } // After: Mobile-aware initialization void main() { RoughMobileWeb.initialize(); // ← Add this line runApp(MyApp()); } ``` -------------------------------- ### Loading Strategy Selection (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Provides guidance on selecting the appropriate loading strategy for fillers based on application usage patterns. Options include `progressive`, `onDemand`, and `preloadAll`. ```dart // Choose based on your app's usage patterns // For apps with diverse filler usage LoadingStrategy.progressive // ← Recommended default // For apps using only basic fillers LoadingStrategy.onDemand // ← Fastest initial load // For apps with heavy filler usage LoadingStrategy.preloadAll // ← Best for power users ``` -------------------------------- ### Zero-Configuration Web Support in Flutter Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_SUMMARY.md Demonstrates the zero-configuration web support in Flutter Rough. This code snippet shows how to use the Generator to create shapes and draw them on a canvas without requiring any specific setup. ```dart // This works automatically - no changes needed! final generator = Generator(); final drawable = generator.rectangle(10, 10, 100, 80); canvas.drawRough(drawable, strokePaint, fillPaint); ``` -------------------------------- ### Complete Rough Flutter Drawing Example Source: https://github.com/acyment/flutter_rough/blob/master/README.md A comprehensive example demonstrating how to create a custom painter in Flutter that utilizes the rough_flutter library to draw a sketchy circle. It covers setting up DrawConfig, Filler, Generator, and painting on the canvas. ```dart import 'package:flutter/material.dart'; import 'package:rough_flutter/rough_flutter.dart'; class RoughExample extends CustomPainter { @override void paint(Canvas canvas, Size size) { // Create draw config final drawConfig = DrawConfig.build( roughness: 2, curveStepCount: 10, seed: 1, ); // Create filler config final fillerConfig = FillerConfig.build( hachureGap: 8, hachureAngle: -20, drawConfig: drawConfig, ); // Create filler final filler = ZigZagFiller(fillerConfig); // Create generator final generator = Generator(drawConfig, filler); // Create drawable final circle = generator.circle(size.width / 2, size.height / 2, 100); // Create paints final pathPaint = Paint() ..color = Colors.blue ..style = PaintingStyle.stroke ..strokeWidth = 2; final fillPaint = Paint() ..color = Colors.red.withOpacity(0.3) ..style = PaintingStyle.stroke ..strokeWidth = 1; // Draw on canvas canvas.drawRough(circle, pathPaint, fillPaint); } @override bool shouldRepaint(covariant CustomPainter oldDelegate) => false; } ``` -------------------------------- ### Flutter Web Integration Test Example Source: https://github.com/acyment/flutter_rough/blob/master/WEB_TESTING_RESULTS.md An example of a Flutter integration test specifically for the web platform. It demonstrates navigating the app, interacting with UI elements like sliders, and verifying rendering. ```dart // Example web-specific integration test testWidgets('Web: Drawing renders correctly', (tester) async { await tester.pumpWidget(MyApp()); // Navigate to circle demo await tester.tap(find.text('Interactive circle')); await tester.pumpAndSettle(); // Verify canvas is present expect(find.byType(CustomPaint), findsOneWidget); // Test slider interaction await tester.drag(find.byType(Slider).first, Offset(50, 0)); await tester.pumpAndSettle(); // Verify no rendering errors expect(tester.takeException(), isNull); }); ``` -------------------------------- ### Basic Flutter Rough Usage (Web Optimized) Source: https://github.com/acyment/flutter_rough/blob/master/MIGRATION_GUIDE.md This Dart code demonstrates basic flutter_rough usage. It works identically to previous versions but is now automatically web-optimized, requiring no code changes. ```dart import 'package:rough_flutter/rough_flutter.dart'; final generator = Generator(); final drawable = generator.rectangle(10, 10, 100, 80); canvas.drawRough(drawable, strokePaint, fillPaint); ``` -------------------------------- ### RoughMobileHaptics Class Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Provides utility methods for triggering haptic feedback on mobile web devices. ```APIDOC ## RoughMobileHaptics Class Haptic feedback helpers for mobile web. ### Description Offers simple methods to invoke haptic feedback, enhancing the user experience on touch devices by providing tactile confirmation for actions. ### Methods - `lightImpact()` (static, async): Triggers a light haptic impact. - `selectionClick()` (static, async): Triggers a haptic feedback suitable for selection actions. ### Example Usage ```dart import 'package:rough_flutter/rough_flutter.dart'; Future triggerHaptics() async { await RoughMobileHaptics.lightImpact(); await RoughMobileHaptics.selectionClick(); } ``` ``` -------------------------------- ### RoughMobileWeb Class Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Utilities for mobile web detection and optimization, including canvas sizing and configuration. ```APIDOC ## RoughMobileWeb Class Mobile web detection and optimization utilities. ### Description Provides methods for detecting mobile web environments and applying optimizations for canvas rendering and configurations. ### Methods - `initialize()`: Initializes mobile web detection. - `isMobileWeb` (getter): Checks if the application is running on a mobile web platform. - `getOptimizedCanvasSize(Size requestedSize)`: Returns an optimized canvas size suitable for mobile web. - `getMobileOptimizedConfig()`: Retrieves a map of mobile-optimized drawing configurations. ### Example Usage ```dart import 'package:rough_flutter/rough_flutter.dart'; void setupMobileOptimizations() { RoughMobileWeb.initialize(); if (RoughMobileWeb.isMobileWeb) { final optimizedSize = RoughMobileWeb.getOptimizedCanvasSize(Size(800, 600)); final config = RoughMobileWeb.getMobileOptimizedConfig(); print('Optimized Canvas Size: $optimizedSize'); print('Mobile Config: $config'); } } ``` ``` -------------------------------- ### UI Components Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Collection of UI components designed for mobile web, including sliders, dropdowns, and progress indicators. ```APIDOC ## UI Components Provides specialized UI widgets for enhanced user interaction on mobile web platforms. ### `RoughMobileSlider` Touch-optimized slider component for mobile web interfaces. #### Properties - `key` (Key?): Optional key for widget identification. - `value` (double): The current value of the slider. - `min` (double): The minimum value of the slider. - `max` (double): The maximum value of the slider. - `divisions` (int?): The number of divisions between min and max. - `label` (String?): Label to display for the current value. - `onChanged` (ValueChanged?): Callback function when the slider value changes. ### `LazyFillerDropdown` A dropdown widget that displays loading states for lazy-loaded fillers. #### Properties - `key` (Key?): Optional key for widget identification. - `value` (dynamic): The currently selected value. - `onChanged` (ValueChanged?): Callback function when the dropdown value changes. - `availableFillers` (List): List of available filler names to display. - `loadingBuilder` (Widget Function?): Builder function for the loading state. - `errorBuilder` (Widget Function?): Builder function for the error state. ### `LoadingProgressIndicator` A widget that visually represents the loading progress of the lazy loading system. #### Properties - `key` (Key?): Optional key for widget identification. - `builder` (Widget Function?): Custom builder function to define the progress indicator's appearance. - `updateInterval` (Duration): The interval at which the progress indicator updates. ### Example Usage ```dart import 'package:rough_flutter/rough_flutter.dart'; Widget buildUIComponents() { return Column( children: [ RoughMobileSlider( value: 50.0, min: 0.0, max: 100.0, divisions: 10, label: '50%', ), LazyFillerDropdown( availableFillers: ['FillerA', 'FillerB'], onChanged: (value) => print('Selected: $value'), ), LoadingProgressIndicator(), ], ); } ``` ``` -------------------------------- ### Basic Web Usage in Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/README_WEB_FEATURES.md Demonstrates the basic setup for using Flutter Rough on the web. It initializes the generator and draws a simple rectangle on the canvas. This code is automatically optimized for web environments. ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() { runApp(MyApp()); } // Use anywhere - automatically web-optimized final generator = Generator(); final drawable = generator.rectangle(10, 10, 100, 80); canvas.drawRough(drawable, strokePaint, fillPaint); ``` -------------------------------- ### Bundle Size Management (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Advises against importing all fillers directly to manage bundle size. Instead, it recommends importing only core exports from `rough_flutter` and letting lazy loading handle the rest. ```dart // Avoid importing all fillers at once // ❌ Don't do this: import 'package:rough_flutter/src/filler.dart'; // Imports everything // ✅ Do this instead: import 'package:rough_flutter/rough_flutter.dart'; // Only core exports // Let lazy loading handle the rest ``` -------------------------------- ### Mobile Web Initialization Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Initializes the mobile web detection system for the Flutter application. This function should be called early in the application lifecycle, typically within the main function, to enable mobile-specific optimizations. ```dart void main() { // Initialize mobile web detection RoughMobileWeb.initialize(); runApp(const MyApp()); } ``` -------------------------------- ### Core System Initialization and Lazy Filler Usage in Dart Source: https://github.com/acyment/flutter_rough/blob/master/PHASE_3_ADVANCED_OPTIMIZATIONS_RESULTS.md Provides examples of initializing the WebOptimizedGenerator with a specific loading strategy and using lazy-loaded fillers. It also demonstrates how to integrate a LoadingProgressIndicator for monitoring loading progress. ```dart // Initialize the system await WebOptimizedGenerator.initialize( strategy: LoadingStrategy.progressive, ); // Use lazy-loaded fillers final generator = await WebOptimizedGenerator.withLazyFiller( 'ZigZagFiller', fillerConfig, drawConfig, ); // Monitor loading progress LoadingProgressIndicator( builder: (progressData) => CustomProgressWidget(progressData), ) ``` -------------------------------- ### Get Cache Stats (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Retrieves and prints cache statistics for web optimization, specifically path and paint cache sizes. This is useful for analyzing cache performance. ```dart // Web optimization cache stats final cacheStats = RoughWebUtils.getCacheStats(); print('Path cache size: ${cacheStats['pathCacheSize']}'); print('Paint cache size: ${cacheStats['paintCacheSize']}'); ``` -------------------------------- ### Enable Flutter Web and Create Project Files Source: https://github.com/acyment/flutter_rough/blob/master/MIGRATION_GUIDE.md These bash commands are used to enable the Flutter web platform and create necessary project files. Ensure Flutter web is enabled before building for web targets. ```bash # Enable Flutter web if not already enabled flutter config --enable-web # Create web-specific files flutter create --platforms web . ``` -------------------------------- ### Canvas Size Optimization Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md A utility function to get an optimized canvas size for mobile web environments. This helps maintain better performance by limiting the canvas dimensions on smaller screens. ```dart // Mobile canvases limited to 800px for better performance final optimizedSize = RoughMobileWeb.getOptimizedCanvasSize(requestedSize); ``` -------------------------------- ### Build and Run Flutter Web Application Source: https://github.com/acyment/flutter_rough/blob/master/MIGRATION_GUIDE.md This bash snippet shows how to build a Flutter application for the web and run it locally for testing. Use `flutter build web` for production builds and `flutter run -d chrome` for local development. ```bash # Build for web flutter build web # Test locally flutter run -d chrome ``` -------------------------------- ### Mobile Optimization Initialization (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Illustrates the essential step of initializing mobile web detection using `RoughMobileWeb.initialize()` in the `main` function for proper mobile support. It also shows the usage of mobile-aware components like `RoughMobileSlider` and `RoughMobileLayout`. ```dart // Always initialize mobile detection void main() { RoughMobileWeb.initialize(); // ← Essential for mobile support runApp(MyApp()); } // Use mobile-aware components Widget buildControls() { return Column( children: [ // Mobile-optimized slider RoughMobileSlider(...), // Responsive layout RoughMobileLayout( child: DesktopControls(), mobileChild: MobileControls(), ), ], ); } ``` -------------------------------- ### Performance Monitoring (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md This Dart code snippet demonstrates real-time performance monitoring within a Flutter application using `RoughMobilePerformance`. It records frames, checks if performance is good, and provides a way to get a performance report. ```dart // Real-time performance tracking RoughMobilePerformance.recordFrame(); final isGoodPerformance = RoughMobilePerformance.isPerformanceGood(); print('Performance is ${isGoodPerformance ? 'good' : 'poor'}'); ``` -------------------------------- ### Mobile-First Web Design with Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_SUMMARY.md Demonstrates how to initialize the mobile web optimization system and use touch-optimized components. It automatically adjusts touch targets and integrates native-feeling haptic feedback for a better mobile user experience. ```dart // Automatic mobile detection and optimization RoughMobileWeb.initialize(); // Touch-optimized components RoughMobileSlider( // 40% larger touch targets automatically label: 'Roughness', value: roughness, onChanged: (value) { updateValue(value); RoughMobileHaptics.lightImpact(); // Native-feeling feedback }, ) ``` -------------------------------- ### PWA Manifest Configuration Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Configuration for a Progressive Web App (PWA) manifest, defining the application's name, start URL, display mode, and theme color. This is a standard JSON configuration used by web browsers for PWA features. ```html { "name": "Flutter Rough Demo", "short_name": "Rough Demo", "start_url": "/", "display": "standalone", "theme_color": "#FF9800" } ``` -------------------------------- ### Initialize Lazy Loading System (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/MIGRATION_GUIDE.md Demonstrates the initialization of the lazy loading system in a Flutter application. It shows both the basic mobile initialization and the optimized initialization with Phase 3 components, highlighting that Phase 3 components are implemented but not exported due to compilation issues. ```dart // Before: Basic mobile initialization void main() { RoughMobileWeb.initialize(); runApp(MyApp()); } // After: Full optimization suite (Phase 3 components created but not exported) void main() { // Mobile optimizations (working) RoughMobileWeb.initialize(); runApp(MyApp()); } ``` -------------------------------- ### Smart Preloading and Loading State Management in Dart Source: https://github.com/acyment/flutter_rough/blob/master/PHASE_3_ADVANCED_OPTIMIZATIONS_RESULTS.md Demonstrates how to use the LazyLoadingManager for usage-based and strategic preloading of fillers. It also shows how to integrate LazyFillerDropdown to provide visual feedback during loading, including custom builders for loading and error states. ```dart // Usage-based preloading LazyLoadingManager.instance.trackUsage('HachureFiller'); // Automatically preloads: ZigZagFiller, CrossHatchFiller // Strategic preloading await LazyLoadingManager.instance.preloadCategory('common'); // Visual feedback for users LazyFillerDropdown( value: selectedFiller, onChanged: (filler) => handleFillerChange(filler), loadingBuilder: (name) => LoadingIndicator(name), errorBuilder: (name, error) => ErrorWidget(name, error), ) ``` -------------------------------- ### Flutter Web Build and Serve Commands Source: https://github.com/acyment/flutter_rough/blob/master/WEB_TESTING_RESULTS.md Commands to build the Flutter web application for production and serve it locally for testing. Includes options for development mode and experimental WebAssembly builds. ```bash # Launch in development mode flutter run -d chrome # Build for production testing flutter build web # Serve locally for testing cd build/web && python3 -m http.server 8080 # Then visit http://localhost:8080 # Build with WebAssembly (experimental) flutter build web --wasm ``` -------------------------------- ### Add rough_flutter Package to a New Project Source: https://github.com/acyment/flutter_rough/blob/master/PUBLISHING_CHECKLIST.md These bash commands show how to create a new Flutter project, navigate into its directory, and add the rough_flutter package as a dependency. ```bash flutter create test_rough_flutter cd test_rough_flutter flutter pub add rough_flutter ``` -------------------------------- ### RoughMobilePerformance Class Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Tools for monitoring and analyzing the performance of the application on mobile web. ```APIDOC ## RoughMobilePerformance Class Performance monitoring for mobile web. ### Description Provides utilities to track and analyze application performance metrics, such as frame times and overall rendering performance, to help identify and resolve bottlenecks. ### Methods - `recordFrame()`: Records the time taken for the current frame, used for performance analysis. - `getAverageFrameTime()`: Returns the average frame time calculated over recorded frames. - `isPerformanceGood()`: Checks if the current performance meets a good standard (e.g., 60fps). - `getPerformanceReport()`: Generates a detailed report of performance metrics. ### Example Usage ```dart import 'package:rough_flutter/rough_flutter.dart'; void monitorPerformance() { RoughMobilePerformance.recordFrame(); final avgFrameTime = RoughMobilePerformance.getAverageFrameTime(); final isGood = RoughMobilePerformance.isPerformanceGood(); final report = RoughMobilePerformance.getPerformanceReport(); print('Average Frame Time: $avgFrameTime'); print('Performance Good: $isGood'); print('Performance Report: $report'); } ``` ``` -------------------------------- ### Initialize WebOptimizedGenerator with LoadingStrategy Source: https://github.com/acyment/flutter_rough/blob/master/API_REFERENCE.md Demonstrates how to initialize the WebOptimizedGenerator with a chosen LoadingStrategy. The strategy influences the preloading behavior of fillers. ```dart // Initialize with strategy await WebOptimizedGenerator.initialize( strategy: LoadingStrategy.progressive, // Recommended default ); // Strategy affects preloading behavior switch (strategy) { case LoadingStrategy.onDemand: // Loads fillers only when explicitly requested break; case LoadingStrategy.preloadCommon: // Preloads: ZigZagFiller, DashedFiller break; case LoadingStrategy.preloadAll: // Preloads all available fillers in background break; case LoadingStrategy.progressive: // Starts with common, then progressively loads more break; } ``` -------------------------------- ### LazyLoadingManager Class Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Manages the loading strategies and preloading of fillers within the lazy loading system. ```APIDOC ## LazyLoadingManager Class Manages loading strategies and filler preloading. ### Description This class is responsible for controlling how fillers are loaded, allowing for different strategies like on-demand loading and preloading specific categories to optimize application performance. ### Properties - `instance` (static getter): Provides access to the singleton instance of the `LazyLoadingManager`. ### Methods - `initialize({LoadingStrategy strategy = LoadingStrategy.onDemand})`: Initializes the manager with a specified loading strategy. - `trackUsage(String fillerName)`: Tracks the usage of a specific filler, which can inform optimization decisions. - `preloadCategory(String category)`: Forces the preloading of all fillers within a given category. - `getStats()`: Retrieves the current loading statistics managed by this instance. ### Example Usage ```dart import 'package:rough_flutter/rough_flutter.dart'; void manageLoading() { final manager = LazyLoadingManager.instance; manager.initialize(strategy: LoadingStrategy.onDemand); manager.trackUsage('MyCustomFiller'); manager.preloadCategory('Shapes'); final stats = manager.getStats(); print('Lazy Loading Stats: $stats'); } ``` ``` -------------------------------- ### Initialize Mobile Optimizations in Flutter App Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_SUMMARY.md Initializes mobile optimizations for the Rough Flutter library and runs the main application. This is a crucial step for enabling mobile-specific features and performance enhancements. ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() { // Initialize mobile optimizations RoughMobileWeb.initialize(); runApp(MyApp()); } class MyCanvas extends StatelessWidget { @override Widget build(BuildContext context) { return RoughMobileLayout( child: CustomPaint( painter: MyRoughPainter(), ), ); } } ``` -------------------------------- ### WebOptimizedGenerator Class Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md An enhanced generator class that supports lazy loading of fillers and progressive loading strategies. ```APIDOC ## WebOptimizedGenerator Class Enhanced generator with lazy loading capabilities. ### Description Extends the base `Generator` class to provide advanced features for lazy loading fillers and managing loading strategies, improving performance by loading assets on demand. ### Methods - `initialize({LoadingStrategy strategy = LoadingStrategy.progressive})` (static): Initializes the web optimization system with a specified loading strategy. - `withLazyFiller(String fillerName, FillerConfig fillerConfig, [DrawConfig? drawConfig])` (static): Creates a generator instance with a lazily loaded filler. - `withLazyFillerSync(String fillerName, FillerConfig fillerConfig, [DrawConfig? drawConfig])` (static): Creates a generator instance with a lazily loaded filler, using synchronous loading as a fallback. - `preloadFillers(List fillerNames)` (static): Preloads a list of specified fillers. - `getAvailableFillers()` (static): Returns a list of all available filler names. - `getLoadingStats()` (static): Retrieves statistics about the loading process. ### Example Usage ```dart import 'package:rough_flutter/rough_flutter.dart'; Future setupLazyLoading() async { await WebOptimizedGenerator.initialize(strategy: LoadingStrategy.progressive); final generator = await WebOptimizedGenerator.withLazyFiller( 'ZigZagFiller', FillerConfig(), // Replace with actual FillerConfig ); await WebOptimizedGenerator.preloadFillers(['CircleFiller', 'SquareFiller']); final stats = WebOptimizedGenerator.getLoadingStats(); print('Loading Stats: $stats'); } ``` ``` -------------------------------- ### Update Dependencies for Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/MIGRATION_GUIDE.md This snippet shows the dependency declaration in pubspec.yaml. No changes are required for the basic flutter_rough package as it now includes enhanced features. ```yaml dependencies: rough_flutter: ^0.1.2 # Same package, enhanced features ``` -------------------------------- ### Advanced Lazy Loading System in Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_SUMMARY.md Illustrates the architecture for an advanced lazy loading system, where filler algorithms and components are loaded on demand. It includes examples of visual feedback for loading and error states, enhancing the user experience during dynamic content loading. ```dart // Phase 3 architecture (implemented, not exported) final generator = await WebOptimizedGenerator.withLazyFiller( 'ZigZagFiller', // Loaded on-demand fillerConfig, drawConfig, ); // Visual loading feedback LazyFillerDropdown( value: selectedFiller, loadingBuilder: (name) => LoadingIndicator(name), errorBuilder: (name, error) => ErrorDisplay(name, error), ) ``` -------------------------------- ### Dynamic Filler Loading Source: https://github.com/acyment/flutter_rough/blob/master/PHASE_3_ADVANCED_OPTIMIZATIONS_RESULTS.md Demonstrates asynchronous and synchronous methods for dynamically loading filler constructors. It includes error handling for async loading and fallback mechanisms for sync loading, ensuring robust filler instantiation. ```dart // Async loading with error handling final constructor = await FillerRegistry.getFiller('ZigZagFiller'); final filler = constructor(config); // Sync loading with fallback final filler = WebOptimizedGenerator.withLazyFillerSync( 'AdvancedFiller', config ); ``` -------------------------------- ### Error Handling for Lazy Loading (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Demonstrates how to implement error handling for lazy-loaded generators, providing a fallback to a basic filler in case of an error during the loading process. ```dart // Always provide fallbacks for lazy loading final generator = await WebOptimizedGenerator .withLazyFiller('AdvancedFiller', config) .catchError((error) { // Fallback to basic filler return WebOptimizedGenerator(config, NoFiller()); }); ``` -------------------------------- ### Initialize Flutter Rough for Mobile Web Lazy Loading (Dart) Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_GUIDE.md Sets up the Flutter application for mobile web optimizations and initializes the lazy loading system with a progressive strategy. This is typically done in the main function before running the app. ```dart import 'package:rough_flutter/rough_flutter.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Initialize mobile optimizations RoughMobileWeb.initialize(); // Initialize lazy loading system await WebOptimizedGenerator.initialize( strategy: LoadingStrategy.progressive, ); runApp(const MyApp()); } ``` -------------------------------- ### Install Rough Flutter Library Source: https://github.com/acyment/flutter_rough/blob/master/README.md Add the rough_flutter package to your pubspec.yaml file to include it as a dependency in your Flutter project. Ensure you are using Dart SDK version 3.0.0 or higher. ```yaml dependencies: rough_flutter: ``` -------------------------------- ### Mobile-Optimized Usage in Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/README_WEB_FEATURES.md Enables mobile-specific optimizations for Flutter Rough by calling `RoughMobileWeb.initialize()`. It also shows an example of a mobile-friendly slider control with larger touch targets. ```dart void main() { RoughMobileWeb.initialize(); // Enable mobile optimizations runApp(MyApp()); } // Mobile-friendly controls with larger touch targets RoughMobileSlider( label: 'Roughness', value: roughness, min: 0.0, max: 5.0, onChanged: updateRoughness, ) ``` -------------------------------- ### Intelligent Performance Monitoring with Flutter Rough Source: https://github.com/acyment/flutter_rough/blob/master/WEB_OPTIMIZATION_SUMMARY.md Shows how to implement real-time performance tracking within the Flutter Rough framework. This allows for recording frame performance and generating detailed performance reports, including FPS and frame times, to help identify and resolve performance bottlenecks. ```dart // Real-time performance tracking RoughMobilePerformance.recordFrame(); final report = RoughMobilePerformance.getPerformanceReport(); // Returns: FPS, frame times, performance status ```