### Solid CLI Usage Examples Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/getting-started.mdx Demonstrates various command-line usages for the Solid transpilation tool, including basic transpilation, enabling watch mode for auto-regeneration, and cleaning the build cache with verbose output. ```sh Usage: solid [options] -s, --source Source directory to read from (defaults to "source") -o, --output Output directory to write to (defaults to "lib") -w, --[no-]watch Watch for file changes and auto-regenerate -c, --[no-]clean Deletes the build cache. The next build will be a full build. -v, --[no-]verbose Verbose output -h, --[no-]help Show this help message Examples: solid # Basic transpilation solid --watch # Watch mode solid --clean --verbose # Clean build with verbose output ``` -------------------------------- ### Install Solid Generator CLI Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/getting-started.mdx Installs the Solid code generator command-line interface globally. This tool is essential for generating boilerplate code in your Flutter projects. ```bash dart pub global activate solid_generator ``` -------------------------------- ### Add Very Good Analysis to Flutter Project Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/getting-started.mdx Installs the 'very_good_analysis' package as a development dependency to enforce strong linting rules in your Flutter project. It also shows how to include its configuration in your analysis_options.yaml. ```bash flutter pub add dev:very_good_analysis ``` -------------------------------- ### Create Astro Project with Starlight Template Source: https://github.com/nank1ro/solid/blob/main/docs/README.md This command initializes a new Astro project using the Starlight template. It requires Node.js and npm to be installed. The command will prompt for project name and potentially other configuration options. ```bash npm create astro@latest -- --template starlight ``` -------------------------------- ### Configure Very Good Analysis in analysis_options.yaml Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/getting-started.mdx Configures the 'very_good_analysis' package in your Flutter project's 'analysis_options.yaml' file. This example includes disabling specific linter rules to accommodate Solid's code generation pattern. ```yaml include: package:very_good_analysis/very_good_analysis.yaml analyzer: errors: must_be_immutable: ignore # Ignore immutability rule, because Solid generates immutable classes but you write mutable ones linter: rules: public_member_api_docs: false # Disable documentation requirement for public members ``` -------------------------------- ### Add Solid Flutter Dependencies Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/getting-started.mdx Adds the necessary Solid annotations and state management library dependencies to your Flutter project using Flutter's package manager. ```bash flutter pub add solid_annotations flutter_solidart ``` -------------------------------- ### Astro Project Management Commands Source: https://github.com/nank1ro/solid/blob/main/docs/README.md This table lists common npm commands for managing an Astro project. These commands are executed from the project's root directory and cover dependency installation, local development server, production builds, and previewing. ```bash npm install ``` ```bash npm run dev ``` ```bash npm run build ``` ```bash npm run preview ``` ```bash npm run astro ... ``` ```bash npm run astro -- --help ``` -------------------------------- ### Signal and Computed Examples in flutter_solidart Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/faq.mdx Demonstrates the basic usage of Signals for mutable state and Computed for derived state in the flutter_solidart library. This showcases Solid's approach to reactivity. ```dart final counter = Signal(0); late final doubleCounter = Computed(() => counter.value * 2); ``` -------------------------------- ### Simple @SolidQuery for Async Data Fetching (Dart) Source: https://context7.com/nank1ro/solid/llms.txt Illustrates a basic @SolidQuery setup for fetching data asynchronously. It transforms a method returning a Future into a managed resource, automatically handling loading, ready, and error states using the .when() extension. No external dependencies are required for this basic functionality. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; import 'package:solid_annotations/extensions.dart'; class QueryExample extends StatelessWidget { const QueryExample({super.key}); // Simple query without dependencies @SolidQuery() Future fetchData() async { await Future.delayed(const Duration(seconds: 1)); return 'Fetched Data'; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Query')), body: Center( // .when() extension handles all states child: fetchData().when( ready: (data) => Text(data), loading: () => const CircularProgressIndicator(), error: (error, stackTrace) => Text('Error: $error'), ), ), ); } } ``` -------------------------------- ### Inline Provider Setup using Widget.environment Extension in Dart Source: https://context7.com/nank1ro/solid/llms.txt Shows how to wrap a widget with a `SolidProvider` inline using the `environment()` extension method. This provides a concise way to inject dependencies directly where they are needed, simplifying widget tree construction. The `notifyUpdate` parameter controls whether the provider re-renders. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/extensions.dart'; class ApiClient { final String baseUrl; ApiClient(this.baseUrl); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { // Wrap MaterialApp with provider using extension return MaterialApp( home: HomePage(), ).environment( (context) => ApiClient('https://api.example.com'), notifyUpdate: (oldWidget) => false, ); } } ``` -------------------------------- ### Dart Effect Example Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/effect.mdx Demonstrates a reactive effect in Dart using Solid. The @SolidEffect() annotation triggers the logCounter function whenever the 'counter' state variable changes. This example includes a basic UI with a counter and a button to increment it. ```dart class EffectExample extends StatelessWidget { EffectExample({super.key}); @SolidState() int counter = 0; @SolidEffect() void logCounter() { print('Counter changed: $counter'); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Effect')), body: Center(child: Text('Counter: $counter')), floatingActionButton: FloatingActionButton( onPressed: () => counter++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Solid Framework Counter Example in Dart Source: https://github.com/nank1ro/solid/blob/main/packages/solid_generator/README.md This Dart code snippet demonstrates a basic Counter widget using the Solid Framework. It utilizes the `@SolidState()` annotation for state management and showcases how Solid automatically handles UI updates only for the parts of the widget that depend on the changed state. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; class Counter extends StatelessWidget { Counter({super.key}); @SolidState() int counter = 0; @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Text('Date: ${DateTime.now()}'), Text('Counter is $counter'), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () => counter++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Dart: Fetch asynchronous data with @SolidQuery Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/query.mdx This example demonstrates how to use the @SolidQuery() annotation to fetch asynchronous data. It simulates network fetching with a delay and handles the data states (ready, loading, error) using the .when() method. This is useful for displaying data from APIs or other async sources. ```dart class QueryExample extends StatelessWidget { const QueryExample({super.key}); @SolidQuery() Future fetchData() async { await Future.delayed(const Duration(seconds: 1)); return 'Fetched Data'; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Query')), body: Center( child: fetchData().when( ready: (data) => Text(data), loading: () => CircularProgressIndicator(), error: (error, stackTrace) => Text('Error: $error'), ), ), ); } } ``` -------------------------------- ### @SolidQuery with Reactive Sources and Debouncing (Dart) Source: https://context7.com/nank1ro/solid/llms.txt Demonstrates how @SolidQuery can automatically re-fetch data when `@SolidState` dependencies change. This example utilizes debouncing to limit the frequency of data fetching requests, making it efficient for user interactions. It handles cases where a reactive source might be null. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; import 'package:solid_annotations/extensions.dart'; class QueryWithSourceExample extends StatelessWidget { QueryWithSourceExample({super.key}); @SolidState() String? userId; // Query reruns when userId changes, with 1-second debounce @SolidQuery(debounce: Duration(seconds: 1)) Future fetchData() async { if (userId == null) return null; await Future.delayed(const Duration(seconds: 1)); return 'Fetched Data for $userId'; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('QueryWithSource')), body: Center( child: fetchData().when( ready: (data) => data == null ? const Text('No user ID provided') : Text(data), loading: () => const CircularProgressIndicator(), error: (error, stackTrace) => Text('Error: $error'), ), ), floatingActionButton: FloatingActionButton( onPressed: () => userId = 'user_${DateTime.now().millisecondsSinceEpoch}', child: const Icon(Icons.refresh), ), ); } } ``` -------------------------------- ### Dart: Manually refresh a query Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/query.mdx This example demonstrates how to manually trigger a data refresh for a query by calling its `refresh` method. This is useful for providing users with an explicit way to update data on demand, complementing automatic refresh mechanisms. ```dart fetchData.refresh(); ``` -------------------------------- ### Create Reactive State with @SolidState() in Dart Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/state.mdx Demonstrates how to declare a reactive state variable using the @SolidState() annotation in a Dart widget. When the variable changes, UI elements depending on it update automatically. This example shows a simple counter that increments on button press. ```dart import 'package:solid_annotations/solid_annotations.dart'; import 'package:flutter/material.dart'; class Counter extends StatelessWidget { Counter({super.key}); @SolidState() int counter = 0; @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Text('Counter is $counter'), ), floatingActionButton: FloatingActionButton( onPressed: () => counter++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Flutter Counter Example with Solid Framework Annotations Source: https://github.com/nank1ro/solid/blob/main/packages/solid_annotations/README.md This Dart code snippet demonstrates a basic counter component in Flutter using the Solid Framework. It utilizes the `@SolidState()` annotation to manage the counter's state, enabling fine-grained reactivity. The `FloatingActionButton` increments the counter, and only the text displaying the counter value updates, showcasing Solid's efficient UI updates. Dependencies include `flutter/material.dart` and `solid_annotations/solid_annotations.dart`. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; class Counter extends StatelessWidget { Counter({super.key}); @SolidState() int counter = 0; @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Text('Date: ${DateTime.now()}'), Text('Counter is $counter'), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () => counter++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Dart: React to state changes with debounced @SolidQuery Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/query.mdx This example illustrates how a query can depend on reactive state variables, such as `userId`. When `userId` changes, the `fetchData` query is automatically re-executed. The `debounce` parameter is used to limit how often the query is triggered after changes, improving performance by preventing excessive calls. ```dart class QueryWithSourceExample extends StatelessWidget { QueryWithSourceExample({super.key}); @SolidState() String? userId; @SolidQuery(debounce: Duration(seconds: 1)) Future fetchData() async { if (userId == null) return null; await Future.delayed(const Duration(seconds: 1)); return 'Fetched Data for $userId'; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('QueryWithSource')), body: Center( child: fetchData().when( ready: (data) { if (data == null) { return const Text('No user ID provided'); } return Text(data); }, loading: () => CircularProgressIndicator(), error: (error, stackTrace) => Text('Error: $error'), ), ), floatingActionButton: FloatingActionButton( onPressed: () => userId = 'user_${DateTime.now().millisecondsSinceEpoch}', child: const Icon(Icons.refresh), ), ); } } ``` -------------------------------- ### Side Effect Management with @SolidEffect in Flutter Source: https://context7.com/nank1ro/solid/llms.txt Shows how to use the @SolidEffect annotation for managing side effects in Flutter. Methods annotated with @SolidEffect act as reactive effects that automatically re-run whenever the signals they depend on change. This example logs the counter's value to the console whenever it is incremented. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; class EffectExample extends StatelessWidget { EffectExample({super.key}); @SolidState() int counter = 0; // Method becomes Effect that runs on counter changes @SolidEffect() void logCounter() { // Automatically tracks dependency on 'counter' print('Counter changed: $counter'); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Effect')), body: Center(child: Text('Counter: $counter')), floatingActionButton: FloatingActionButton( onPressed: () => counter++, // Triggers logCounter() child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Create Derived State with @SolidState() in Dart Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/state.mdx Illustrates how to create computed properties (derived state) in Solid using the @SolidState() annotation on a getter. The getter's value is computed based on other reactive state variables and automatically updates when dependencies change. This example shows a derived 'doubleCounter'. ```dart class Counter extends StatelessWidget { Counter({super.key}); @SolidState() int counter = 0; @SolidState() int get doubleCounter => counter * 2; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Computed')), body: Center( child: Text('Counter: $counter, DoubleCounter: $doubleCounter'), ), floatingActionButton: FloatingActionButton( onPressed: () => counter++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Reactive State Management with @SolidState in Flutter Source: https://context7.com/nank1ro/solid/llms.txt Demonstrates how to use the @SolidState annotation to declare reactive state variables in Flutter. Fields annotated with @SolidState are transformed into Signals for mutable state, and UI components depending on them are automatically wrapped for fine-grained reactivity. This example shows a simple counter where only the text displaying the counter value updates. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; class CounterPage extends StatelessWidget { CounterPage({super.key}); // Field becomes Signal @SolidState(name: 'customName') int counter = 0; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('State Example')), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // This Text widget does NOT update when counter changes Text(DateTime.now().toString()), // Only this Text widget updates when counter changes Text('Counter: $counter'), ElevatedButton( onPressed: () => counter++, child: const Text('Increment'), ), ], ), ), ); } } ``` -------------------------------- ### Derived State with @SolidState Getters in Flutter Source: https://context7.com/nank1ro/solid/llms.txt Illustrates using the @SolidState annotation on getters to create derived, reactive state in Flutter. Getters annotated with @SolidState are transformed into Computed values that automatically recalculate when their dependencies change. The example shows a computed value 'doubleCounter' that updates whenever the 'counter' signal changes. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; class ComputedExample extends StatelessWidget { ComputedExample({super.key}); @SolidState() int counter = 0; // Getter becomes Computed @SolidState() int get doubleCounter => counter * 2; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Computed')), body: Center( // Both counter and doubleCounter automatically update child: Text('Counter: $counter, DoubleCounter: $doubleCounter'), ), floatingActionButton: FloatingActionButton( onPressed: () => counter++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Starlight Project Structure Overview Source: https://github.com/nank1ro/solid/blob/main/docs/README.md This illustrates the typical directory structure of an Astro project configured with Starlight. Key directories include `public/` for static assets, `src/content/docs/` for Markdown documentation, and configuration files like `astro.config.mjs`. ```treeview .\n├── public/\n├── src/\n│ ├── assets/\n│ ├── content/\n│ │ └── docs/\n│ └── content.config.ts\n├── astro.config.mjs\n├── package.json\n└── tsconfig.json ``` -------------------------------- ### Provide Counter Instance with environment Extension Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/environment.mdx This Dart code shows an alternative way to provide a `Counter` instance using the `environment` extension. This method is concise for setting up environment providers. ```dart class EnvironmentExample extends StatelessWidget { const EnvironmentExample({super.key}); @override Widget build(BuildContext context) { return EnvironmentInjectionExample.environment((context) => Counter()); } } ``` -------------------------------- ### @SolidQuery with Streams and Manual Refresh (Dart) Source: https://context7.com/nank1ro/solid/llms.txt Shows how to use @SolidQuery with methods returning Streams for real-time data updates. It includes support for manual refresh using the `.refresh()` extension and demonstrates how the `useRefreshing` parameter affects the loading state during refresh. Reactive sources also trigger stream re-subscription. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; import 'package:solid_annotations/extensions.dart'; class QueryWithStreamAndSourceExample extends StatelessWidget { QueryWithStreamAndSourceExample({super.key}); @SolidState() int multiplier = 1; // Stream query with reactive source, enters loading on refresh @SolidQuery(useRefreshing: false) Stream fetchData() { return Stream.periodic( const Duration(seconds: 1), (i) => i * multiplier ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('QueryWithStream')), body: Center( child: Column( children: [ // Check refreshing state Text('Is refreshing: ${fetchData().isRefreshing}'), fetchData().when( ready: (data) => Text(data.toString()), loading: CircularProgressIndicator.new, error: (error, stackTrace) => Text('Error: $error'), ), ElevatedButton( // Manual refresh triggers re-subscription onPressed: fetchData.refresh, child: const Text('Manual Refresh'), ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () => multiplier++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Build Configuration for Multiple Generators Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/faq.mdx This `build.yaml` configuration allows Solid to process code from the 'source' directory alongside other code generators. It ensures that the 'source' directory is included in the build process, enabling seamless integration. ```yaml targets: $default: sources: - lib/** - $package$ - source/** ``` -------------------------------- ### Provide Counter Instance with SolidProvider Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/environment.mdx This Dart code demonstrates how to provide an instance of the `Counter` class using the `SolidProvider` widget. It sets up the dependency injection tree for descendant widgets. ```dart class EnvironmentExample extends StatelessWidget { const EnvironmentExample({super.key}); @override Widget build(BuildContext context) { return SolidProvider( create: (context) => Counter(), child: EnvironmentInjectionExample(), ); } } ``` -------------------------------- ### Access Providers using BuildContext Extensions in Dart Source: https://context7.com/nank1ro/solid/llms.txt Demonstrates accessing provider data from BuildContext using extension methods like `read`, `watch`, `maybeRead`, and `maybeWatch`. These methods provide convenient access to registered providers, with `watch` and `maybeWatch` enabling reactive updates. They are part of the `solid_annotations` package. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/provider.dart'; import 'package:solid_annotations/extensions.dart'; class UserService { String get userName => 'John Doe'; } class ProfilePage extends StatelessWidget { @override Widget build(BuildContext context) { // Read without listening (one-time access) final service = context.read(); // Watch for updates (rebuilds when notified) final watchedService = context.watch(); // Safe variants that return null if not found final maybeService = context.maybeRead(); final maybeWatched = context.maybeWatch(); return Scaffold( body: Center( child: Column( children: [ Text('User: ${service.userName}'), if (maybeService != null) Text('Optional: ${maybeService.userName}'), ], ), ), ); } } ``` -------------------------------- ### Dependency Injection with @SolidEnvironment - Dart Source: https://context7.com/nank1ro/solid/llms.txt Demonstrates how to use the @SolidEnvironment annotation to inject dependencies managed by SolidProvider. Injected objects with a dispose() method are automatically cleaned up. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; import 'package:solid_annotations/provider.dart'; class ACustomClassWithSolidState { @SolidState() int value = 0; void dispose() { print('ACustomClass disposed'); } } class EnvironmentExample extends StatelessWidget { const EnvironmentExample({super.key}); @override Widget build(BuildContext context) { return SolidProvider( create: (context) => ACustomClassWithSolidState(), child: EnvironmentInjectionExample(), ); } } class EnvironmentInjectionExample extends StatelessWidget { EnvironmentInjectionExample({super.key}); // Automatically injected from nearest SolidProvider @SolidEnvironment() late ACustomClassWithSolidState myData; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Environment')), body: Center(child: Text(myData.value.toString())), floatingActionButton: FloatingActionButton( onPressed: () => myData.value++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### SolidProvider for Data Provision - Dart Source: https://context7.com/nank1ro/solid/llms.txt Shows how to use SolidProvider to supply data of a specific type T to its widget descendants. It automatically handles disposal of provided data and offers methods for accessing the data within child widgets. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/provider.dart'; import 'package:solid_annotations/extensions.dart'; class MyService { final String apiKey; MyService(this.apiKey); void dispose() { print('MyService disposed'); } } class AppRoot extends StatelessWidget { const AppRoot({super.key}); @override Widget build(BuildContext context) { return SolidProvider( create: (context) => MyService('api-key-123'), child: MaterialApp( home: MyHomePage(), ), ); } } class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { // Access provider data with listen=false (no rebuilds) final service = context.read(); // Or with listen=true (rebuilds on updates) final watchedService = context.watch(); // Or use static method final service2 = SolidProvider.of(context, listen: false); return Scaffold( body: Center( child: Text('API Key: ${service.apiKey}'), ), ); } } ``` -------------------------------- ### Async State Handling with Future/Stream Extensions - Dart Source: https://context7.com/nank1ro/solid/llms.txt Utilizes extension methods on Future and Stream to manage asynchronous states within the UI. The `.when()` and `.maybeWhen()` methods simplify handling loading, ready, and error states. ```dart import 'package:flutter/material.dart'; import 'package:solid_annotations/solid_annotations.dart'; import 'package:solid_annotations/extensions.dart'; class QueryWithMultipleSourcesExample extends StatelessWidget { QueryWithMultipleSourcesExample({super.key}); @SolidState() String? userId; @SolidState() String? authToken; @SolidQuery() Future fetchData() async { if (userId == null || authToken == null) return null; await Future.delayed(const Duration(seconds: 1)); return 'Fetched Data for $userId'; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('QueryWithMultipleSources')), body: Center( child: Column( spacing: 8, children: [ const Text('Complex SolidQuery example'), // Handle all states with .when() fetchData().when( ready: (data) => data == null ? const Text('No user ID provided') : Text(data), loading: () => const CircularProgressIndicator(), error: (error, stackTrace) => Text('Error: $error'), ), // Or use .maybeWhen() with optional handlers fetchData().maybeWhen( ready: (data) => Text('Data: $data'), orElse: () => const Text('Loading or error...'), ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () { userId = 'user_${DateTime.now().millisecondsSinceEpoch}'; authToken = 'token_${DateTime.now().millisecondsSinceEpoch}'; }, child: const Icon(Icons.refresh), ), ); } } ``` -------------------------------- ### Dart: Fetch stream data with @SolidQuery Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/query.mdx This snippet shows how to use the @SolidQuery() annotation with streams to handle real-time data updates. The query automatically reacts to new data emitted by the stream, making it suitable for scenarios like live feeds or continuously updating data. ```dart @SolidQuery() Stream fetchData() { return Stream.periodic(const Duration(seconds: 1), (i) => i); } ``` -------------------------------- ### Astro Component for Author Card Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/author.mdx This Astro component renders an author card, displaying the author's image, name, and links to their GitHub and Twitter profiles. It utilizes Starlight's Card and CardGrid components for layout. ```astro import { Card, CardGrid } from '@astrojs/starlight/components'; import AuthorCard from '../../components/AuthorCard.astro'; ``` -------------------------------- ### Inject Counter Instance with @Environment Annotation Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/environment.mdx This Dart code illustrates how to inject an instance of `Counter` into a `StatelessWidget` using the `@Environment()` annotation. It then utilizes the injected `counter` to display its value and allow incrementing it. ```dart class EnvironmentInjectionExample extends StatelessWidget { EnvironmentInjectionExample({super.key}); @Environment() late Counter counter; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Environment')), body: Center(child: Text(counter.value.toString())), floatingActionButton: FloatingActionButton( onPressed: () => counter.value++, child: const Icon(Icons.add), ), ); } } ``` -------------------------------- ### Counter Class with SolidState Annotation Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/environment.mdx This Dart code defines a simple `Counter` class with an integer `value` annotated with `@SolidState()`. This indicates that the `value` property should be managed reactively by Solid. ```dart class Counter { @SolidState() int value = 0; } ``` -------------------------------- ### Configure Analyzer for Immutable Widgets Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/faq.mdx This YAML snippet configures the Dart analyzer to ignore the 'must_be_immutable' error. This is useful when developing StatelessWidget in Solid, as the code generator ensures immutability in the compiled output, reducing boilerplate. ```yaml analyzer: errors: must_be_immutable: ignore ``` -------------------------------- ### Dart: Detect query refreshing state Source: https://github.com/nank1ro/solid/blob/main/docs/src/content/docs/guides/query.mdx This code snippet shows how to check if a query is currently refreshing its data using the `isRefreshing` property. This allows for UI adjustments, like showing a subtle loading indicator, without interrupting the current view. The behavior can be disabled by setting `useRefreshing` to `false` in the `@SolidQuery` annotation. ```dart fetchData().isRefreshing ``` ```dart @SolidQuery(useRefreshing: false) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.