From 8b2433455f4fa8e01bbf6915dc8ef89dae025301 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Wed, 18 Dec 2024 12:48:44 +0100 Subject: [PATCH] book: init flutter snippets Signed-off-by: Yuki Kishimoto --- .github/workflows/book.yml | 3 + book/snippets/flutter/.gitignore | 7 + book/snippets/flutter/analysis_options.yaml | 30 ++ book/snippets/flutter/justfile | 5 + book/snippets/flutter/lib/hello.dart | 25 + book/snippets/flutter/pubspec.lock | 486 ++++++++++++++++++++ book/snippets/flutter/pubspec.yaml | 17 + book/snippets/justfile | 5 +- book/src/sdk/hello.md | 20 +- 9 files changed, 592 insertions(+), 6 deletions(-) create mode 100644 book/snippets/flutter/.gitignore create mode 100644 book/snippets/flutter/analysis_options.yaml create mode 100644 book/snippets/flutter/justfile create mode 100644 book/snippets/flutter/lib/hello.dart create mode 100644 book/snippets/flutter/pubspec.lock create mode 100644 book/snippets/flutter/pubspec.yaml diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index 55d99d6be..afadaf90b 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -44,6 +44,9 @@ jobs: distribution: "temurin" java-version: 17 + # Required for dart/flutter snippets + - uses: subosito/flutter-action@v2 + - name: Check run: just check-book diff --git a/book/snippets/flutter/.gitignore b/book/snippets/flutter/.gitignore new file mode 100644 index 000000000..ca269e6dc --- /dev/null +++ b/book/snippets/flutter/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ +packages/ +.flutter-version +.flutter-plugins +.flutter-plugins-dependencies diff --git a/book/snippets/flutter/analysis_options.yaml b/book/snippets/flutter/analysis_options.yaml new file mode 100644 index 000000000..6dd972f3c --- /dev/null +++ b/book/snippets/flutter/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +analyzer: + exclude: + - packages/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/book/snippets/flutter/justfile b/book/snippets/flutter/justfile new file mode 100644 index 000000000..d64170c31 --- /dev/null +++ b/book/snippets/flutter/justfile @@ -0,0 +1,5 @@ +#!/usr/bin/env just --justfile + +test: + flutter pub get + dart analyze --fatal-infos diff --git a/book/snippets/flutter/lib/hello.dart b/book/snippets/flutter/lib/hello.dart new file mode 100644 index 000000000..b5eaaf794 --- /dev/null +++ b/book/snippets/flutter/lib/hello.dart @@ -0,0 +1,25 @@ +// ANCHOR: full + +import 'package:nostr_sdk/nostr_sdk.dart'; + +Future hello() async { + // ANCHOR: client + Keys keys = Keys.generate(); + NostrSigner signer = NostrSigner.keys(keys: keys); + Client client = Client.builder().signer(signer: signer).build(); + // ANCHOR_END: client + + // ANCHOR: connect + await client.addRelay(url: "wss://relay.damus.io"); + await client.connect(); + // ANCHOR_END: connect + + // ANCHOR: publish + // TODO + // ANCHOR_END: publish + + // ANCHOR: output + // TODO + // ANCHOR_END: output +} +// ANCHOR_END: full diff --git a/book/snippets/flutter/pubspec.lock b/book/snippets/flutter/pubspec.lock new file mode 100644 index 000000000..de0d749c5 --- /dev/null +++ b/book/snippets/flutter/pubspec.lock @@ -0,0 +1,486 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834 + url: "https://pub.dev" + source: hosted + version: "72.0.0" + _macros: + dependency: transitive + description: dart + source: sdk + version: "0.3.2" + analyzer: + dependency: transitive + description: + name: analyzer + sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139 + url: "https://pub.dev" + source: hosted + version: "6.7.0" + args: + dependency: transitive + description: + name: args + sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 + url: "https://pub.dev" + source: hosted + version: "2.6.0" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + build_cli_annotations: + dependency: transitive + description: + name: build_cli_annotations + sha256: b59d2769769efd6c9ff6d4c4cede0be115a566afc591705c2040b707534b1172 + url: "https://pub.dev" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + coverage: + dependency: transitive + description: + name: coverage + sha256: e3493833ea012784c740e341952298f1cc77f1f01b1bbc3eb4eecf6984fb7f43 + url: "https://pub.dev" + source: hosted + version: "1.11.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + file: + dependency: transitive + description: + name: file + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + url: "https://pub.dev" + source: hosted + version: "7.0.1" + flutter: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + flutter_rust_bridge: + dependency: transitive + description: + name: flutter_rust_bridge + sha256: f703c4b50e253e53efc604d50281bbaefe82d615856f8ae1e7625518ae252e98 + url: "https://pub.dev" + source: hosted + version: "2.0.0" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + url: "https://pub.dev" + source: hosted + version: "2.4.4" + frontend_server_client: + dependency: transitive + description: + name: frontend_server_client + sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694 + url: "https://pub.dev" + source: hosted + version: "4.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + http_multi_server: + dependency: transitive + description: + name: http_multi_server + sha256: aa6199f908078bb1c5efb8d8638d4ae191aac11b311132c3ef48ce352fb52ef8 + url: "https://pub.dev" + source: hosted + version: "3.2.2" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + io: + dependency: transitive + description: + name: io + sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b + url: "https://pub.dev" + source: hosted + version: "1.0.5" + js: + dependency: transitive + description: + name: js + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + url: "https://pub.dev" + source: hosted + version: "0.7.1" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + lints: + dependency: "direct dev" + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" + macros: + dependency: transitive + description: + name: macros + sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" + url: "https://pub.dev" + source: hosted + version: "0.1.2-main.4" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" + source: hosted + version: "0.11.1" + meta: + dependency: transitive + description: + name: meta + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" + source: hosted + version: "1.15.0" + mime: + dependency: transitive + description: + name: mime + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + url: "https://pub.dev" + source: hosted + version: "2.0.0" + node_preamble: + dependency: transitive + description: + name: node_preamble + sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db" + url: "https://pub.dev" + source: hosted + version: "2.0.2" + nostr_sdk: + dependency: "direct main" + description: + path: "." + ref: deb74a974fa0a767b91adc7b88eae5495d94931e + resolved-ref: deb74a974fa0a767b91adc7b88eae5495d94931e + url: "https://github.com/rust-nostr/nostr-sdk-flutter.git" + source: git + version: "0.37.0" + package_config: + dependency: transitive + description: + name: package_config + sha256: "92d4488434b520a62570293fbd33bb556c7d49230791c1b4bbd973baf6d2dc67" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" + pool: + dependency: transitive + description: + name: pool + sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" + url: "https://pub.dev" + source: hosted + version: "1.5.1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "7b3cfbf654f3edd0c6298ecd5be782ce997ddf0e00531b9464b55245185bbbbd" + url: "https://pub.dev" + source: hosted + version: "2.1.5" + shelf: + dependency: transitive + description: + name: shelf + sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 + url: "https://pub.dev" + source: hosted + version: "1.4.1" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + shelf_static: + dependency: transitive + description: + name: shelf_static + sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3 + url: "https://pub.dev" + source: hosted + version: "1.1.3" + shelf_web_socket: + dependency: transitive + description: + name: shelf_web_socket + sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b + url: "https://pub.dev" + source: hosted + version: "2.1.2" + source_maps: + dependency: transitive + description: + name: source_maps + sha256: "190222579a448b03896e0ca6eca5998fa810fda630c1d65e2f78b3f638f54812" + url: "https://pub.dev" + source: hosted + version: "0.10.13" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test: + dependency: "direct dev" + description: + name: test + sha256: "43490fe4c0f5ecb898f3fa1cdcdad8d521d7f6ff17ebdc4e8cd32b2e99524a20" + url: "https://pub.dev" + source: hosted + version: "1.25.13" + test_api: + dependency: transitive + description: + name: test_api + sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd + url: "https://pub.dev" + source: hosted + version: "0.7.4" + test_core: + dependency: transitive + description: + name: test_core + sha256: "84d17c3486c8dfdbe5e12a50c8ae176d15e2a771b96909a9442b40173649ccaa" + url: "https://pub.dev" + source: hosted + version: "0.6.8" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + url: "https://pub.dev" + source: hosted + version: "14.2.5" + watcher: + dependency: transitive + description: + name: watcher + sha256: "69da27e49efa56a15f8afe8f4438c4ec02eff0a117df1b22ea4aad194fe1c104" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" + url: "https://pub.dev" + source: hosted + version: "0.1.6" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" + url: "https://pub.dev" + source: hosted + version: "3.0.1" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + yaml: + dependency: transitive + description: + name: yaml + sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" + url: "https://pub.dev" + source: hosted + version: "3.1.2" +sdks: + dart: ">=3.5.3 <4.0.0" + flutter: ">=3.3.0" diff --git a/book/snippets/flutter/pubspec.yaml b/book/snippets/flutter/pubspec.yaml new file mode 100644 index 000000000..667576acd --- /dev/null +++ b/book/snippets/flutter/pubspec.yaml @@ -0,0 +1,17 @@ +name: nostr_sdk_snippets_flutter +description: "A sample command-line application." +version: 1.0.0 +publish_to: 'none' + +environment: + sdk: '>=3.0.0 <4.0.0' + +dependencies: + nostr_sdk: + git: + url: https://github.com/rust-nostr/nostr-sdk-flutter.git + ref: deb74a974fa0a767b91adc7b88eae5495d94931e + +dev_dependencies: + lints: ^3.0.0 + test: ^1.24.9 diff --git a/book/snippets/justfile b/book/snippets/justfile index 3341c41a1..754116fb6 100644 --- a/book/snippets/justfile +++ b/book/snippets/justfile @@ -1,4 +1,4 @@ -test: rust python js kotlin swift +test: rust python js kotlin flutter swift rust: cd rust && cargo build @@ -12,5 +12,8 @@ js: kotlin: cd kotlin && just test +flutter: + cd flutter && just test + swift: cd swift && just test diff --git a/book/src/sdk/hello.md b/book/src/sdk/hello.md index c7b22fb29..74d099a5f 100644 --- a/book/src/sdk/hello.md +++ b/book/src/sdk/hello.md @@ -55,7 +55,9 @@ The first step is to generate random keys needed for the client and construct th
Flutter
-TODO +```dart,ignore +{{#include ../../snippets/flutter/lib/hello.dart:client}} +```
@@ -113,7 +115,9 @@ Next, add some relays to your client and connect to them.
Flutter
-TODO +```dart,ignore +{{#include ../../snippets/flutter/lib/hello.dart:connect}} +```
@@ -173,7 +177,9 @@ build a text note with the [EventBuilder](event/builder.md) and publish it to re
Flutter
-TODO +```dart,ignore +{{#include ../../snippets/flutter/lib/hello.dart:publish}} +```
@@ -231,7 +237,9 @@ Published the event, you can inspect the output to ensure everything worked corr
Flutter
-TODO +```dart,ignore +{{#include ../../snippets/flutter/lib/hello.dart:output}} +```
@@ -289,7 +297,9 @@ Here’s the full example that includes all the steps from generating keys to in
Flutter
-TODO +```dart,ignore +{{#include ../../snippets/flutter/lib/hello.dart:full}} +```