├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .metadata
├── CHANGELOG.md
├── LICENSE
├── Makefile
├── README.md
├── analysis_options.yaml
├── example
├── .gitignore
├── .metadata
├── README.md
├── android
│ ├── .gitignore
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ │ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── kotlin
│ │ │ │ └── com
│ │ │ │ │ └── example
│ │ │ │ │ └── example
│ │ │ │ │ └── MainActivity.kt
│ │ │ └── res
│ │ │ │ ├── drawable
│ │ │ │ └── launch_background.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ └── values
│ │ │ │ └── styles.xml
│ │ │ └── profile
│ │ │ └── AndroidManifest.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ └── settings.gradle
├── ios
│ ├── .gitignore
│ ├── Flutter
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ └── Release.xcconfig
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Runner.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ │ └── WorkspaceSettings.xcsettings
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ └── WorkspaceSettings.xcsettings
│ └── Runner
│ │ ├── AppDelegate.swift
│ │ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ ├── Contents.json
│ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ ├── Icon-App-20x20@1x.png
│ │ │ ├── Icon-App-20x20@2x.png
│ │ │ ├── Icon-App-20x20@3x.png
│ │ │ ├── Icon-App-29x29@1x.png
│ │ │ ├── Icon-App-29x29@2x.png
│ │ │ ├── Icon-App-29x29@3x.png
│ │ │ ├── Icon-App-40x40@1x.png
│ │ │ ├── Icon-App-40x40@2x.png
│ │ │ ├── Icon-App-40x40@3x.png
│ │ │ ├── Icon-App-60x60@2x.png
│ │ │ ├── Icon-App-60x60@3x.png
│ │ │ ├── Icon-App-76x76@1x.png
│ │ │ ├── Icon-App-76x76@2x.png
│ │ │ └── Icon-App-83.5x83.5@2x.png
│ │ └── LaunchImage.imageset
│ │ │ ├── Contents.json
│ │ │ ├── LaunchImage.png
│ │ │ ├── LaunchImage@2x.png
│ │ │ ├── LaunchImage@3x.png
│ │ │ └── README.md
│ │ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ │ ├── Info.plist
│ │ └── Runner-Bridging-Header.h
├── lib
│ └── main.dart
├── pubspec.lock
├── pubspec.yaml
├── test
│ └── widget_test.dart
└── web
│ ├── favicon.png
│ ├── icons
│ ├── Icon-192.png
│ └── Icon-512.png
│ ├── index.html
│ └── manifest.json
├── lib
├── org_flutter.dart
└── src
│ ├── controller.dart
│ ├── entity.dart
│ ├── error.dart
│ ├── events.dart
│ ├── flash.dart
│ ├── folding.dart
│ ├── highlight.dart
│ ├── indent.dart
│ ├── locatable.dart
│ ├── locator.dart
│ ├── search.dart
│ ├── settings.dart
│ ├── span.dart
│ ├── theme.dart
│ ├── util
│ ├── alignment.dart
│ ├── bidi.dart
│ ├── collection.dart
│ ├── elisp.dart
│ ├── keywords.dart
│ ├── local_variables.dart
│ ├── locale.dart
│ ├── text.dart
│ ├── util.dart
│ ├── value_notifier.dart
│ └── widget.dart
│ ├── widget
│ ├── org_block.dart
│ ├── org_comment.dart
│ ├── org_content.dart
│ ├── org_decrypted_content.dart
│ ├── org_document.dart
│ ├── org_drawer.dart
│ ├── org_dynamic_block.dart
│ ├── org_fixed_width_area.dart
│ ├── org_footnote_reference.dart
│ ├── org_headline.dart
│ ├── org_horizontal_rule.dart
│ ├── org_inline_src_block.dart
│ ├── org_latex_block.dart
│ ├── org_latex_inline.dart
│ ├── org_link.dart
│ ├── org_link_target.dart
│ ├── org_list.dart
│ ├── org_local_variables.dart
│ ├── org_meta.dart
│ ├── org_paragraph.dart
│ ├── org_pgp_block.dart
│ ├── org_property.dart
│ ├── org_radio_target.dart
│ ├── org_root.dart
│ ├── org_section.dart
│ ├── org_sub_superscript.dart
│ ├── org_table.dart
│ └── org_theme.dart
│ └── widgets.dart
├── pubspec.lock
├── pubspec.yaml
└── test
├── alignment_test.dart
├── bidi_test.dart
├── elisp_test.dart
├── local_variables_test.dart
├── locale_test.dart
├── text_test.dart
└── widget
├── basic_test.dart
├── entities_test.dart
├── events_test.dart
├── footnotes_test.dart
├── headline_test.dart
├── images_test.dart
├── keyword_settings_test.dart
├── link_target_test.dart
├── local_variables_test.dart
├── meta_test.dart
├── named_element_test.dart
├── org-manual.org
├── org_attach_id_dir_test.dart
├── prettification_test.dart
├── radio_link_test.dart
├── search_test.dart
├── section_matcher_test.dart
├── state_restoration_test.dart
├── sub_superscript_test.dart
├── text_changes_test.dart
├── util.dart
└── visibility_cycling_test.dart
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Flutter CI
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v4
16 | - uses: subosito/flutter-action@v2
17 | with:
18 | channel: stable
19 | - name: Install dependencies
20 | run: flutter pub get
21 | - name: Analyze
22 | run: flutter analyze
23 | - name: Run tests
24 | run: make test
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | .dart_tool/
26 | .flutter-plugins
27 | .flutter-plugins-dependencies
28 | .packages
29 | .pub-cache/
30 | .pub/
31 | build/
32 |
33 | # Web related
34 | lib/generated_plugin_registrant.dart
35 |
36 | # Exceptions to above rules.
37 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
38 |
39 | *~
40 | /tmp
41 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 659dc8129d4edb9166e9a0d600439d135740933f
8 | channel: beta
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright © 2020 Aaron Madlon-Kay
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the “Software”), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | git_hash = $(shell git rev-parse --short HEAD)
2 | gold_dir = $(PWD)/tmp/$(git_hash)
3 |
4 | .PHONY: test
5 | test: ## Run all tests
6 | test: test-unit test-example
7 |
8 | .PHONY: test-unit
9 | test-unit: ## Run unit tests
10 | flutter test
11 |
12 | .PHONY: test-example
13 | test-example: ## Run example tests
14 | cd example && flutter test
15 |
16 | .PHONY: screenshot
17 | screenshot: ## Manually dump screenshots for layout testing purposes
18 | rm -rf $(gold_dir)
19 | flutter test --dart-define=GOLD_DIR=$(gold_dir) --plain-name 'Screenshot' --update-goldens --run-skipped
20 | # Screenshot of entire document is so big that most viewers can't handle it, so
21 | # we split it into 20 parts
22 | cd $(gold_dir) && for f in *.png; do convert -crop 1x20@ +repage $$f $${f%%.png}-%d.png; done
23 |
24 | .PHONY: help
25 | help: ## Show this help text
26 | $(info usage: make [target])
27 | $(info )
28 | $(info Available targets:)
29 | @awk -F ':.*?## *' '/^[^\t].+?:.*?##/ \
30 | {printf " %-24s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # org_flutter
2 |
3 | [Org Mode](https://orgmode.org/) widgets for Flutter.
4 |
5 | # Usage
6 |
7 | For parsing Org Mode documents, see
8 | [org_parser](https://github.com/amake/org_parser). For an example application
9 | that displays Org Mode documents with org_parser and org_flutter, see
10 | [Orgro](https://orgro.org).
11 |
12 | The simplest way to display an Org Mode document in your Flutter application is
13 | to use the `Org` widget:
14 |
15 | ```dart
16 | import 'package:org_flutter/org_flutter.dart';
17 |
18 | class MyOrgViewWidget extends StatelessWidget {
19 | Widget build(BuildContext context) {
20 | return Org('''* TODO [#A] foo bar
21 | baz buzz''');
22 | }
23 | }
24 | ```
25 |
26 | See the [example](./example/lib/main.dart) for more.
27 |
28 | ## Rich text
29 |
30 | Use Org markup to create rich `Text`-equivalent widgets with `OrgText`.
31 |
32 | ```dart
33 | OrgText('*This* is a /rich/ text label ([[https://example.com][details]])')
34 | ```
35 |
36 | ## Advanced
37 |
38 | For more advanced usage, such as specifying link handling, use `OrgController`
39 | in concert with `OrgRootWidget`:
40 |
41 | ```dart
42 | import 'package:org_flutter/org_flutter.dart';
43 |
44 | Widget build(BuildContext context) {
45 | final doc = OrgDocument.parse(
46 | rawOrgModeDocString,
47 | // Interpret e.g. #+TODO: settings at the cost of a second parsing pass
48 | interpretEmbeddedSettings: true,
49 | );
50 | return OrgController(
51 | root: doc,
52 | child: OrgLocator( // Include OrgLocator to enable tap-to-jump on footnotes, etc.
53 | child: OrgRootWidget(
54 | style: myTextStyle,
55 | onLinkTap: launch, // e.g. from url_launcher package
56 | child: OrgDocumentWidget(doc),
57 | ),
58 | ),
59 | );
60 | }
61 | ```
62 |
63 | Place `OrgController` higher up in your widget hierarchy and access via
64 | `OrgController.of(context)` to dynamically control various properties of the
65 | displayed document:
66 |
67 | ```dart
68 | IconButton(
69 | icon: const Icon(Icons.repeat),
70 | onPressed: OrgController.of(context).cycleVisibility,
71 | );
72 | ```
73 |
74 | ## Text selection
75 |
76 | The Org Mode text is not selectable by default, but you can make it so by
77 | wrapping the widget in
78 | [`SelectionArea`](https://api.flutter.dev/flutter/material/SelectionArea-class.html).
79 |
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:flutter_lints/flutter.yaml
2 |
3 | analyzer:
4 | language:
5 | strict-casts: true
6 | strict-inference: true
7 | strict-raw-types: true
8 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | **/ios/Flutter/.last_build_id
26 | .dart_tool/
27 | .flutter-plugins
28 | .flutter-plugins-dependencies
29 | .packages
30 | .pub-cache/
31 | .pub/
32 | /build/
33 |
34 | # Web related
35 | lib/generated_plugin_registrant.dart
36 |
37 | # Symbolication related
38 | app.*.symbols
39 |
40 | # Obfuscation related
41 | app.*.map.json
42 |
43 | # Exceptions to above rules.
44 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
45 |
--------------------------------------------------------------------------------
/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 2738a1148ba6c9a6114df62358109407c3ef2553
8 | channel: beta
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # example
2 |
3 | An example demonstrating the org_flutter package
4 |
--------------------------------------------------------------------------------
/example/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | namespace 'com.example.example'
30 |
31 | compileSdk flutter.compileSdkVersion
32 |
33 | sourceSets {
34 | main.java.srcDirs += 'src/main/kotlin'
35 | }
36 |
37 |
38 | defaultConfig {
39 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
40 | applicationId "com.example.example"
41 | minSdkVersion flutter.minSdkVersion
42 | targetSdkVersion flutter.targetSdkVersion
43 | versionCode flutterVersionCode.toInteger()
44 | versionName flutterVersionName
45 | }
46 |
47 | buildTypes {
48 | release {
49 | // TODO: Add your own signing config for the release build.
50 | // Signing with the debug keys for now, so `flutter run --release` works.
51 | signingConfig signingConfigs.debug
52 | }
53 | }
54 | }
55 |
56 | flutter {
57 | source '../..'
58 | }
59 |
60 | dependencies {
61 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
62 | }
63 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
14 |
18 |
22 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
38 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.example
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity : FlutterActivity()
6 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.8.22'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.4.2'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | tasks.register("clean", Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.enableR8=true
3 | android.useAndroidX=true
4 | android.enableJetifier=true
5 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Mar 10 22:45:41 JST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
7 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Flutter Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be
3 | // found in the LICENSE file.
4 |
5 | include ':app'
6 |
7 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
8 | def properties = new Properties()
9 |
10 | assert localPropertiesFile.exists()
11 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
12 |
13 | def flutterSdkPath = properties.getProperty("flutter.sdk")
14 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
15 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
16 |
--------------------------------------------------------------------------------
/example/ios/.gitignore:
--------------------------------------------------------------------------------
1 | *.mode1v3
2 | *.mode2v3
3 | *.moved-aside
4 | *.pbxuser
5 | *.perspectivev3
6 | **/*sync/
7 | .sconsign.dblite
8 | .tags*
9 | **/.vagrant/
10 | **/DerivedData/
11 | Icon?
12 | **/Pods/
13 | **/.symlinks/
14 | profile
15 | xcuserdata
16 | **/.generated/
17 | Flutter/App.framework
18 | Flutter/Flutter.framework
19 | Flutter/Flutter.podspec
20 | Flutter/Generated.xcconfig
21 | Flutter/app.flx
22 | Flutter/app.zip
23 | Flutter/flutter_assets/
24 | Flutter/flutter_export_environment.sh
25 | ServiceDefinitions.json
26 | Runner/GeneratedPluginRegistrant.*
27 |
28 | # Exceptions to above rules.
29 | !default.mode1v3
30 | !default.mode2v3
31 | !default.pbxuser
32 | !default.perspectivev3
33 |
--------------------------------------------------------------------------------
/example/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 12.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
3 | #include "Generated.xcconfig"
4 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
3 | #include "Generated.xcconfig"
4 |
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '12.0'
3 |
4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6 |
7 | project 'Runner', {
8 | 'Debug' => :debug,
9 | 'Profile' => :release,
10 | 'Release' => :release,
11 | }
12 |
13 | def flutter_root
14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15 | unless File.exist?(generated_xcode_build_settings_path)
16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17 | end
18 |
19 | File.foreach(generated_xcode_build_settings_path) do |line|
20 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
21 | return matches[1].strip if matches
22 | end
23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24 | end
25 |
26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27 |
28 | flutter_ios_podfile_setup
29 |
30 | target 'Runner' do
31 | use_frameworks!
32 | use_modular_headers!
33 |
34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35 | end
36 |
37 | post_install do |installer|
38 | installer.pods_project.targets.each do |target|
39 | flutter_additional_ios_build_settings(target)
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/example/ios/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - Flutter (1.0.0)
3 | - flutter_tex_js_ios (0.0.1):
4 | - Flutter
5 |
6 | DEPENDENCIES:
7 | - Flutter (from `Flutter`)
8 | - flutter_tex_js_ios (from `.symlinks/plugins/flutter_tex_js_ios/ios`)
9 |
10 | EXTERNAL SOURCES:
11 | Flutter:
12 | :path: Flutter
13 | flutter_tex_js_ios:
14 | :path: ".symlinks/plugins/flutter_tex_js_ios/ios"
15 |
16 | SPEC CHECKSUMS:
17 | Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
18 | flutter_tex_js_ios: babbfcf08c2586a67d7ee713dbb5e8acdff19dd6
19 |
20 | PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011
21 |
22 | COCOAPODS: 1.14.3
23 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | example
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | $(FLUTTER_BUILD_NAME)
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UISupportedInterfaceOrientations
30 |
31 | UIInterfaceOrientationPortrait
32 | UIInterfaceOrientationLandscapeLeft
33 | UIInterfaceOrientationLandscapeRight
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UIViewControllerBasedStatusBarAppearance
43 |
44 | CADisableMinimumFrameDurationOnPhone
45 |
46 | UIApplicationSupportsIndirectInputEvents
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/example/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:org_flutter/org_flutter.dart';
3 |
4 | void main() {
5 | runApp(const MyApp());
6 | }
7 |
8 | class MyApp extends StatelessWidget {
9 | const MyApp({super.key});
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | return MaterialApp(
14 | title: 'org_flutter',
15 | restorationScopeId: 'example_root',
16 | theme: ThemeData(
17 | primarySwatch: Colors.blue,
18 | visualDensity: VisualDensity.adaptivePlatformDensity,
19 | ),
20 | home: const MyHomePage(),
21 | );
22 | }
23 | }
24 |
25 | class MyHomePage extends StatelessWidget {
26 | const MyHomePage({super.key});
27 |
28 | @override
29 | Widget build(BuildContext context) {
30 | return DefaultTabController(
31 | length: 2,
32 | child: Scaffold(
33 | appBar: AppBar(
34 | title: const Text('org_flutter'),
35 | bottom: const TabBar(
36 | tabs: [
37 | Tab(text: 'Simple'),
38 | Tab(text: 'Complex'),
39 | ],
40 | ),
41 | ),
42 | body: const TabBarView(children: [
43 | SimpleTab(),
44 | ComplexTab(),
45 | ]),
46 | ),
47 | );
48 | }
49 | }
50 |
51 | class SimpleTab extends StatelessWidget {
52 | const SimpleTab({super.key});
53 |
54 | @override
55 | Widget build(BuildContext context) {
56 | return const Org(
57 | '''* TODO [#A] foo bar
58 | baz buzz''',
59 | restorationId: 'my_org_widget',
60 | );
61 | }
62 | }
63 |
64 | class ComplexTab extends StatefulWidget {
65 | const ComplexTab({super.key});
66 |
67 | @override
68 | State createState() => _ComplexTabState();
69 | }
70 |
71 | class _ComplexTabState extends State {
72 | late OrgDocument root;
73 |
74 | @override
75 | void initState() {
76 | root = OrgDocument.parse('''* TODO [#A] foo bar
77 | ~1~''');
78 |
79 | super.initState();
80 | }
81 |
82 | @override
83 | Widget build(BuildContext context) {
84 | return OrgController(
85 | root: root,
86 | child: ListView(
87 | children: [
88 | OrgRootWidget(child: OrgDocumentWidget(root, shrinkWrap: true)),
89 | ElevatedButton(
90 | onPressed: _incrementCounter,
91 | child: const Text('Increment'),
92 | ),
93 | ],
94 | ),
95 | );
96 | }
97 |
98 | void _incrementCounter() {
99 | late OrgMarkup markupNode;
100 | root.visit((node) {
101 | markupNode = node;
102 | return false; // stop visiting
103 | });
104 | final value = int.parse(markupNode.content.children.single.toMarkup());
105 | setState(() {
106 | root = root
107 | .editNode(markupNode)!
108 | .replace(OrgMarkup.just('${value + 1}', OrgStyle.code))
109 | .commit() as OrgDocument;
110 | });
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/example/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: example
2 | description: An example app demonstrating the org_flutter package
3 |
4 | publish_to: 'none'
5 |
6 | version: 1.0.0+1
7 |
8 | environment:
9 | sdk: ">=3.0.0 <4.0.0"
10 |
11 | dependencies:
12 | flutter:
13 | sdk: flutter
14 | org_flutter:
15 | path: ..
16 |
17 | dev_dependencies:
18 | flutter_lints: ^5.0.0
19 | flutter_test:
20 | sdk: flutter
21 |
22 | flutter:
23 | uses-material-design: true
24 |
--------------------------------------------------------------------------------
/example/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:example/main.dart';
2 | import 'package:flutter_test/flutter_test.dart';
3 |
4 | void main() {
5 | testWidgets('Smoke test', (tester) async {
6 | await tester.pumpWidget(const MyApp());
7 | });
8 | }
9 |
--------------------------------------------------------------------------------
/example/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/web/favicon.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amake/org_flutter/ce28d119208cffe3bf913f558a4b4e215b2a71c9/example/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/example/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | example
18 |
19 |
20 |
21 |
24 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/example/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "short_name": "example",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "A new Flutter project.",
9 | "orientation": "portrait-primary",
10 | "prefer_related_applications": false,
11 | "icons": [
12 | {
13 | "src": "icons/Icon-192.png",
14 | "sizes": "192x192",
15 | "type": "image/png"
16 | },
17 | {
18 | "src": "icons/Icon-512.png",
19 | "sizes": "512x512",
20 | "type": "image/png"
21 | }
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/lib/src/error.dart:
--------------------------------------------------------------------------------
1 | typedef OrgErrorHandler = void Function(dynamic);
2 |
3 | sealed class OrgError implements Exception {
4 | const OrgError(this.message);
5 |
6 | final String message;
7 | }
8 |
9 | class OrgParserError extends OrgError {
10 | const OrgParserError(super.message, this.result);
11 |
12 | final dynamic result;
13 | }
14 |
15 | class OrgExecutionError extends OrgError {
16 | const OrgExecutionError(super.message, this.code, this.cause);
17 |
18 | final String code;
19 | final dynamic cause;
20 | }
21 |
22 | class OrgTimeoutError extends OrgError {
23 | const OrgTimeoutError(super.message, this.code, this.timeLimit);
24 |
25 | final String code;
26 | final Duration timeLimit;
27 | }
28 |
29 | class OrgArgumentError extends OrgError {
30 | const OrgArgumentError(super.message, this.item);
31 |
32 | final dynamic item;
33 | }
34 |
--------------------------------------------------------------------------------
/lib/src/events.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/widgets.dart';
2 | import 'package:org_flutter/src/controller.dart';
3 | import 'package:org_parser/org_parser.dart';
4 |
5 | /// A widget for managing callbacks invoked upon user interaction or other
6 | /// document-related events.
7 | class OrgEvents extends InheritedWidget {
8 | const OrgEvents({
9 | required super.child,
10 | this.onLinkTap,
11 | this.onLocalSectionLinkTap,
12 | this.onSectionLongPress,
13 | this.onSectionSlide,
14 | this.onListItemTap,
15 | this.onCitationTap,
16 | this.onTimestampTap,
17 | this.loadImage,
18 | super.key,
19 | });
20 |
21 | /// A callback invoked when the user taps a link. The argument is the
22 | /// [OrgLink] object; the URL is [OrgLink.location]. You might want to open
23 | /// this in a browser.
24 | final void Function(OrgLink)? onLinkTap;
25 |
26 | /// A callback invoked when the user taps on a link to a section within the
27 | /// current document. The argument is the target section. You might want to
28 | /// display it somehow.
29 | final void Function(OrgTree)? onLocalSectionLinkTap;
30 |
31 | /// A callback invoked when the user long-presses on a section headline within
32 | /// the current document. The argument is the pressed section. You might want
33 | /// to narrow the display to show just this section.
34 | final void Function(OrgSection)? onSectionLongPress;
35 |
36 | /// A callback invoked to build a list of actions revealed when the user
37 | /// slides a section. The argument is the section being slid. Consider
38 | /// supplying instances of `SlidableAction` from the
39 | /// [flutter_slidable](https://pub.dev/packages/flutter_slidable) package.
40 | final List Function(OrgSection)? onSectionSlide;
41 |
42 | /// A callback invoked when the user taps on a list item that has a checkbox
43 | /// within the current document. The argument is the tapped item. You might
44 | /// want to toggle the checkbox.
45 | final void Function(OrgListItem)? onListItemTap;
46 |
47 | /// A callback invoked when the user taps on a citation.
48 | final void Function(OrgCitation)? onCitationTap;
49 |
50 | /// A callback invoked when the user taps on a timestamp.
51 | final void Function(OrgNode)? onTimestampTap;
52 |
53 | /// A callback invoked when an image should be displayed. The argument is the
54 | /// [OrgLink] describing where the image data can be found. It is your
55 | /// responsibility to resolve the link, fetch the data, and return a widget
56 | /// for displaying the image.
57 | ///
58 | /// Return null instead to display the link text.
59 | final Widget? Function(OrgLink)? loadImage;
60 |
61 | static OrgEvents of(BuildContext context) =>
62 | context.dependOnInheritedWidgetOfExactType()!;
63 |
64 | /// Invoke the appropriate handler for the given [url]
65 | void dispatchLinkTap(BuildContext context, OrgLink link) {
66 | final section = _resolveLocalSectionLink(context, link.location);
67 | if (section != null) {
68 | onLocalSectionLinkTap?.call(section);
69 | } else {
70 | onLinkTap?.call(link);
71 | }
72 | }
73 |
74 | OrgTree? _resolveLocalSectionLink(BuildContext context, String url) {
75 | if (isOrgLocalSectionUrl(url)) {
76 | final sectionTitle = parseOrgLocalSectionUrl(url);
77 | final section = OrgController.of(context).sectionWithTitle(sectionTitle);
78 | if (section == null) {
79 | debugPrint('Failed to find local section with title "$sectionTitle"');
80 | }
81 | return section;
82 | } else if (isOrgIdUrl(url)) {
83 | final sectionId = parseOrgIdUrl(url);
84 | final section = OrgController.of(context).sectionWithId(sectionId);
85 | if (section == null) {
86 | debugPrint('Failed to find local section with ID "$sectionId"');
87 | }
88 | return section;
89 | } else if (isOrgCustomIdUrl(url)) {
90 | final sectionId = parseOrgCustomIdUrl(url);
91 | final section = OrgController.of(context).sectionWithCustomId(sectionId);
92 | if (section == null) {
93 | debugPrint('Failed to find local section with CUSTOM_ID "$sectionId"');
94 | }
95 | return section;
96 | }
97 | try {
98 | final link = OrgFileLink.parse(url);
99 | if (link.isLocal) {
100 | return _resolveLocalSectionLink(context, link.extra!);
101 | }
102 | } on Exception {
103 | // Ignore
104 | }
105 | return null;
106 | }
107 |
108 | @override
109 | bool updateShouldNotify(OrgEvents oldWidget) =>
110 | onLinkTap != oldWidget.onLinkTap ||
111 | onSectionLongPress != oldWidget.onSectionLongPress;
112 | }
113 |
--------------------------------------------------------------------------------
/lib/src/flash.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:org_flutter/org_flutter.dart';
3 |
4 | class AnimatedTextFlash extends StatefulWidget {
5 | const AnimatedTextFlash({
6 | required this.child,
7 | required this.cookie,
8 | this.times = 2,
9 | super.key,
10 | });
11 |
12 | final Widget child;
13 | final int times;
14 | final dynamic cookie;
15 |
16 | @override
17 | State createState() => _AnimatedTextFlashState();
18 | }
19 |
20 | class _AnimatedTextFlashState extends State
21 | with SingleTickerProviderStateMixin {
22 | late AnimationController _animation;
23 |
24 | @override
25 | void initState() {
26 | _animation = AnimationController(
27 | vsync: this,
28 | duration: const Duration(milliseconds: 100),
29 | );
30 | super.initState();
31 | }
32 |
33 | @override
34 | void dispose() {
35 | _animation.dispose();
36 | super.dispose();
37 | }
38 |
39 | @override
40 | void didUpdateWidget(covariant AnimatedTextFlash oldWidget) {
41 | if (oldWidget.cookie != widget.cookie) {
42 | _flash();
43 | }
44 | super.didUpdateWidget(oldWidget);
45 | }
46 |
47 | void _flash() async {
48 | for (var i = 0; i < widget.times; i++) {
49 | await _animation.forward();
50 | await _animation.reverse();
51 | }
52 | }
53 |
54 | @override
55 | Widget build(BuildContext context) {
56 | final defaultStyle = DefaultTextStyle.of(context).style;
57 |
58 | return DefaultTextStyleTransition(
59 | style: _animation.drive(
60 | TextStyleTween(
61 | begin: defaultStyle,
62 | end: defaultStyle.copyWith(
63 | backgroundColor: OrgTheme.dataOf(context).highlightColor),
64 | ).chain(
65 | CurveTween(curve: Curves.linearToEaseOut),
66 | ),
67 | ),
68 | child: widget.child,
69 | );
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/lib/src/folding.dart:
--------------------------------------------------------------------------------
1 | enum OrgVisibilityState {
2 | /// Just the root headline; equivalent to global "overview" state
3 | folded,
4 |
5 | /// All headlines of all levels
6 | contents,
7 |
8 | /// All immediate children (subtrees folded)
9 | children,
10 |
11 | /// Everything
12 | subtree,
13 |
14 | /// Not shown; for use in sparse trees
15 | hidden,
16 | }
17 |
18 | extension OrgVisibilityStateJson on OrgVisibilityState? {
19 | String? toJson() => this?.toString();
20 |
21 | static OrgVisibilityState? fromJson(String? json) => json == null
22 | ? null
23 | : OrgVisibilityState.values.singleWhere(
24 | (value) => value.toString() == json,
25 | );
26 | }
27 |
28 | extension OrgVisibilityStateCycling on OrgVisibilityState {
29 | OrgVisibilityState get cycleGlobal {
30 | switch (this) {
31 | case OrgVisibilityState.folded:
32 | return OrgVisibilityState.contents;
33 | case OrgVisibilityState.contents:
34 | return OrgVisibilityState.subtree;
35 | case OrgVisibilityState.subtree:
36 | case OrgVisibilityState.children:
37 | return OrgVisibilityState.folded;
38 | case OrgVisibilityState.hidden:
39 | return OrgVisibilityState.hidden;
40 | }
41 | }
42 |
43 | OrgVisibilityState cycleSubtree(bool empty) {
44 | switch (this) {
45 | case OrgVisibilityState.folded:
46 | return OrgVisibilityState.children;
47 | case OrgVisibilityState.contents:
48 | return empty ? OrgVisibilityState.subtree : OrgVisibilityState.folded;
49 | case OrgVisibilityState.children:
50 | return empty ? OrgVisibilityState.folded : OrgVisibilityState.subtree;
51 | case OrgVisibilityState.subtree:
52 | return OrgVisibilityState.folded;
53 | case OrgVisibilityState.hidden:
54 | return OrgVisibilityState.hidden;
55 | }
56 | }
57 |
58 | OrgVisibilityState get subtreeState {
59 | switch (this) {
60 | case OrgVisibilityState.folded: // fallthrough
61 | case OrgVisibilityState.contents: // fallthrough
62 | case OrgVisibilityState.children:
63 | return OrgVisibilityState.folded;
64 | case OrgVisibilityState.subtree:
65 | return OrgVisibilityState.subtree;
66 | case OrgVisibilityState.hidden:
67 | return OrgVisibilityState.hidden;
68 | }
69 | }
70 | }
71 |
72 | typedef OrgVisibilityResult = ({bool? searchHit, bool? sparseHit});
73 |
74 | extension OrgVisibilityResultUtil on OrgVisibilityResult {
75 | OrgVisibilityResult or(OrgVisibilityResult other) => (
76 | searchHit: searchHit == null ? null : searchHit! || other.searchHit!,
77 | sparseHit: sparseHit == null ? null : sparseHit! || other.sparseHit!,
78 | );
79 | }
80 |
--------------------------------------------------------------------------------
/lib/src/highlight.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter/widgets.dart';
3 | import 'package:highlighting/highlighting.dart';
4 | import 'package:highlighting/languages/all.dart';
5 | import 'package:org_flutter/src/widgets.dart';
6 |
7 | bool supportedSrcLanguage(String? language) =>
8 | allLanguages.containsKey(language) ||
9 | allLanguages.containsKey(language?.toLowerCase());
10 |
11 | Widget buildSrcHighlight(
12 | BuildContext context, {
13 | required String code,
14 | required String? languageId,
15 | }) =>
16 | HighlightView(
17 | code,
18 | theme: OrgTheme.dataOf(context).srcTheme ?? {},
19 | languageId: languageId,
20 | textStyle: DefaultTextStyle.of(context).style,
21 | );
22 |
23 | TextSpan buildSrcHighlightSpan(
24 | BuildContext context, {
25 | required String code,
26 | required String? languageId,
27 | }) =>
28 | _highlightedSpan(
29 | code,
30 | languageId: languageId,
31 | theme: OrgTheme.dataOf(context).srcTheme ?? {},
32 | textStyle: DefaultTextStyle.of(context).style,
33 | );
34 |
35 | // Below copied from:
36 | // https://github.com/akvelon/dart-highlighting/blob/25bc512c66d9eead9012dd129d0a12e77393b828/flutter_highlighting/lib/flutter_highlighting.dart
37 | //
38 | // with the following changes:
39 | //
40 | // - Replace `RichText` with `Text.rich`; see
41 | // https://github.com/akvelon/dart-highlighting/pull/71
42 | // - Fix lints
43 | // - Refactor to allow obtaining just the `TextSpan`
44 |
45 | const _rootKey = 'root';
46 | const _defaultFontColor = Color(0xff000000);
47 | const _defaultBackgroundColor = Color(0xffffffff);
48 |
49 | // TODO: dart:io is not available at web platform currently
50 | // See: https://github.com/flutter/flutter/issues/39998
51 | // So we just use monospace here for now
52 | const _defaultFontFamily = 'monospace';
53 |
54 | /// Highlight Flutter Widget
55 | class HighlightView extends StatelessWidget {
56 | /// The original code to be highlighted
57 | final String source;
58 |
59 | /// Highlight language
60 | ///
61 | /// It is recommended to give it a value for performance
62 | ///
63 | /// [All available languages](https://github.com/akvelon/dart-highlighting/tree/main/highlighting/lib/languages)
64 | final String? languageId;
65 |
66 | /// Highlight theme
67 | ///
68 | /// [All available themes](https://github.com/akvelon/dart-highlighting/tree/main/flutter_highlighting/lib/themes)
69 | final Map theme;
70 |
71 | /// Padding
72 | final EdgeInsetsGeometry? padding;
73 |
74 | /// Text styles
75 | ///
76 | /// Specify text styles such as font family and font size
77 | final TextStyle? textStyle;
78 |
79 | HighlightView(
80 | String input, {
81 | this.languageId,
82 | this.theme = const {},
83 | this.padding,
84 | this.textStyle,
85 | int tabSize = 8, // TODO: https://github.com/flutter/flutter/issues/50087
86 | super.key,
87 | }) : source = input.replaceAll('\t', ' ' * tabSize);
88 |
89 | @override
90 | Widget build(BuildContext context) {
91 | return Container(
92 | color: theme[_rootKey]?.backgroundColor ?? _defaultBackgroundColor,
93 | padding: padding,
94 | child: Text.rich(
95 | _highlightedSpan(
96 | source,
97 | languageId: languageId,
98 | theme: theme,
99 | textStyle: textStyle,
100 | ),
101 | ),
102 | );
103 | }
104 | }
105 |
106 | TextSpan _highlightedSpan(
107 | String source, {
108 | String? languageId,
109 | Map theme = const {},
110 | TextStyle? textStyle,
111 | }) {
112 | var style = TextStyle(
113 | fontFamily: _defaultFontFamily,
114 | color: theme[_rootKey]?.color ?? _defaultFontColor,
115 | );
116 | if (textStyle != null) {
117 | style = style.merge(textStyle);
118 | }
119 |
120 | return TextSpan(
121 | style: style,
122 | children: _convert(
123 | // ignore: invalid_use_of_internal_member
124 | highlight.highlight(languageId ?? '', source, true).nodes ?? [],
125 | theme,
126 | ),
127 | );
128 | }
129 |
130 | List _convert(List nodes, Map theme) {
131 | List spans = [];
132 | var currentSpans = spans;
133 | List> stack = [];
134 |
135 | traverse(Node node) {
136 | if (node.value != null) {
137 | currentSpans.add(node.className == null
138 | ? TextSpan(text: node.value)
139 | : TextSpan(text: node.value, style: theme[node.className]));
140 | } else {
141 | List tmp = [];
142 | currentSpans.add(TextSpan(children: tmp, style: theme[node.className]));
143 | stack.add(currentSpans);
144 | currentSpans = tmp;
145 |
146 | for (var n in node.children) {
147 | traverse(n);
148 | if (n == node.children.last) {
149 | currentSpans = stack.isEmpty ? spans : stack.removeLast();
150 | }
151 | }
152 | }
153 | }
154 |
155 | for (var node in nodes) {
156 | traverse(node);
157 | }
158 |
159 | return spans;
160 | }
161 |
--------------------------------------------------------------------------------
/lib/src/indent.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/widgets.dart';
2 |
3 | class IndentContext extends InheritedWidget {
4 | const IndentContext(this.indentSize, {required super.child, super.key});
5 |
6 | final int indentSize;
7 |
8 | @override
9 | bool updateShouldNotify(IndentContext oldWidget) =>
10 | indentSize != oldWidget.indentSize;
11 |
12 | static IndentContext? of(BuildContext context) =>
13 | context.dependOnInheritedWidgetOfExactType();
14 | }
15 |
16 | class IndentBuilder extends StatelessWidget {
17 | const IndentBuilder(
18 | this.indent, {
19 | this.expanded = true,
20 | required this.builder,
21 | super.key,
22 | });
23 |
24 | final Widget Function(BuildContext, int) builder;
25 | final String indent;
26 | final bool expanded;
27 |
28 | @override
29 | Widget build(BuildContext context) {
30 | final parentIndent = IndentContext.of(context)?.indentSize ?? 0;
31 | final newIndent =
32 | indent.length >= parentIndent ? indent.substring(parentIndent) : '';
33 | final totalIndentSize = parentIndent + newIndent.length;
34 | Widget child = IndentContext(
35 | parentIndent + newIndent.length,
36 | child: builder(context, totalIndentSize),
37 | );
38 | if (expanded) {
39 | child = Expanded(child: child);
40 | }
41 | return Row(
42 | crossAxisAlignment: CrossAxisAlignment.start,
43 | children: [Text(newIndent), child],
44 | );
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/lib/src/locatable.dart:
--------------------------------------------------------------------------------
1 | export 'widget/org_footnote_reference.dart' show FootnoteKey;
2 | export 'widget/org_link_target.dart' show LinkTargetKey;
3 | export 'widget/org_meta.dart' show NameKey;
4 | export 'widget/org_radio_target.dart' show RadioTargetKey;
5 |
--------------------------------------------------------------------------------
/lib/src/search.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:org_flutter/src/controller.dart';
3 |
4 | typedef SearchResultKey = GlobalKey;
5 |
6 | class SearchResult extends StatefulWidget {
7 | static Widget of(BuildContext context, {required Widget child}) =>
8 | SearchResult(
9 | key: OrgController.of(context).generateSearchResultKey(),
10 | child: child,
11 | );
12 |
13 | const SearchResult({required this.child, super.key});
14 | final Widget child;
15 |
16 | @override
17 | State createState() => SearchResultState();
18 | }
19 |
20 | /// The state object for a search result. Consumers of
21 | /// [OrgControllerData.searchResultKeys] can use [selected] to toggle focus
22 | /// highlighting.
23 | class SearchResultState extends State {
24 | bool _selected = false;
25 | late OrgControllerData _controller;
26 |
27 | @override
28 | void didChangeDependencies() {
29 | super.didChangeDependencies();
30 | _controller = OrgController.of(context);
31 | }
32 |
33 | bool get selected => _selected;
34 |
35 | set selected(bool value) {
36 | setState(() => _selected = value);
37 | }
38 |
39 | @override
40 | void dispose() {
41 | super.dispose();
42 | final key = widget.key;
43 | if (key is SearchResultKey) {
44 | _controller.removeSearchResultKey(key);
45 | }
46 | }
47 |
48 | @override
49 | Widget build(BuildContext context) {
50 | return _selected
51 | ? DecoratedBox(
52 | decoration: BoxDecoration(
53 | border: Border.all(
54 | color: Theme.of(context).colorScheme.outline,
55 | width: 0.5,
56 | ),
57 | ),
58 | position: DecorationPosition.foreground,
59 | child: widget.child,
60 | )
61 | : widget.child;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/lib/src/util/alignment.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:org_parser/org_parser.dart';
3 |
4 | enum OrgAlignment { left, center, right }
5 |
6 | final _attrPattern = RegExp(r'^#\+attr(.*):$', caseSensitive: false);
7 |
8 | OrgAlignment? alignmentForNode(OrgNode node, OrgTree root) {
9 | // TODO(aaron): This is potentially expensive. Think of a better way to track
10 | // the path within the tree.
11 | var zipper = root.editNode(node);
12 | if (zipper == null) return null;
13 |
14 | // For the document
15 | //
16 | // ```
17 | // #+ATTR_ORG: :align center
18 | // [[foo]]
19 | // ```
20 | //
21 | // the tree will look like:
22 | //
23 | // OrgDocument: #+ATTR_ORG...
24 | // OrgContent: #+ATTR_ORG...
25 | // OrgMeta: #+ATTR_ORG...
26 | // OrgContent: :align ce...
27 | // OrgPlainText: :align ce...
28 | // OrgParagraph: [[foo]]\n
29 | // OrgContent: [[foo]]\n
30 | // OrgLink: [[foo]]
31 | // OrgPlainText: "\n"
32 | //
33 | // Instead of going up a fixed number of times, we go up until we can go left.
34 | // This is important because we don't want to detect alignment for things
35 | // inline within a paragraph.
36 | //
37 | // - Alignable item: alone in an OrgParagraph; must go up to the level that
38 | // might have an OrgMeta sibling
39 | //
40 | // - Non-alignable item: will have siblings within OrgParagraph; will look at those
41 | // and fail to find an OrgMeta (which is good)
42 | while (!zipper!.canGoLeft()) {
43 | if (!zipper.canGoUp()) return null;
44 | zipper = zipper.goUp();
45 | }
46 |
47 | OrgAlignment? result;
48 | while (zipper!.canGoLeft()) {
49 | zipper = zipper.goLeft();
50 | final node = zipper.node;
51 | if (node is! OrgMeta) continue;
52 |
53 | final match = _attrPattern.firstMatch(node.key);
54 | if (match == null) continue;
55 | final authoritative = match.group(1)?.toLowerCase() == '_org';
56 |
57 | final value = node.value?.toMarkup();
58 | if (value == null) continue;
59 |
60 | final plist = tokenizePlist(value);
61 | final center = plist.get(':center');
62 | if (center == 't') {
63 | result = OrgAlignment.center;
64 | if (authoritative) break;
65 | } else {
66 | final alignment = plist.get(':align');
67 | if (alignment == null) continue;
68 | switch (alignment.toLowerCase()) {
69 | case 'left':
70 | result = OrgAlignment.left;
71 | case 'center':
72 | result = OrgAlignment.center;
73 | case 'right':
74 | result = OrgAlignment.right;
75 | }
76 | if (authoritative) break;
77 | }
78 | }
79 | return result;
80 | }
81 |
82 | typedef Plist = List;
83 |
84 | // TODO(aaron): Handle this properly, like with support for quoted strings.
85 | Plist tokenizePlist(String plist) => plist
86 | .split(RegExp(r'\s+'))
87 | .map((s) => s.trim())
88 | .where((s) => s.isNotEmpty)
89 | .toList(growable: false);
90 |
91 | extension PlistExtension on Plist {
92 | String? get(String key) {
93 | for (var i = 0; i < length; i++) {
94 | final token = this[i];
95 | if (token.toLowerCase() == key) {
96 | if (i + 1 < length) {
97 | return this[i + 1];
98 | }
99 | }
100 | }
101 | return null;
102 | }
103 | }
104 |
105 | extension OrgAlignmentExtension on OrgAlignment {
106 | MainAxisAlignment get toMainAxisAlignment => switch (this) {
107 | OrgAlignment.left => MainAxisAlignment.start,
108 | OrgAlignment.center => MainAxisAlignment.center,
109 | OrgAlignment.right => MainAxisAlignment.end
110 | };
111 | }
112 |
--------------------------------------------------------------------------------
/lib/src/util/bidi.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:more/char_matcher.dart';
3 | import 'package:org_flutter/org_flutter.dart';
4 |
5 | extension BidiUtil on OrgNode {
6 | TextDirection? detectTextDirection() {
7 | final serializer = OrgBidiDetectionSerializer();
8 | toMarkup(serializer: serializer);
9 | if (serializer.strongChar == null) return null;
10 | return UnicodeCharMatcher.bidiLeftToRight().match(serializer.strongChar!)
11 | ? TextDirection.ltr
12 | : TextDirection.rtl;
13 | }
14 | }
15 |
16 | class OrgBidiDetectionSerializer extends OrgSerializer {
17 | int? strongChar;
18 | bool canceled = false;
19 |
20 | @override
21 | void visit(OrgNode node) {
22 | if (canceled) return;
23 | super.visit(node);
24 | }
25 |
26 | @override
27 | void write(String str) {
28 | if (canceled) return;
29 |
30 | final idx = UnicodeCharMatcher.bidiStrong().firstIndexIn(str);
31 | if (idx != -1) {
32 | canceled = true;
33 | strongChar = str.codeUnitAt(idx);
34 | }
35 | super.write(str);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/lib/src/util/collection.dart:
--------------------------------------------------------------------------------
1 | Iterable interleave(Iterable items, T withItem) sync* {
2 | for (final item in items) {
3 | yield item;
4 | yield withItem;
5 | }
6 | }
7 |
8 | Iterable zipMap(
9 | Iterable a, Iterable b, R Function(T, U) visit) sync* {
10 | final iterA = a.iterator;
11 | final iterB = b.iterator;
12 | while (iterA.moveNext() && iterB.moveNext()) {
13 | yield visit(iterA.current, iterB.current);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/lib/src/util/elisp.dart:
--------------------------------------------------------------------------------
1 | import 'dart:developer';
2 |
3 | import 'package:petit_lisp/lisp.dart';
4 | import 'package:petitparser/petitparser.dart';
5 |
6 | class ElispParserDefinition extends LispParserDefinition {
7 | @override
8 | Parser atomChoice() => super.atomChoice()
9 | // # can start a symbol, so put functionQuote before symbol
10 | ..replace(ref0(symbol), ref0(functionQuote) | ref0(symbol));
11 |
12 | Parser functionQuote() =>
13 | (string("#'") & ref0(atom)).map((each) => Cons.quote(each[1]));
14 | }
15 |
16 | final _definition = ElispParserDefinition();
17 | final elispParser = _definition.build();
18 |
19 | // TODO(aaron): more accurate standard env
20 | class ElispEnvironment extends Environment {
21 | ElispEnvironment(super.owner) {
22 | // petit_lisp's `set!` does not evaluate the symbol
23 | define(Name('set'), _set);
24 | define(Name('setq'), _setq);
25 | define(Name('debugger'), _debugger);
26 | evalString(elispParser, this, _standardLibrary);
27 | }
28 |
29 | static dynamic _set(Environment env, dynamic args) {
30 | final sym = eval(env, args.head);
31 | if (sym is! Name) {
32 | throw ArgumentError('set: first argument must be a symbol');
33 | }
34 | return env[sym] = eval(env, args.tail.head);
35 | }
36 |
37 | static dynamic _setq(Environment env, dynamic args) {
38 | dynamic result;
39 | while (args is Cons) {
40 | final sym = args.head;
41 | if (sym is! Name) {
42 | throw ArgumentError('Invalid setq: $sym is not a symbol');
43 | }
44 | args = args.tail;
45 | result = env.setOrDefine(sym, eval(env, args.head));
46 | args = args.tail;
47 | }
48 | return result;
49 | }
50 |
51 | static dynamic _debugger(Environment env, dynamic args) {
52 | debugger();
53 | }
54 |
55 | static const _standardLibrary = '''
56 | (define t true)
57 | (define nil null)
58 |
59 | (define equal =)
60 | (define eq eq?)
61 |
62 | (define lambda lambda*)
63 |
64 | (define-macro* (defun name args . body)
65 | `(define* ,(cons name args) ,@body))
66 |
67 | (define-macro (defvar name value)
68 | `(define ,name ,value))
69 |
70 | (define-macro* (defmacro name args . body)
71 | `(define-macro* ,(cons name args) ,@body))
72 |
73 | (defun add-to-list (list-var element &optional appendp compare-fn)
74 | (if (not (member element (eval list-var) (eval compare-fn)))
75 | (set list-var (if appendp
76 | (append (eval list-var) (cons element nil))
77 | (cons element (eval list-var)))))
78 | (eval list-var))
79 |
80 | (defmacro dolist (spec &rest body)
81 | (let ((var (car spec))
82 | (templist (make-symbol "list"))
83 | (resultvar (caddr spec)))
84 | `(let ((,templist ,(cadr spec))
85 | ,var
86 | ,@(when resultvar `(,resultvar)))
87 | (while ,templist
88 | (setq ,var (car ,templist))
89 | ,@body
90 | (setq ,templist (cdr ,templist)))
91 | ,resultvar)))
92 | ''';
93 | }
94 |
95 | extension ElispExt on Environment {
96 | Environment get _root {
97 | var env = this;
98 | while (env.owner != null) {
99 | env = env.owner!;
100 | }
101 | return env;
102 | }
103 |
104 | dynamic setOrDefine(Name key, dynamic value) {
105 | try {
106 | return this[key] = value;
107 | } on ArgumentError {
108 | return _root.define(key, value);
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/lib/src/util/keywords.dart:
--------------------------------------------------------------------------------
1 | import 'package:org_flutter/org_flutter.dart';
2 |
3 | List getStartupSettings(OrgTree tree) {
4 | final result = [];
5 | tree.visit((meta) {
6 | if (meta.key.toUpperCase() == '#+STARTUP:' && meta.value != null) {
7 | for (final setting in meta.value!.toMarkup().trim().split(' ')) {
8 | result.add(setting.toLowerCase());
9 | }
10 | }
11 | return true;
12 | });
13 | return result;
14 | }
15 |
--------------------------------------------------------------------------------
/lib/src/util/locale.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:org_flutter/org_flutter.dart';
3 |
4 | /// Extracts the locale from `#+LANGUAGE:` in the given [tree].
5 | Locale? extractLocale(
6 | OrgTree tree,
7 | ) {
8 | Locale? result;
9 | tree.visit((meta) {
10 | if (meta.key.toUpperCase() == '#+LANGUAGE:' && meta.value != null) {
11 | final trailing = meta.value!.toMarkup().trim();
12 | result = tryParseLocale(trailing);
13 | if (result != null) return false;
14 | }
15 | return true;
16 | });
17 | debugPrint('Detected locale: $result');
18 | return result;
19 | }
20 |
21 | Locale? tryParseLocale(String locale) {
22 | final parts = locale.split(RegExp('[_-]'));
23 | if (parts.length == 1 && parts[0].isNotEmpty) {
24 | return Locale(parts[0]);
25 | } else if (parts.length == 2 && parts[1].length == 2) {
26 | return Locale(parts[0], parts[1]);
27 | } else if (parts.length == 2 && parts[1].length == 4) {
28 | return Locale.fromSubtags(
29 | languageCode: parts[0],
30 | scriptCode: parts[1],
31 | );
32 | } else if (parts.length == 3) {
33 | return Locale.fromSubtags(
34 | languageCode: parts[0],
35 | scriptCode: parts[1],
36 | countryCode: parts[2],
37 | );
38 | }
39 | return null;
40 | }
41 |
--------------------------------------------------------------------------------
/lib/src/util/text.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:org_flutter/src/util/collection.dart';
4 |
5 | /// If necessary, interleave runes with U+200B ZERO WIDTH SPACE to serve as a
6 | /// place to wrap the line.
7 | String characterWrappable(String text) {
8 | if (text.contains(' ')) {
9 | return text;
10 | } else {
11 | return String.fromCharCodes(interleave(text.runes, 0x200b));
12 | }
13 | }
14 |
15 | extension PatternUtil on Pattern? {
16 | bool get isEmpty {
17 | final self = this;
18 | if (self is String) {
19 | return self.isEmpty;
20 | } else if (self is RegExp) {
21 | return self.pattern.isEmpty;
22 | } else {
23 | return self == null;
24 | }
25 | }
26 |
27 | bool sameAs(Pattern? other) {
28 | final self = this;
29 | if (self == other) {
30 | return true;
31 | }
32 | if (self is RegExp && other is RegExp) {
33 | return self.pattern == other.pattern &&
34 | self.isCaseSensitive == other.isCaseSensitive &&
35 | self.isDotAll == other.isDotAll &&
36 | self.isMultiLine == other.isMultiLine &&
37 | self.isUnicode == other.isUnicode;
38 | }
39 | return false;
40 | }
41 | }
42 |
43 | enum TokenLocation { start, middle, end, only }
44 |
45 | TokenLocation locationOf(Object elem, List