### Add Scratcher Dependency to Flutter Project Source: https://pub.dev/packages/scratcher/install Run this command to add the scratcher package to your Flutter project's dependencies. This command also implicitly runs 'flutter pub get'. ```bash $ flutter pub add scratcher ``` -------------------------------- ### Declare Scratcher Dependency in pubspec.yaml Source: https://pub.dev/packages/scratcher/install This is an example of how the scratcher dependency will be added to your pubspec.yaml file. Your editor might automatically run 'flutter pub get' after this. ```yaml dependencies: scratcher: ^2.5.0 ``` -------------------------------- ### Initialize Scratch Card Demo Application Source: https://pub.dev/packages/scratcher/example Sets up a main entry point for a Flutter application using a tabbed interface to switch between advanced and basic scratch card implementations. ```dart import 'package:flutter/material.dart'; import 'advanced.dart'; import 'basic.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: DefaultTabController( length: 2, child: Scaffold( bottomNavigationBar: SafeArea( child: TabBar( labelColor: Colors.blueAccent, unselectedLabelColor: Colors.blueGrey, indicatorColor: Colors.blueAccent, indicatorSize: TabBarIndicatorSize.label, tabs: [ Tab(icon: Icon(Icons.looks_one)), Tab(icon: Icon(Icons.looks_two)), ], ), ), body: TabBarView( physics: const NeverScrollableScrollPhysics(), children: [ AdvancedScreen(), BasicScreen(), ], ), ), ), ); } } ``` -------------------------------- ### Programmatic Access to Scratcher Source: https://pub.dev/packages/scratcher Explains how to control the Scratcher widget programmatically using a GlobalKey. ```APIDOC ## Programmatic Access ### Description Control the Scratcher widget's state and actions programmatically by assigning a `GlobalKey` to it. ### Method Widget Declaration with GlobalKey and Method Calls ### Endpoint N/A (Flutter Widget) ### Parameters #### Widget Properties - **key** (GlobalKey) - Required - Assign a `GlobalKey` to the `Scratcher` widget to enable programmatic control. ### Request Example (Assigning Key) ```dart final scratchKey = GlobalKey(); Scratcher( key: scratchKey, // other properties... ) ``` ### Exposed Methods #### `reset` - **Description**: Resets the scratcher state to its initial values. - **Parameters**: - `duration` (Duration) - Optional - The duration for the reset animation. #### `reveal` - **Description**: Reveals the entire scratcher, displaying only the original child widget. ### Request Example (Calling Methods) ```dart RaisedButton( child: const Text('Reset'), onPressed: () { scratchKey.currentState.reset(duration: Duration(milliseconds: 2000)); }, ); RaisedButton( child: const Text('Reveal'), onPressed: () { scratchKey.currentState.reveal(); }, ); ``` ### Response #### Success Response (Method Execution) - **Void** - The methods do not return a value, but modify the state of the Scratcher widget. #### Response Example N/A (Method execution) ``` -------------------------------- ### Scratcher Widget Usage Source: https://pub.dev/packages/scratcher Demonstrates how to use the Scratcher widget to cover a child widget and configure its behavior. ```APIDOC ## Scratcher Widget ### Description A scratch card widget that temporarily hides content from the user, allowing them to reveal it through scratching. ### Method Widget Declaration ### Endpoint N/A (Flutter Widget) ### Parameters #### Widget Properties - **child** (Widget) - Required - The widget to be rendered under the scratch area. - **enabled** (bool) - Optional - Determines if new scratches can be applied. Defaults to true. - **threshold** (double) - Required - The percentage of the scratch area that must be revealed to trigger the `onThreshold` callback. - **brushSize** (double) - Optional - The size of the brush used for scratching. Larger values result in faster scratching. Defaults to a system-defined value. - **accuracy** (ScratchAccuracy) - Optional - Determines the accuracy of scratch progress reporting. Lower accuracy can improve performance. Defaults to a system-defined value. - **color** (Color) - Optional - The color used to cover the child widget. Use this or `image`. - **image** (Image) - Optional - An image widget used to cover the child widget. Use this or `color`. - **rebuildOnResize** (bool) - Optional - Determines if the scratcher should rebuild itself when space constraints change. Defaults to true. - **onChange** (Function) - Optional - A callback function that is invoked when the scratch progress changes (minimum 0.1% difference). - **onThreshold** (Function) - Optional - A callback function that is invoked when the `threshold` is reached. - **onScratchStart** (Function) - Optional - A callback function invoked when scratching begins. - **onScratchUpdate** (Function) - Optional - A callback function invoked during scratching. - **onScratchEnd** (Function) - Optional - A callback function invoked when scratching ends. ### Request Example ```dart Scratcher( brushSize: 30, threshold: 50, color: Colors.red, onChange: (value) => print("Scratch progress: $value%"), onThreshold: () => print("Threshold reached, you won!"), child: Container( height: 300, width: 300, color: Colors.blue, ), ) ``` ### Response #### Success Response (Widget Rendered) - **Rendered Widget** (Widget) - The Scratcher widget itself, displaying the covered child. #### Response Example N/A (Widget rendering) ``` -------------------------------- ### Implement the Scratcher widget Source: https://pub.dev/packages/scratcher Wrap a child widget with Scratcher to create a scratchable area with configurable brush size, threshold, and callbacks. ```dart Scratcher( brushSize: 30, threshold: 50, color: Colors.red, onChange: (value) => print("Scratch progress: $value%"), onThreshold: () => print("Threshold reached, you won!"), child: Container( height: 300, width: 300, color: Colors.blue, ), ) ``` -------------------------------- ### Control Scratcher programmatically Source: https://pub.dev/packages/scratcher Use a GlobalKey to access the ScratcherState and trigger methods like reset or reveal. ```dart final scratchKey = GlobalKey(); Scratcher( key: scratchKey, // remaining properties ) ``` ```dart RaisedButton( child: const Text('Reset'), onPressed: () { scratchKey.currentState.reset(duration: Duration(milliseconds: 2000)); }, ); ``` -------------------------------- ### Add dependency to pubspec.yaml Source: https://pub.dev/packages/scratcher Include the package in your project dependencies. ```yaml dependencies: scratcher: "^2.5.0" ``` -------------------------------- ### Static Analysis Warning Source: https://pub.dev/packages/scratcher/score A warning identified during static analysis regarding the usage of the loadImage method. ```dart ╷ 208 │ imageProvider.loadImage( │ ^^^^^^^^^ ╵ ``` -------------------------------- ### Import Scratcher Package in Dart Code Source: https://pub.dev/packages/scratcher/install Use this import statement in your Dart code to access the functionalities provided by the scratcher package. ```dart import 'package:scratcher/scratcher.dart'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.