├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── android ├── app │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── flutter │ │ └── plugins │ │ └── GeneratedPluginRegistrant.java └── local.properties ├── example ├── .gitignore ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ └── res │ │ │ │ ├── drawable-v21 │ │ │ │ └── launch_background.xml │ │ │ │ ├── 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-night │ │ │ │ └── styles.xml │ │ │ │ └── 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 │ ├── 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 │ └── RunnerTests │ │ └── RunnerTests.swift ├── lib │ └── main.dart ├── linux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ └── runner │ │ ├── CMakeLists.txt │ │ ├── main.cc │ │ ├── my_application.cc │ │ └── my_application.h ├── macos │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ └── GeneratedPluginRegistrant.swift │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── app_icon_1024.png │ │ │ │ ├── app_icon_128.png │ │ │ │ ├── app_icon_16.png │ │ │ │ ├── app_icon_256.png │ │ │ │ ├── app_icon_32.png │ │ │ │ ├── app_icon_512.png │ │ │ │ └── app_icon_64.png │ │ ├── Base.lproj │ │ │ └── MainMenu.xib │ │ ├── Configs │ │ │ ├── AppInfo.xcconfig │ │ │ ├── Debug.xcconfig │ │ │ ├── Release.xcconfig │ │ │ └── Warnings.xcconfig │ │ ├── DebugProfile.entitlements │ │ ├── Info.plist │ │ ├── MainFlutterWindow.swift │ │ └── Release.entitlements │ └── RunnerTests │ │ └── RunnerTests.swift ├── pubspec.yaml ├── test │ └── widget_test.dart ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── index.html │ └── manifest.json └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake │ └── runner │ ├── CMakeLists.txt │ ├── Runner.rc │ ├── flutter_window.cpp │ ├── flutter_window.h │ ├── main.cpp │ ├── resource.h │ ├── resources │ └── app_icon.ico │ ├── runner.exe.manifest │ ├── utils.cpp │ ├── utils.h │ ├── win32_window.cpp │ └── win32_window.h ├── flutter_syntax_view.iml ├── lib ├── flutter_syntax_view.dart └── src │ ├── flutter_syntax_view.dart │ ├── syntax │ ├── base.dart │ ├── c.dart │ ├── cpp.dart │ ├── dart.dart │ ├── index.dart │ ├── java.dart │ ├── javascript.dart │ ├── kotlin.dart │ ├── lua.dart │ ├── python.dart │ ├── rust.dart │ ├── swift.dart │ └── yaml.dart │ └── theme │ └── theme.dart ├── pubspec.yaml ├── test └── flutter_syntax_view_test.dart └── theme_shots ├── ayuDark.png ├── ayuLight.png ├── dracula.png ├── gravityDark.png ├── gravityLight.png ├── monokaiSublime.png ├── obsidian.png ├── oceanSunset.png ├── standard.png ├── vscodeDark.png └── vscodeLight.png /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | ios/.generated/ 9 | ios/Flutter/Generated.xcconfig 10 | ios/Runner/GeneratedPluginRegistrant.* 11 | .idea/workspace.xml 12 | -------------------------------------------------------------------------------- /.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: 8661d8aecd626f7f57ccbcb735553edc05a2e713 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.0.1] - 04/26/2019 2 | 3 | * First test release. 4 | 5 | ## [0.1.0] - 04/27/2019 6 | 7 | * First stable release. 8 | 9 | ## [0.1.1] - 04/27/2019 10 | 11 | * Fixed a Warning. 12 | 13 | ## [0.1.2] - 04/28/2019 14 | 15 | * New Syntax Added (Java, Kotlin, Swift). 16 | * New Theme Added (Ocean Sunset). 17 | 18 | ## [0.1.3] - 04/28/2019 19 | 20 | * Fixed README.md 21 | 22 | 23 | ## [0.2.0] - 05/25/2019 24 | 25 | * JavaScript Syntax Added & Fixed Duplicated Syntax KeyWord in Swift. 26 | 27 | ## [0.2.1] - 05/25/2019 28 | 29 | * Syntax Theme is not required (Default: dracula). 30 | * SDK minimun support upgraded from 2.1.0 to 2.2.2. 31 | * Syntax Lines counter is now available. 32 | 33 | ## [0.2.2] - 02/23/2020 34 | 35 | * implemented abstraction. 36 | * Added Editable Rich Text 37 | 38 | ## [1.0.0] - 02/23/2020 39 | 40 | * Removed (Editable Rich Text due some platform errors) 41 | 42 | ## [2.0.0] - 10/04/2020 43 | 44 | * Code Cleanup 45 | * Now Zooming depends on gesture 46 | * Added C Syntax Support 47 | * Added C++ Syntax Support 48 | 49 | ## [2.1.0] - 10/04/2020 50 | 51 | * Added YAML Syntax Support 52 | 53 | 54 | ## [2.2.0] - 13/01/2021 55 | 56 | * Added vscode dark and light themes 57 | * Added new themes screenshots 58 | 59 | ## [2.2.1] - 13/01/2021 60 | 61 | * Fixed Theme screenshots not showing due invalid link 62 | 63 | ## [2.2.2] - 13/01/2021 64 | 65 | * Fixed duplicated themes issue 66 | 67 | ## [3.2.2] - 21/02/2021 68 | 69 | * Added Font size with a default value of 12.0 by @marwenx. 70 | * Added Expansion (default to false) which allows the SyntaxView to be used inside a Column or a ListView... @marwenx. 71 | * Added void, types and Preprocessor Conditional compilation ( #if, #else, #elif, #ifdef, #ifndef, #endif, and #pragma ) to C/C++ built in types parser 72 | 73 | ## [4.0.0] - 31/03/2021 74 | * Revert softWrap for now due instability 75 | * Removed Zooming with gestures due instability, now zooming is only supported with icon controls 76 | * Upgraded string_scanner dependency to null safety stable version 1.1.0 77 | * Executed $ dart migrate command which enabled Null safety support automatically 78 | * Added late and required to Dart syntax keywords 79 | * Added publish_to: "none" to example project's pubspec.yaml 80 | 81 | ## [4.1.0] - 02/04/2024 82 | * Syntax view text is now selectable thanks to @shyam1s15 PR #14 83 | * Updated example 84 | 85 | ## [4.1.1] - 26/12/2024 86 | * Fix scrollbar position attached in web thanks to @jhon2520 PR #19 87 | * Updated example 88 | 89 | ## [4.1.2] - 26/12/2024 90 | * Fix lines count are not aligned correctly with code when selection is on 91 | 92 | ## [4.1.3] - 26/12/2024 93 | * Improve code documentation and styling 94 | * 95 | ## [4.1.4] - 27/12/2024 96 | * Added Rust Syntax Highlighter 97 | 98 | ## [4.1.5] - 08/02/2025 99 | * Update README 100 | * Update example 101 | * The copyWith method is created to allow developers to add custom SyntaxView styles 102 | 103 | ## [4.1.6] - 08/03/2025 104 | * Added Lua Syntax Highlighter by @Binozo 105 | 106 | ## [4.1.7] - 09/03/2025 107 | * Added Python Syntax Highlighter by @lebao3105 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Bader Eddine Ouaich and other contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_syntax_view 2 | 3 | Flutter Syntax Highlighter 4 | 5 | ## Basic Usage 6 | 7 | ```dart 8 | class HomePage extends StatelessWidget { 9 | const HomePage({super.key}); 10 | 11 | final String code = """ 12 | // Importing core libraries 13 | import 'dart:math'; 14 | int fibonacci(int n) { 15 | if (n == 0 || n == 1) return n; 16 | return fibonacci(n - 1) + fibonacci(n - 2); 17 | } 18 | final int result = fibonacci(20); 19 | /* and there 20 | you have it! */ 21 | """; 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return Scaffold( 26 | body: Center( 27 | child: SyntaxView( 28 | code: code, // Code text 29 | syntax: Syntax.DART, // Language 30 | syntaxTheme: SyntaxTheme.vscodeDark(), // Theme 31 | fontSize: 12.0, // Font size 32 | withZoom: true, // Enable/Disable zoom icon controls 33 | withLinesCount: true, // Enable/Disable line number 34 | expanded: false, // Enable/Disable container expansion 35 | selectable: true // Enable/Disable code text selection 36 | ), 37 | ), 38 | ); 39 | } 40 | } 41 | ``` 42 | 43 | ## Create a Custom SyntaxTheme 44 | 45 | ```dart 46 | class AppColors{ 47 | 48 | static const Color backgroundColor = Color(0xff1A1A19); 49 | static const Color linesCountColor = Color(0xffEFE9D5); 50 | static const Color commentStyle = Color(0xffEEDF7A); 51 | static const Color zoomIconColor = Color(0xff77CDFF); 52 | static const Color stringStyle = Color(0xffF87A53); 53 | static const Color baseStyle = Color(0xffF5F5F5); 54 | static const Color keywordStyle = Color(0xffCAE0BC); 55 | static const Color classStyle = Color(0xffB9E5E8); 56 | 57 | } 58 | 59 | class HomePage extends StatelessWidget { 60 | HomePage({super.key}); 61 | 62 | static const String code = r""" 63 | import 'dart:math' as math; 64 | 65 | // Coffee class is the best! 66 | class Coffee { 67 | late int _temperature; 68 | 69 | void heat() => _temperature = 100; 70 | void chill() => _temperature = -5; 71 | 72 | void sip() { 73 | final bool isTooHot = math.max(37, _temperature) > 37; 74 | if (isTooHot) 75 | print("myyy liiips!"); 76 | else 77 | print("mmmmm refreshing!"); 78 | } 79 | 80 | int? get temperature => temperature; 81 | } 82 | void main() { 83 | var coffee = Coffee(); 84 | coffee.heat(); 85 | coffee.sip(); 86 | coffee.chill(); 87 | coffee.sip(); 88 | } 89 | /* And there 90 | you have it */"""; 91 | 92 | 93 | final SyntaxTheme myCustomTheme = SyntaxTheme.standard().copyWith( 94 | backgroundColor : AppColors.backgroundColor, 95 | linesCountColor : AppColors.linesCountColor, 96 | commentStyle : const TextStyle(color: AppColors.commentStyle), 97 | zoomIconColor : AppColors.zoomIconColor, 98 | stringStyle : const TextStyle(color: AppColors.stringStyle), 99 | baseStyle : const TextStyle(color: AppColors.baseStyle), 100 | keywordStyle : const TextStyle(color: AppColors.keywordStyle), 101 | punctuationStyle: const TextStyle(color: AppColors.keywordStyle), 102 | classStyle : const TextStyle(color: AppColors.classStyle), 103 | ); 104 | 105 | @override 106 | Widget build(BuildContext context) { 107 | return Scaffold( 108 | body: Center( 109 | child: SyntaxView( 110 | code: code, // Code text 111 | syntax: Syntax.DART, // Language 112 | syntaxTheme: myCustomTheme, // Theme 113 | fontSize: 12.0, // Font size 114 | withZoom: true, // Enable/Disable zoom icon controls 115 | withLinesCount: true, // Enable/Disable line number 116 | expanded: false, // Enable/Disable container expansion 117 | selectable: true // Enable/Disable code text selection 118 | ), 119 | ), 120 | ); 121 | } 122 | } 123 | ``` 124 | 125 | ## Supported Syntax 126 | 127 | - [x] Dart 128 | - [x] C 129 | - [x] C++ 130 | - [x] Java 131 | - [x] Kotlin 132 | - [x] Swift 133 | - [x] JavaScript 134 | - [x] YAML 135 | - [x] Rust 136 | - [x] Lua 137 | - [x] Python 138 | 139 | ## Themes 140 | 141 | 142 | 143 | 144 | ## Installing 145 | 146 | [Package](https://pub.dartlang.org/packages/flutter_syntax_view) 147 | 148 | 149 | ## Contributing 150 | 151 | - if you are familiar with Regular Expressions in Dart and would like contribute in adding further syntax support. it will be very appreciated! 152 | 153 | 154 | ## Contributors ✨ 155 | Thanks goes to these wonderful people!
156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 |
198 | 199 | 200 | ## Features and bugs 201 | 202 | If you face any problems feel free to open an issue at the [issue tracker][tracker]. If you feel the library is missing a feature, please raise a ticket on Github. Pull request are also welcome. 203 | 204 | [tracker]: https://github.com/baderouaich/flutter_syntax_view/issues 205 | -------------------------------------------------------------------------------- /android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java: -------------------------------------------------------------------------------- 1 | package io.flutter.plugins; 2 | 3 | import androidx.annotation.Keep; 4 | import androidx.annotation.NonNull; 5 | import io.flutter.Log; 6 | 7 | import io.flutter.embedding.engine.FlutterEngine; 8 | 9 | /** 10 | * Generated file. Do not edit. 11 | * This file is generated by the Flutter tool based on the 12 | * plugins that support the Android platform. 13 | */ 14 | @Keep 15 | public final class GeneratedPluginRegistrant { 16 | private static final String TAG = "GeneratedPluginRegistrant"; 17 | public static void registerWith(@NonNull FlutterEngine flutterEngine) { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /android/local.properties: -------------------------------------------------------------------------------- 1 | sdk.dir=/home/bader/Android/Sdk 2 | flutter.sdk=/home/bader/snap/flutter/common/flutter -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Symbolication related 35 | app.*.symbols 36 | 37 | # Obfuscation related 38 | app.*.map.json 39 | 40 | # Android Studio will place build artifacts here 41 | /android/app/debug 42 | /android/app/profile 43 | /android/app/release 44 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) 13 | 14 | For help getting started with Flutter development, view the 15 | [online documentation](https://docs.flutter.dev/), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at https://dart.dev/lints. 17 | # 18 | # Instead of disabling a lint rule for the entire project in the 19 | # section below, it can also be suppressed for a single line of code 20 | # or a specific dart file by using the `// ignore: name_of_lint` and 21 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 22 | # producing the lint. 23 | rules: 24 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 25 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 26 | 27 | # Additional information about this file can be found at 28 | # https://dart.dev/guides/language/analysis-options 29 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "com.android.application" 3 | id "kotlin-android" 4 | id "dev.flutter.flutter-gradle-plugin" 5 | } 6 | 7 | def localProperties = new Properties() 8 | def localPropertiesFile = rootProject.file('local.properties') 9 | if (localPropertiesFile.exists()) { 10 | localPropertiesFile.withReader('UTF-8') { reader -> 11 | localProperties.load(reader) 12 | } 13 | } 14 | 15 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 16 | if (flutterVersionCode == null) { 17 | flutterVersionCode = '1' 18 | } 19 | 20 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 21 | if (flutterVersionName == null) { 22 | flutterVersionName = '1.0' 23 | } 24 | 25 | android { 26 | namespace "com.flutter_syntax_view.example.example" 27 | compileSdk flutter.compileSdkVersion 28 | ndkVersion flutter.ndkVersion 29 | 30 | compileOptions { 31 | sourceCompatibility JavaVersion.VERSION_1_8 32 | targetCompatibility JavaVersion.VERSION_1_8 33 | } 34 | 35 | defaultConfig { 36 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 37 | applicationId "com.flutter_syntax_view.example.example" 38 | // You can update the following values to match your application needs. 39 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. 40 | minSdkVersion flutter.minSdkVersion 41 | targetSdkVersion flutter.targetSdkVersion 42 | versionCode flutterVersionCode.toInteger() 43 | versionName flutterVersionName 44 | } 45 | 46 | buildTypes { 47 | release { 48 | // TODO: Add your own signing config for the release build. 49 | // Signing with the debug keys for now, so `flutter run --release` works. 50 | signingConfig signingConfigs.debug 51 | } 52 | } 53 | } 54 | 55 | flutter { 56 | source '../..' 57 | } 58 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 14 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 32 | 33 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /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 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | } 7 | 8 | rootProject.buildDir = '../build' 9 | subprojects { 10 | project.buildDir = "${rootProject.buildDir}/${project.name}" 11 | } 12 | subprojects { 13 | project.evaluationDependsOn(':app') 14 | } 15 | 16 | tasks.register("clean", Delete) { 17 | delete rootProject.buildDir 18 | } 19 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4G 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | def flutterSdkPath = { 3 | def properties = new Properties() 4 | file("local.properties").withInputStream { properties.load(it) } 5 | def flutterSdkPath = properties.getProperty("flutter.sdk") 6 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 7 | return flutterSdkPath 8 | } 9 | settings.ext.flutterSdkPath = flutterSdkPath() 10 | 11 | includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") 12 | 13 | repositories { 14 | google() 15 | mavenCentral() 16 | gradlePluginPortal() 17 | } 18 | } 19 | 20 | plugins { 21 | id "dev.flutter.flutter-plugin-loader" version "1.0.0" 22 | id "com.android.application" version "8.5.2" apply false 23 | id "org.jetbrains.kotlin.android" version "1.7.10" apply false 24 | } 25 | 26 | include ":app" 27 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /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 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/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 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | CADisableMinimumFrameDurationOnPhone 45 | 46 | UIApplicationSupportsIndirectInputEvents 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/ios/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Flutter 2 | import UIKit 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_syntax_view/flutter_syntax_view.dart'; 3 | 4 | void main() => runApp(const App()); 5 | 6 | class App extends StatelessWidget { 7 | const App({super.key}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return const MaterialApp( 12 | home: MyApp(), 13 | debugShowCheckedModeBanner: false, 14 | title: "Flutter Syntax View Example", 15 | ); 16 | } 17 | } 18 | 19 | class MyApp extends StatefulWidget { 20 | const MyApp({super.key}); 21 | 22 | @override 23 | State createState() => MyAppState(); 24 | } 25 | 26 | class MyAppState extends State { 27 | static const String code = r""" 28 | import 'dart:math' as math; 29 | 30 | // Coffee class is the best! 31 | class Coffee { 32 | late int _temperature; 33 | 34 | void heat() => _temperature = 100; 35 | void chill() => _temperature = -5; 36 | 37 | void sip() { 38 | final bool isTooHot = math.max(37, _temperature) > 37; 39 | if (isTooHot) 40 | print("myyy liiips!"); 41 | else 42 | print("mmmmm refreshing!"); 43 | } 44 | 45 | int? get temperature => temperature; 46 | } 47 | void main() { 48 | var coffee = Coffee(); 49 | coffee.heat(); 50 | coffee.sip(); 51 | coffee.chill(); 52 | coffee.sip(); 53 | } 54 | /* And there 55 | you have it */"""; 56 | 57 | static final syntaxViews = { 58 | "Standard": SyntaxView( 59 | code: code, 60 | syntax: Syntax.DART, 61 | syntaxTheme: SyntaxTheme.standard(), 62 | fontSize: 12.0, 63 | withZoom: true, 64 | withLinesCount: true, 65 | expanded: true, 66 | selectable: true, 67 | ), 68 | "Dracula": SyntaxView( 69 | code: code, 70 | syntax: Syntax.DART, 71 | syntaxTheme: SyntaxTheme.dracula(), 72 | fontSize: 12.0, 73 | withZoom: true, 74 | withLinesCount: false, 75 | expanded: false, 76 | selectable: true, 77 | ), 78 | "AyuLight": SyntaxView( 79 | code: code, 80 | syntax: Syntax.DART, 81 | syntaxTheme: SyntaxTheme.ayuLight(), 82 | fontSize: 12.0, 83 | withZoom: false, 84 | withLinesCount: true, 85 | expanded: true, 86 | ), 87 | "Custom AyuLight": SyntaxView( 88 | code: code, 89 | syntax: Syntax.DART, 90 | syntaxTheme: SyntaxTheme.ayuLight().copyWith( 91 | linesCountColor: Colors.teal, 92 | keywordStyle: const TextStyle(color: Colors.purple)), 93 | fontSize: 12.0, 94 | withZoom: false, 95 | withLinesCount: true, 96 | expanded: true, 97 | ), 98 | "AyuDark": SyntaxView( 99 | code: code, 100 | syntax: Syntax.DART, 101 | syntaxTheme: SyntaxTheme.ayuDark(), 102 | fontSize: 12.0, 103 | withZoom: true, 104 | withLinesCount: false, 105 | expanded: false, 106 | ), 107 | "GravityLight": SyntaxView( 108 | code: code, 109 | syntax: Syntax.DART, 110 | syntaxTheme: SyntaxTheme.gravityLight(), 111 | fontSize: 12.0, 112 | withZoom: true, 113 | withLinesCount: true, 114 | expanded: true, 115 | ), 116 | "GravityDark": SyntaxView( 117 | code: code, 118 | syntax: Syntax.DART, 119 | syntaxTheme: SyntaxTheme.gravityDark(), 120 | fontSize: 12.0, 121 | withZoom: false, 122 | withLinesCount: false, 123 | expanded: false, 124 | selectable: true), 125 | "MonokaiSublime": SyntaxView( 126 | code: code, 127 | syntax: Syntax.DART, 128 | syntaxTheme: SyntaxTheme.monokaiSublime(), 129 | fontSize: 12.0, 130 | withZoom: true, 131 | withLinesCount: true, 132 | expanded: true, 133 | selectable: true), 134 | "Obsidian": SyntaxView( 135 | code: code, 136 | syntax: Syntax.DART, 137 | syntaxTheme: SyntaxTheme.obsidian(), 138 | fontSize: 12.0, 139 | withZoom: true, 140 | withLinesCount: true, 141 | expanded: false, 142 | selectable: true), 143 | "OceanSunset": SyntaxView( 144 | code: code, 145 | syntax: Syntax.DART, 146 | syntaxTheme: SyntaxTheme.oceanSunset(), 147 | fontSize: 12.0, 148 | withZoom: false, 149 | withLinesCount: true, 150 | expanded: true, 151 | selectable: true, 152 | ), 153 | "vscodeDark": SyntaxView( 154 | code: code, 155 | syntax: Syntax.DART, 156 | syntaxTheme: SyntaxTheme.vscodeDark(), 157 | fontSize: 12.0, 158 | withZoom: true, 159 | withLinesCount: true, 160 | expanded: false, 161 | selectable: true), 162 | "vscodeLight": SyntaxView( 163 | code: code, 164 | syntax: Syntax.DART, 165 | syntaxTheme: SyntaxTheme.vscodeLight(), 166 | fontSize: 12.0, 167 | withZoom: true, 168 | withLinesCount: true, 169 | expanded: true, 170 | selectable: true) 171 | }; 172 | 173 | @override 174 | Widget build(BuildContext context) { 175 | return Scaffold( 176 | appBar: AppBar( 177 | title: const Text("Flutter Syntax View Example"), 178 | backgroundColor: Colors.blueGrey[800], 179 | elevation: 6, 180 | ), 181 | body: ListView.builder( 182 | padding: const EdgeInsets.all(8), 183 | itemCount: syntaxViews.length, 184 | itemBuilder: (BuildContext context, int index) { 185 | String themeName = syntaxViews.keys.elementAt(index); 186 | SyntaxView syntaxView = syntaxViews.values.elementAt(index); 187 | return Card( 188 | margin: const EdgeInsets.all(10), 189 | elevation: 6.0, 190 | child: Column( 191 | children: [ 192 | Padding( 193 | padding: const EdgeInsets.all(3.0), 194 | child: Row( 195 | mainAxisAlignment: MainAxisAlignment.center, 196 | children: [ 197 | const Icon(Icons.brush_sharp), 198 | Text( 199 | themeName, 200 | style: const TextStyle(fontWeight: FontWeight.bold), 201 | ), 202 | const Icon(Icons.brush_sharp), 203 | ], 204 | ), 205 | ), 206 | const Divider(), 207 | if (syntaxView.expanded) 208 | SizedBox( 209 | height: MediaQuery.of(context).size.height / 2.5, 210 | child: syntaxView) 211 | else 212 | syntaxView 213 | ], 214 | ), 215 | ); 216 | }), 217 | ); 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.13) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.flutter_syntax_view.example.example") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | # Application build; see runner/CMakeLists.txt. 58 | add_subdirectory("runner") 59 | 60 | # Run the Flutter tool portions of the build. This must not be removed. 61 | add_dependencies(${BINARY_NAME} flutter_assemble) 62 | 63 | # Only the install-generated bundle's copy of the executable will launch 64 | # correctly, since the resources must in the right relative locations. To avoid 65 | # people trying to run the unbundled copy, put it in a subdirectory instead of 66 | # the default top-level location. 67 | set_target_properties(${BINARY_NAME} 68 | PROPERTIES 69 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 70 | ) 71 | 72 | 73 | # Generated plugin build rules, which manage building the plugins and adding 74 | # them to the application. 75 | include(flutter/generated_plugins.cmake) 76 | 77 | 78 | # === Installation === 79 | # By default, "installing" just makes a relocatable bundle in the build 80 | # directory. 81 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 82 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 83 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 84 | endif() 85 | 86 | # Start with a clean build bundle directory every time. 87 | install(CODE " 88 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 89 | " COMPONENT Runtime) 90 | 91 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 92 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 93 | 94 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 95 | COMPONENT Runtime) 96 | 97 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 98 | COMPONENT Runtime) 99 | 100 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 101 | COMPONENT Runtime) 102 | 103 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 104 | install(FILES "${bundled_library}" 105 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 106 | COMPONENT Runtime) 107 | endforeach(bundled_library) 108 | 109 | # Copy the native assets provided by the build.dart from all packages. 110 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") 111 | install(DIRECTORY "${NATIVE_ASSETS_DIR}" 112 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 113 | COMPONENT Runtime) 114 | 115 | # Fully re-copy the assets directory on each build to avoid having stale files 116 | # from a previous install. 117 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 118 | install(CODE " 119 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 120 | " COMPONENT Runtime) 121 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 122 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 123 | 124 | # Install the AOT library on non-Debug builds only. 125 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 126 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 127 | COMPONENT Runtime) 128 | endif() 129 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/linux/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} 10 | "main.cc" 11 | "my_application.cc" 12 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 13 | ) 14 | 15 | # Apply the standard set of build settings. This can be removed for applications 16 | # that need different build settings. 17 | apply_standard_settings(${BINARY_NAME}) 18 | 19 | # Add preprocessor definitions for the application ID. 20 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 21 | 22 | # Add dependency libraries. Add any application-specific dependencies here. 23 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 24 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 25 | 26 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 27 | -------------------------------------------------------------------------------- /example/linux/runner/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/linux/runner/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GApplication::startup. 85 | static void my_application_startup(GApplication* application) { 86 | //MyApplication* self = MY_APPLICATION(object); 87 | 88 | // Perform any actions required at application startup. 89 | 90 | G_APPLICATION_CLASS(my_application_parent_class)->startup(application); 91 | } 92 | 93 | // Implements GApplication::shutdown. 94 | static void my_application_shutdown(GApplication* application) { 95 | //MyApplication* self = MY_APPLICATION(object); 96 | 97 | // Perform any actions required at application shutdown. 98 | 99 | G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application); 100 | } 101 | 102 | // Implements GObject::dispose. 103 | static void my_application_dispose(GObject* object) { 104 | MyApplication* self = MY_APPLICATION(object); 105 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 106 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 107 | } 108 | 109 | static void my_application_class_init(MyApplicationClass* klass) { 110 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 111 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 112 | G_APPLICATION_CLASS(klass)->startup = my_application_startup; 113 | G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown; 114 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 115 | } 116 | 117 | static void my_application_init(MyApplication* self) {} 118 | 119 | MyApplication* my_application_new() { 120 | // Set the program name to the application ID, which helps various systems 121 | // like GTK and desktop environments map this running application to its 122 | // corresponding .desktop file. This ensures better integration by allowing 123 | // the application to be recognized beyond its binary name. 124 | g_set_prgname(APPLICATION_ID); 125 | 126 | return MY_APPLICATION(g_object_new(my_application_get_type(), 127 | "application-id", APPLICATION_ID, 128 | "flags", G_APPLICATION_NON_UNIQUE, 129 | nullptr)); 130 | } 131 | -------------------------------------------------------------------------------- /example/linux/runner/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @main 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | 10 | override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { 11 | return true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.fluttersyntaxview.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2024 com.flutter_syntax_view.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/RunnerTests/RunnerTests.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | import XCTest 4 | 5 | class RunnerTests: XCTestCase { 6 | 7 | func testExample() { 8 | // If you add code to the Runner application, consider adding tests here. 9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest. 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: "A new Flutter project." 3 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 4 | version: 1.0.0+1 5 | 6 | environment: 7 | sdk: '>=3.3.3 <4.0.0' 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | cupertino_icons: ^1.0.6 14 | flutter_syntax_view: 15 | path: ../ # to include local package instead of the published one 16 | 17 | dev_dependencies: 18 | flutter_test: 19 | sdk: flutter 20 | 21 | flutter_lints: ^3.0.0 22 | 23 | flutter: 24 | uses-material-design: true 25 | 26 | -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility in the flutter_test package. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter_test/flutter_test.dart'; 10 | 11 | import 'package:example/main.dart'; 12 | 13 | void main() { 14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async { 15 | // Build our app and trigger a frame. 16 | await tester.pumpWidget(const MyApp()); 17 | 18 | // Verify that our counter starts at 0. 19 | expect(find.text('0'), findsOneWidget); 20 | expect(find.text('1'), findsNothing); 21 | 22 | // Tap the '+' icon and trigger a frame. 23 | await tester.tap(find.byIcon(Icons.add)); 24 | await tester.pump(); 25 | 26 | // Verify that our counter has incremented. 27 | expect(find.text('0'), findsNothing); 28 | expect(find.text('1'), findsOneWidget); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /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 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(example LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(VERSION 3.14...3.25) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | 56 | # Generated plugin build rules, which manage building the plugins and adding 57 | # them to the application. 58 | include(flutter/generated_plugins.cmake) 59 | 60 | 61 | # === Installation === 62 | # Support files are copied into place next to the executable, so that it can 63 | # run in place. This is done instead of making a separate bundle (as on Linux) 64 | # so that building and running from within Visual Studio will work. 65 | set(BUILD_BUNDLE_DIR "$") 66 | # Make the "install" step default, as it's required to run. 67 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 68 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 69 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 70 | endif() 71 | 72 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 73 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 74 | 75 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 76 | COMPONENT Runtime) 77 | 78 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 79 | COMPONENT Runtime) 80 | 81 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 82 | COMPONENT Runtime) 83 | 84 | if(PLUGIN_BUNDLED_LIBRARIES) 85 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 86 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 87 | COMPONENT Runtime) 88 | endif() 89 | 90 | # Copy the native assets provided by the build.dart from all packages. 91 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") 92 | install(DIRECTORY "${NATIVE_ASSETS_DIR}" 93 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 94 | COMPONENT Runtime) 95 | 96 | # Fully re-copy the assets directory on each build to avoid having stale files 97 | # from a previous install. 98 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 99 | install(CODE " 100 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 101 | " COMPONENT Runtime) 102 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 103 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 104 | 105 | # Install the AOT library on non-Debug builds only. 106 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 107 | CONFIGURATIONS Profile;Release 108 | COMPONENT Runtime) 109 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # Set fallback configurations for older versions of the flutter tool. 14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 15 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 16 | endif() 17 | 18 | # === Flutter Library === 19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 20 | 21 | # Published to parent scope for install step. 22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 26 | 27 | list(APPEND FLUTTER_LIBRARY_HEADERS 28 | "flutter_export.h" 29 | "flutter_windows.h" 30 | "flutter_messenger.h" 31 | "flutter_plugin_registrar.h" 32 | "flutter_texture_registrar.h" 33 | ) 34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 35 | add_library(flutter INTERFACE) 36 | target_include_directories(flutter INTERFACE 37 | "${EPHEMERAL_DIR}" 38 | ) 39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 40 | add_dependencies(flutter flutter_assemble) 41 | 42 | # === Wrapper === 43 | list(APPEND CPP_WRAPPER_SOURCES_CORE 44 | "core_implementations.cc" 45 | "standard_codec.cc" 46 | ) 47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 49 | "plugin_registrar.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 52 | list(APPEND CPP_WRAPPER_SOURCES_APP 53 | "flutter_engine.cc" 54 | "flutter_view_controller.cc" 55 | ) 56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 57 | 58 | # Wrapper sources needed for a plugin. 59 | add_library(flutter_wrapper_plugin STATIC 60 | ${CPP_WRAPPER_SOURCES_CORE} 61 | ${CPP_WRAPPER_SOURCES_PLUGIN} 62 | ) 63 | apply_standard_settings(flutter_wrapper_plugin) 64 | set_target_properties(flutter_wrapper_plugin PROPERTIES 65 | POSITION_INDEPENDENT_CODE ON) 66 | set_target_properties(flutter_wrapper_plugin PROPERTIES 67 | CXX_VISIBILITY_PRESET hidden) 68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 69 | target_include_directories(flutter_wrapper_plugin PUBLIC 70 | "${WRAPPER_ROOT}/include" 71 | ) 72 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 73 | 74 | # Wrapper sources needed for the runner. 75 | add_library(flutter_wrapper_app STATIC 76 | ${CPP_WRAPPER_SOURCES_CORE} 77 | ${CPP_WRAPPER_SOURCES_APP} 78 | ) 79 | apply_standard_settings(flutter_wrapper_app) 80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 81 | target_include_directories(flutter_wrapper_app PUBLIC 82 | "${WRAPPER_ROOT}/include" 83 | ) 84 | add_dependencies(flutter_wrapper_app flutter_assemble) 85 | 86 | # === Flutter tool backend === 87 | # _phony_ is a non-existent file to force this command to run every time, 88 | # since currently there's no way to get a full input/output list from the 89 | # flutter tool. 90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 92 | add_custom_command( 93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 95 | ${CPP_WRAPPER_SOURCES_APP} 96 | ${PHONY_OUTPUT} 97 | COMMAND ${CMAKE_COMMAND} -E env 98 | ${FLUTTER_TOOL_ENVIRONMENT} 99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 100 | ${FLUTTER_TARGET_PLATFORM} $ 101 | VERBATIM 102 | ) 103 | add_custom_target(flutter_assemble DEPENDS 104 | "${FLUTTER_LIBRARY}" 105 | ${FLUTTER_LIBRARY_HEADERS} 106 | ${CPP_WRAPPER_SOURCES_CORE} 107 | ${CPP_WRAPPER_SOURCES_PLUGIN} 108 | ${CPP_WRAPPER_SOURCES_APP} 109 | ) 110 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.flutter_syntax_view.example" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2024 com.flutter_syntax_view.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | // Flutter can complete the first frame before the "show window" callback is 35 | // registered. The following call ensures a frame is pending to ensure the 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. 37 | flutter_controller_->ForceRedraw(); 38 | 39 | return true; 40 | } 41 | 42 | void FlutterWindow::OnDestroy() { 43 | if (flutter_controller_) { 44 | flutter_controller_ = nullptr; 45 | } 46 | 47 | Win32Window::OnDestroy(); 48 | } 49 | 50 | LRESULT 51 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 52 | WPARAM const wparam, 53 | LPARAM const lparam) noexcept { 54 | // Give Flutter, including plugins, an opportunity to handle window messages. 55 | if (flutter_controller_) { 56 | std::optional result = 57 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 58 | lparam); 59 | if (result) { 60 | return *result; 61 | } 62 | } 63 | 64 | switch (message) { 65 | case WM_FONTCHANGE: 66 | flutter_controller_->engine()->ReloadSystemFonts(); 67 | break; 68 | } 69 | 70 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 71 | } 72 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | unsigned int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr) 51 | -1; // remove the trailing null character 52 | int input_length = (int)wcslen(utf16_string); 53 | std::string utf8_string; 54 | if (target_length == 0 || target_length > utf8_string.max_size()) { 55 | return utf8_string; 56 | } 57 | utf8_string.resize(target_length); 58 | int converted_length = ::WideCharToMultiByte( 59 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 60 | input_length, utf8_string.data(), target_length, nullptr, nullptr); 61 | if (converted_length == 0) { 62 | return std::string(); 63 | } 64 | return utf8_string; 65 | } 66 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates a win32 window with |title| that is positioned and sized using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | -------------------------------------------------------------------------------- /flutter_syntax_view.iml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /lib/flutter_syntax_view.dart: -------------------------------------------------------------------------------- 1 | library flutter_syntax_view; 2 | 3 | export 'src/flutter_syntax_view.dart'; 4 | export 'src/syntax/index.dart'; 5 | -------------------------------------------------------------------------------- /lib/src/flutter_syntax_view.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'dart:math' as math; // math.max & max 3 | 4 | import 'syntax/index.dart'; 5 | 6 | class SyntaxView extends StatefulWidget { 7 | SyntaxView( 8 | {required this.code, 9 | required this.syntax, 10 | this.syntaxTheme, 11 | this.withZoom = true, 12 | this.withLinesCount = true, 13 | this.fontSize = 12.0, 14 | this.expanded = false, 15 | this.selectable = true}); 16 | 17 | /// Code text 18 | final String code; 19 | 20 | /// Syntax/Language (Dart, C, C++...) 21 | final Syntax syntax; 22 | 23 | /// Enable/Disable zooming controls (default: true) 24 | final bool withZoom; 25 | 26 | /// Enable/Disable line number in left (default: true) 27 | final bool withLinesCount; 28 | 29 | /// Theme of syntax view example SyntaxTheme.dracula() (default: SyntaxTheme.dracula()) 30 | final SyntaxTheme? syntaxTheme; 31 | 32 | /// Font Size with a default value of 12.0 33 | final double fontSize; 34 | 35 | /// Expansion which allows the SyntaxView to be used inside a Column or a ListView... (default: false) 36 | final bool expanded; 37 | 38 | /// selectable allow user to let user select the code 39 | final bool selectable; 40 | 41 | @override 42 | State createState() => SyntaxViewState(); 43 | } 44 | 45 | class SyntaxViewState extends State { 46 | /// For zooming Controls 47 | static const double MAX_FONT_SCALE_FACTOR = 3.0; 48 | static const double MIN_FONT_SCALE_FACTOR = 0.5; 49 | double _fontScaleFactor = 1.0; 50 | late ScrollController _verticalScrollController; 51 | 52 | @override 53 | void initState() { 54 | super.initState(); 55 | _verticalScrollController = ScrollController(); 56 | } 57 | 58 | @override 59 | void dispose() { 60 | _verticalScrollController.dispose(); 61 | super.dispose(); 62 | } 63 | 64 | @override 65 | Widget build(BuildContext context) { 66 | return Stack(alignment: AlignmentDirectional.bottomEnd, children: [ 67 | Container( 68 | padding: widget.withLinesCount 69 | ? const EdgeInsets.only(left: 5, top: 10, right: 10, bottom: 10) 70 | : const EdgeInsets.all(10), 71 | color: widget.syntaxTheme!.backgroundColor, 72 | constraints: widget.expanded ? BoxConstraints.expand() : null, 73 | child: Scrollbar( 74 | controller: _verticalScrollController, 75 | child: SingleChildScrollView( 76 | controller: _verticalScrollController, 77 | child: SingleChildScrollView( 78 | scrollDirection: Axis.horizontal, 79 | child: widget.withLinesCount 80 | ? buildCodeWithLinesCount() // Syntax view with line number to the left 81 | : buildCode() // Syntax view 82 | )))), 83 | if (widget.withZoom) zoomControls() // Zoom control icons 84 | ]); 85 | } 86 | 87 | Widget buildCodeWithLinesCount() { 88 | final int numLines = '\n'.allMatches(widget.code).length + 1; 89 | return Row( 90 | crossAxisAlignment: CrossAxisAlignment.start, 91 | mainAxisSize: MainAxisSize.max, 92 | children: [ 93 | Column( 94 | // mainAxisAlignment: MainAxisAlignment.spaceEvenly, 95 | mainAxisSize: MainAxisSize.min, 96 | children: [ 97 | for (int i = 1; i <= numLines; i++) 98 | widget.selectable 99 | ? SelectableText.rich( 100 | TextSpan( 101 | style: TextStyle( 102 | fontFamily: 'monospace', 103 | fontSize: widget.fontSize, 104 | color: widget.syntaxTheme!.linesCountColor), 105 | text: "$i", 106 | ), 107 | textScaler: TextScaler.linear(_fontScaleFactor), 108 | ) 109 | : RichText( 110 | textScaler: TextScaler.linear(_fontScaleFactor), 111 | text: TextSpan( 112 | style: TextStyle( 113 | fontFamily: 'monospace', 114 | fontSize: widget.fontSize, 115 | color: widget.syntaxTheme!.linesCountColor), 116 | text: "$i", 117 | )), 118 | ]), 119 | VerticalDivider(width: 5), 120 | buildCode(), 121 | ], 122 | ); 123 | } 124 | 125 | Widget buildCode() { 126 | if (widget.selectable) { 127 | return SelectableText.rich( 128 | TextSpan( 129 | style: TextStyle(fontFamily: 'monospace', fontSize: widget.fontSize), 130 | children: [ 131 | getSyntax(widget.syntax, widget.syntaxTheme).format(widget.code) 132 | ], 133 | ), 134 | textScaler: TextScaler.linear(_fontScaleFactor), 135 | ); 136 | } else { 137 | return RichText( 138 | textScaler: TextScaler.linear(_fontScaleFactor), 139 | text: TextSpan( 140 | style: TextStyle(fontFamily: 'monospace', fontSize: widget.fontSize), 141 | children: [ 142 | getSyntax(widget.syntax, widget.syntaxTheme).format(widget.code) 143 | ], 144 | ), 145 | ); 146 | } 147 | } 148 | 149 | Widget zoomControls() { 150 | return Row( 151 | mainAxisSize: MainAxisSize.min, 152 | children: [ 153 | IconButton( 154 | icon: 155 | Icon(Icons.zoom_out, color: widget.syntaxTheme!.zoomIconColor), 156 | onPressed: () => setState(() { 157 | _fontScaleFactor = 158 | math.max(MIN_FONT_SCALE_FACTOR, _fontScaleFactor - 0.1); 159 | })), 160 | IconButton( 161 | icon: Icon(Icons.zoom_in, color: widget.syntaxTheme!.zoomIconColor), 162 | onPressed: () => setState(() { 163 | _fontScaleFactor = 164 | math.min(MAX_FONT_SCALE_FACTOR, _fontScaleFactor + 0.1); 165 | })), 166 | ], 167 | ); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /lib/src/syntax/base.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'index.dart'; 3 | 4 | /// The base class of all syntax highlighters 5 | abstract class SyntaxBase { 6 | SyntaxTheme? get syntaxTheme; 7 | TextSpan format(String src); 8 | Syntax get type; 9 | } 10 | 11 | /// Supported Syntaxes Enum 12 | enum Syntax { 13 | DART, 14 | C, 15 | CPP, 16 | JAVASCRIPT, 17 | KOTLIN, 18 | JAVA, 19 | SWIFT, 20 | YAML, 21 | RUST, 22 | LUA, 23 | PYTHON 24 | } 25 | 26 | /// Tokens 27 | enum HighlightType { 28 | number, 29 | comment, 30 | keyword, 31 | string, 32 | punctuation, 33 | klass, // or struct 34 | constant 35 | } 36 | 37 | /// Rich text span highlighter 38 | class HighlightSpan { 39 | HighlightSpan(this.type, this.start, this.end); 40 | 41 | /// Highlight type (number, comment...) 42 | final HighlightType type; 43 | 44 | /// Starting offset of the token 45 | final int start; 46 | 47 | /// Ending offset of the token 48 | final int end; 49 | 50 | /// Extracts token from String src 51 | String textForSpan(String src) { 52 | return src.substring(start, end); 53 | } 54 | 55 | /// Returns the appropriate styling based on current span type 56 | TextStyle? textStyle(SyntaxTheme? syntaxTheme) { 57 | if (type == HighlightType.number) { 58 | return syntaxTheme!.numberStyle; 59 | } else if (type == HighlightType.comment) { 60 | return syntaxTheme!.commentStyle; 61 | } else if (type == HighlightType.keyword) { 62 | return syntaxTheme!.keywordStyle; 63 | } else if (type == HighlightType.string) { 64 | return syntaxTheme!.stringStyle; 65 | } else if (type == HighlightType.punctuation) { 66 | return syntaxTheme!.punctuationStyle; 67 | } else if (type == HighlightType.klass) { 68 | return syntaxTheme!.classStyle; 69 | } else if (type == HighlightType.constant) { 70 | return syntaxTheme!.constantStyle; 71 | } else { 72 | return syntaxTheme!.baseStyle; 73 | } 74 | } 75 | } 76 | 77 | /// Returns the appropriate syntax highlighter for a programming language syntax 78 | SyntaxBase getSyntax(Syntax syntax, SyntaxTheme? theme) { 79 | switch (syntax) { 80 | case Syntax.DART: 81 | return DartSyntaxHighlighter(theme); 82 | case Syntax.C: 83 | return CSyntaxHighlighter(theme); 84 | case Syntax.CPP: 85 | return CPPSyntaxHighlighter(theme); 86 | case Syntax.JAVA: 87 | return JavaSyntaxHighlighter(theme); 88 | case Syntax.KOTLIN: 89 | return KotlinSyntaxHighlighter(theme); 90 | case Syntax.SWIFT: 91 | return SwiftSyntaxHighlighter(theme); 92 | case Syntax.JAVASCRIPT: 93 | return JavaScriptSyntaxHighlighter(theme); 94 | case Syntax.YAML: 95 | return YamlSyntaxHighlighter(theme); 96 | case Syntax.RUST: 97 | return RustSyntaxHighlighter(theme); 98 | case Syntax.LUA: 99 | return LuaSyntaxHighlighter(theme); 100 | case Syntax.PYTHON: 101 | return PythonSyntaxHighlighter(theme); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /lib/src/syntax/c.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | import 'index.dart'; 4 | 5 | class CSyntaxHighlighter extends SyntaxBase { 6 | CSyntaxHighlighter([this.syntaxTheme]) { 7 | _spans = []; 8 | syntaxTheme ??= SyntaxTheme.dracula(); 9 | } 10 | 11 | @override 12 | Syntax get type => Syntax.C; 13 | 14 | @override 15 | SyntaxTheme? syntaxTheme; 16 | 17 | static const List _keywords = const [ 18 | 'include', 19 | 'auto', 20 | 'break', 21 | 'case', 22 | 'const', 23 | 'continue', 24 | 'default', 25 | 'do', 26 | 'else', 27 | 'enum', 28 | 'extern', 29 | 'for', 30 | 'goto', 31 | 'if', 32 | 'inline', 33 | 'register', 34 | 'restrict', 35 | 'return', 36 | 'signed', 37 | 'sizeof', 38 | 'static', 39 | 'struct', 40 | 'switch', 41 | 'typedef', 42 | 'union', 43 | 'unsigned', 44 | 'void', 45 | 'volatile', 46 | 'while', 47 | 'NULL', 48 | ]; 49 | 50 | static const List _builtInTypes = const [ 51 | 'char', 52 | 'short', 53 | 'int', 54 | 'long', 55 | 'long long', 56 | 'double', 57 | 'float', 58 | 59 | // stuff 60 | "intmax_t", "uintmax_t", 61 | "int8_t", "uint8_t", 62 | "int16_t", "uint16_t", 63 | "int32_t", "uint32_t", 64 | "int64_t", "uint64_t", 65 | "int_least8_t", "uint_least8_t", 66 | "int_least16_t", "uint_least16_t", 67 | "int_least32_t", "uint_least32_t", 68 | "int_least64_t", "uint_least64_t", 69 | "int_fast8_t", "uint_fast8_t", 70 | "int_fast16_t", "uint_fast16_t", 71 | "int_fast32_t", "uint_fast32_t", 72 | "int_fast64_t", "uint_fast64_t", 73 | "intptr_t", "uintptr_t" 74 | ]; 75 | 76 | late String _src; 77 | late StringScanner _scanner; 78 | 79 | late List _spans; 80 | 81 | TextSpan format(String src) { 82 | _src = src; 83 | _scanner = StringScanner(_src); 84 | 85 | if (_generateSpans()) { 86 | /// Successfully parsed the code 87 | final List formattedText = []; 88 | int currentPosition = 0; 89 | 90 | for (HighlightSpan span in _spans) { 91 | if (currentPosition > span.start) continue; 92 | if (currentPosition != span.start) { 93 | formattedText.add( 94 | TextSpan( 95 | text: _src.substring(currentPosition, span.start), 96 | ), 97 | ); 98 | } 99 | 100 | formattedText.add(TextSpan( 101 | style: span.textStyle(syntaxTheme), 102 | text: span.textForSpan(_src), 103 | )); 104 | 105 | currentPosition = span.end; 106 | } 107 | 108 | if (currentPosition != _src.length) { 109 | formattedText.add(TextSpan( 110 | text: _src.substring(currentPosition, _src.length), 111 | )); 112 | } 113 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 114 | } else { 115 | /// Parsing failed, return with only basic formatting 116 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 117 | } 118 | } 119 | 120 | bool _generateSpans() { 121 | int lastLoopPosition = _scanner.position; 122 | 123 | while (!_scanner.isDone) { 124 | /// Skip White space 125 | _scanner.scan(RegExp(r'\s+')); 126 | 127 | /// Block comments 128 | if (_scanner.scan(RegExp('/\\*+[^*]*\\*+(?:[^/*][^*]*\\*+)*/'))) { 129 | _spans.add(HighlightSpan(HighlightType.comment, 130 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 131 | continue; 132 | } 133 | 134 | /// Line comments 135 | if (_scanner.scan('//')) { 136 | final int startComment = _scanner.lastMatch!.start; 137 | bool eof = false; 138 | int endComment; 139 | if (_scanner.scan(RegExp(r'.*'))) { 140 | endComment = _scanner.lastMatch!.end; 141 | } else { 142 | eof = true; 143 | endComment = _src.length; 144 | } 145 | _spans.add( 146 | HighlightSpan(HighlightType.comment, startComment, endComment)); 147 | 148 | if (eof) break; 149 | 150 | continue; 151 | } 152 | 153 | /// Raw R"String" 154 | if (_scanner.scan(RegExp(r'R".*"'))) { 155 | _spans.add(HighlightSpan(HighlightType.string, 156 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 157 | continue; 158 | } 159 | 160 | /// "String" "value" 161 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 162 | _spans.add(HighlightSpan(HighlightType.string, 163 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 164 | continue; 165 | } 166 | 167 | /// Double value x.x .x 168 | if (_scanner.scan(RegExp(r'\d+\.\d+|.\d+'))) { 169 | _spans.add(HighlightSpan(HighlightType.number, 170 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 171 | continue; 172 | } 173 | 174 | /// Float value x.xf .xf 175 | if (_scanner.scan(RegExp(r'\d+\.\d+f|.\d+f'))) { 176 | _spans.add(HighlightSpan(HighlightType.number, 177 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 178 | continue; 179 | } 180 | 181 | /// Integer value 182 | if (_scanner.scan(RegExp(r'\d+'))) { 183 | _spans.add(HighlightSpan(HighlightType.number, 184 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 185 | continue; 186 | } 187 | 188 | /// Preprocessor Conditional compilation () #if, #else, #elif, #ifdef, #ifndef and #endif ) and #pragma 189 | if (_scanner.scan(RegExp( 190 | r'(#ifdef)|(#ifndef)|(#if)|(#else)|(#elif)|(#endif)|(#pragma)'))) { 191 | _spans.add(HighlightSpan(HighlightType.keyword, 192 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 193 | continue; 194 | } 195 | 196 | /// Punctuation TEST: https://www.regexpal.com/100066 197 | if (_scanner.scan(RegExp(r'[\[\]{}().!=><#&\|\?\+\-\*/%\^~;:,]'))) { 198 | _spans.add(HighlightSpan(HighlightType.punctuation, 199 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 200 | continue; 201 | } 202 | 203 | /// Meta data 204 | if (_scanner.scan(RegExp(r'@\w+'))) { 205 | _spans.add(HighlightSpan(HighlightType.keyword, 206 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 207 | continue; 208 | } 209 | 210 | /// Words 211 | if (_scanner.scan(RegExp(r'\w+'))) { 212 | HighlightType? type; 213 | 214 | String word = _scanner.lastMatch![0]!; 215 | if (word.startsWith('_')) word = word.substring(1); 216 | 217 | if (_keywords.contains(word)) { 218 | type = HighlightType.keyword; 219 | } else if (_builtInTypes.contains(word)) { 220 | type = HighlightType.keyword; 221 | } else if (_firstLetterIsUpperCase(word)) { 222 | type = HighlightType.klass; 223 | } else if (word.length >= 2 && 224 | word.startsWith('k') && 225 | _firstLetterIsUpperCase(word.substring(1))) { 226 | type = HighlightType.constant; 227 | } 228 | if (type != null) { 229 | _spans.add(HighlightSpan( 230 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 231 | } 232 | } 233 | 234 | /// Check if this loop did anything 235 | if (lastLoopPosition == _scanner.position) { 236 | /// Failed to parse this file, abort gracefully 237 | return false; 238 | } 239 | lastLoopPosition = _scanner.position; 240 | } 241 | 242 | _simplify(); 243 | return true; 244 | } 245 | 246 | void _simplify() { 247 | for (int i = _spans.length - 2; i >= 0; i -= 1) { 248 | if (_spans[i].type == _spans[i + 1].type && 249 | _spans[i].end == _spans[i + 1].start) { 250 | _spans[i] = 251 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 252 | _spans.removeAt(i + 1); 253 | } 254 | } 255 | } 256 | 257 | bool _firstLetterIsUpperCase(String str) { 258 | if (str.isNotEmpty) { 259 | final String first = str.substring(0, 1); 260 | return first == first.toUpperCase(); 261 | } 262 | return false; 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /lib/src/syntax/dart.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | 4 | import 'index.dart'; 5 | 6 | class DartSyntaxHighlighter extends SyntaxBase { 7 | DartSyntaxHighlighter([this.syntaxTheme]) { 8 | _spans = []; 9 | syntaxTheme ??= SyntaxTheme.dracula(); 10 | } 11 | 12 | @override 13 | Syntax get type => Syntax.DART; 14 | 15 | @override 16 | SyntaxTheme? syntaxTheme; 17 | 18 | static const List _keywords = const [ 19 | 'abstract', 20 | 'as', 21 | 'assert', 22 | 'async', 23 | 'await', 24 | 'break', 25 | 'case', 26 | 'catch', 27 | 'class', 28 | 'const', 29 | 'late', 30 | 'required', 31 | 'continue', 32 | 'default', 33 | 'deferred', 34 | 'do', 35 | 'dynamic', 36 | 'else', 37 | 'enum', 38 | 'export', 39 | 'external', 40 | 'extends', 41 | 'factory', 42 | 'false', 43 | 'final', 44 | 'finally', 45 | 'for', 46 | 'get', 47 | 'if', 48 | 'implements', 49 | 'import', 50 | 'in', 51 | 'is', 52 | 'library', 53 | 'new', 54 | 'null', 55 | 'operator', 56 | 'part', 57 | 'rethrow', 58 | 'return', 59 | 'set', 60 | 'static', 61 | 'super', 62 | 'switch', 63 | 'sync', 64 | 'this', 65 | 'throw', 66 | 'true', 67 | 'try', 68 | 'typedef', 69 | 'var', 70 | 'void', 71 | 'while', 72 | 'with', 73 | 'yield', 74 | 'show' 75 | ]; 76 | 77 | static const List _builtInTypes = const [ 78 | 'int', 79 | 'double', 80 | 'num', 81 | 'bool', 82 | ]; 83 | 84 | late String _src; 85 | late StringScanner _scanner; 86 | 87 | late List _spans; 88 | 89 | TextSpan format(String src) { 90 | _src = src; 91 | _scanner = StringScanner(_src); 92 | 93 | if (_generateSpans()) { 94 | /// Successfully parsed the code 95 | final List formattedText = []; 96 | int currentPosition = 0; 97 | 98 | for (HighlightSpan span in _spans) { 99 | if (currentPosition > span.start) { 100 | continue; 101 | } 102 | if (currentPosition != span.start) { 103 | formattedText.add( 104 | TextSpan( 105 | text: _src.substring(currentPosition, span.start), 106 | ), 107 | ); 108 | } 109 | 110 | formattedText.add(TextSpan( 111 | style: span.textStyle(syntaxTheme), 112 | text: span.textForSpan(_src), 113 | )); 114 | 115 | currentPosition = span.end; 116 | } 117 | 118 | if (currentPosition != _src.length) { 119 | formattedText.add(TextSpan( 120 | text: _src.substring(currentPosition, _src.length), 121 | )); 122 | } 123 | 124 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 125 | } else { 126 | /// Parsing failed, return with only basic formatting 127 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 128 | } 129 | } 130 | 131 | bool _generateSpans() { 132 | int lastLoopPosition = _scanner.position; 133 | 134 | while (!_scanner.isDone) { 135 | /// Skip White space 136 | _scanner.scan(RegExp(r'\s+')); 137 | 138 | /// Block comments 139 | if (_scanner.scan(RegExp('/\\*+[^*]*\\*+(?:[^/*][^*]*\\*+)*/'))) { 140 | _spans.add(HighlightSpan(HighlightType.comment, 141 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 142 | continue; 143 | } 144 | 145 | /// Line comments 146 | if (_scanner.scan('//')) { 147 | final int startComment = _scanner.lastMatch!.start; 148 | bool eof = false; 149 | int endComment; 150 | if (_scanner.scan(RegExp(r'.*'))) { 151 | endComment = _scanner.lastMatch!.end; 152 | } else { 153 | eof = true; 154 | endComment = _src.length; 155 | } 156 | _spans.add( 157 | HighlightSpan(HighlightType.comment, startComment, endComment)); 158 | 159 | if (eof) { 160 | break; 161 | } 162 | 163 | continue; 164 | } 165 | 166 | /// Raw r"String" 167 | if (_scanner.scan(RegExp(r'r".*"'))) { 168 | _spans.add(HighlightSpan(HighlightType.string, 169 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 170 | continue; 171 | } 172 | 173 | /// Raw r'String' 174 | if (_scanner.scan(RegExp(r"r'.*'"))) { 175 | _spans.add(HighlightSpan(HighlightType.string, 176 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 177 | continue; 178 | } 179 | 180 | /// Multiline """String""" 181 | if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { 182 | _spans.add(HighlightSpan(HighlightType.string, 183 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 184 | continue; 185 | } 186 | 187 | /// Multiline '''String''' 188 | if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { 189 | _spans.add(HighlightSpan(HighlightType.string, 190 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 191 | continue; 192 | } 193 | 194 | /// "String" 195 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 196 | _spans.add(HighlightSpan(HighlightType.string, 197 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 198 | continue; 199 | } 200 | 201 | /// 'String' 202 | if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { 203 | _spans.add(HighlightSpan(HighlightType.string, 204 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 205 | continue; 206 | } 207 | 208 | /// Double 209 | if (_scanner.scan(RegExp(r'\d+\.\d+'))) { 210 | _spans.add(HighlightSpan(HighlightType.number, 211 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 212 | continue; 213 | } 214 | 215 | /// Integer 216 | if (_scanner.scan(RegExp(r'\d+'))) { 217 | _spans.add(HighlightSpan(HighlightType.number, 218 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 219 | continue; 220 | } 221 | 222 | /// Punctuation 223 | if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) { 224 | _spans.add(HighlightSpan(HighlightType.punctuation, 225 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 226 | continue; 227 | } 228 | 229 | /// Meta data 230 | if (_scanner.scan(RegExp(r'@\w+'))) { 231 | _spans.add(HighlightSpan(HighlightType.keyword, 232 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 233 | continue; 234 | } 235 | 236 | /// Words 237 | if (_scanner.scan(RegExp(r'\w+'))) { 238 | HighlightType? type; 239 | 240 | String word = _scanner.lastMatch![0]!; 241 | if (word.startsWith('_')) { 242 | word = word.substring(1); 243 | } 244 | 245 | if (_keywords.contains(word)) { 246 | type = HighlightType.keyword; 247 | } else if (_builtInTypes.contains(word)) { 248 | type = HighlightType.keyword; 249 | } else if (_firstLetterIsUpperCase(word)) { 250 | type = HighlightType.klass; 251 | } else if (word.length >= 2 && 252 | word.startsWith('k') && 253 | _firstLetterIsUpperCase(word.substring(1))) { 254 | type = HighlightType.constant; 255 | } 256 | if (type != null) { 257 | _spans.add(HighlightSpan( 258 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 259 | } 260 | } 261 | 262 | /// Check if this loop did anything 263 | if (lastLoopPosition == _scanner.position) { 264 | /// Failed to parse this file, abort gracefully 265 | return false; 266 | } 267 | lastLoopPosition = _scanner.position; 268 | } 269 | 270 | _simplify(); 271 | return true; 272 | } 273 | 274 | void _simplify() { 275 | for (int i = _spans.length - 2; i >= 0; i -= 1) { 276 | if (_spans[i].type == _spans[i + 1].type && 277 | _spans[i].end == _spans[i + 1].start) { 278 | _spans[i] = 279 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 280 | _spans.removeAt(i + 1); 281 | } 282 | } 283 | } 284 | 285 | bool _firstLetterIsUpperCase(String str) { 286 | if (str.isNotEmpty) { 287 | final String first = str.substring(0, 1); 288 | return first == first.toUpperCase(); 289 | } 290 | return false; 291 | } 292 | } 293 | -------------------------------------------------------------------------------- /lib/src/syntax/index.dart: -------------------------------------------------------------------------------- 1 | export '../theme/theme.dart'; 2 | export 'base.dart'; 3 | export 'c.dart'; 4 | export 'cpp.dart'; 5 | export 'dart.dart'; 6 | export 'java.dart'; 7 | export 'javascript.dart'; 8 | export 'kotlin.dart'; 9 | export 'lua.dart'; 10 | export 'python.dart'; 11 | export 'rust.dart'; 12 | export 'swift.dart'; 13 | export 'yaml.dart'; 14 | -------------------------------------------------------------------------------- /lib/src/syntax/java.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | import 'index.dart'; 4 | 5 | class JavaSyntaxHighlighter extends SyntaxBase { 6 | JavaSyntaxHighlighter([this.syntaxTheme]) { 7 | _spans = []; 8 | syntaxTheme ??= SyntaxTheme.dracula(); 9 | } 10 | 11 | @override 12 | Syntax get type => Syntax.JAVA; 13 | 14 | @override 15 | SyntaxTheme? syntaxTheme; 16 | 17 | static const List _keywords = const [ 18 | 'abstract', 19 | 'assert', 20 | 'break', 21 | 'case', 22 | 'catch', 23 | 'class', 24 | 'continue', 25 | 'default', 26 | 'do', 27 | 'else', 28 | 'enum', 29 | 'extends', 30 | 'final', 31 | 'finally', 32 | 'for', 33 | 'if', 34 | 'implements', 35 | 'import', 36 | 'instanceof', 37 | 'interface', 38 | 'native', 39 | 'new', 40 | 'package', 41 | 'private', 42 | 'protected', 43 | 'public', 44 | 'return', 45 | 'static', 46 | 'super', 47 | 'switch', 48 | 'synchronized', 49 | 'throw', 50 | 'throws', 51 | 'transient', 52 | 'void', 53 | 'volatile', 54 | 'while' 55 | ]; 56 | 57 | static const List _builtInTypes = const [ 58 | 'byte', 59 | 'short', 60 | 'int', 61 | 'long', 62 | 'float', 63 | 'double', 64 | 'boolean', 65 | 'char' 66 | ]; 67 | 68 | late String _src; 69 | late StringScanner _scanner; 70 | 71 | late List _spans; 72 | 73 | TextSpan format(String src) { 74 | _src = src; 75 | _scanner = StringScanner(_src); 76 | 77 | if (_generateSpans()) { 78 | /// Successfully parsed the code 79 | final List formattedText = []; 80 | int currentPosition = 0; 81 | 82 | for (HighlightSpan span in _spans) { 83 | if (currentPosition != span.start) { 84 | formattedText 85 | .add(TextSpan(text: _src.substring(currentPosition, span.start))); 86 | } 87 | formattedText.add(TextSpan( 88 | style: span.textStyle(syntaxTheme), text: span.textForSpan(_src))); 89 | 90 | currentPosition = span.end; 91 | } 92 | 93 | if (currentPosition != _src.length) { 94 | formattedText 95 | .add(TextSpan(text: _src.substring(currentPosition, _src.length))); 96 | } 97 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 98 | } else { 99 | /// Parsing failed, return with only basic formatting 100 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 101 | } 102 | } 103 | 104 | bool _generateSpans() { 105 | int lastLoopPosition = _scanner.position; 106 | 107 | while (!_scanner.isDone) { 108 | /// Skip White space 109 | _scanner.scan(RegExp(r'\s+')); 110 | 111 | /// Block comments 112 | if (_scanner.scan(RegExp('/\\*+[^*]*\\*+(?:[^/*][^*]*\\*+)*/'))) { 113 | _spans.add(HighlightSpan(HighlightType.comment, 114 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 115 | continue; 116 | } 117 | 118 | /// Line comments 119 | if (_scanner.scan('//')) { 120 | final int startComment = _scanner.lastMatch!.start; 121 | bool eof = false; 122 | int endComment; 123 | if (_scanner.scan(RegExp(r'.*'))) { 124 | endComment = _scanner.lastMatch!.end; 125 | } else { 126 | eof = true; 127 | endComment = _src.length; 128 | } 129 | _spans.add( 130 | HighlightSpan(HighlightType.comment, startComment, endComment)); 131 | 132 | if (eof) { 133 | break; 134 | } 135 | 136 | continue; 137 | } 138 | 139 | /// Raw r"String" 140 | if (_scanner.scan(RegExp(r'r".*"'))) { 141 | _spans.add(HighlightSpan(HighlightType.string, 142 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 143 | continue; 144 | } 145 | 146 | /// Multiline """String""" 147 | if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { 148 | _spans.add(HighlightSpan(HighlightType.string, 149 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 150 | continue; 151 | } 152 | 153 | /// Multiline '''String''' 154 | if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { 155 | _spans.add(HighlightSpan(HighlightType.string, 156 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 157 | continue; 158 | } 159 | 160 | /// "String" "value" 161 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 162 | _spans.add(HighlightSpan(HighlightType.string, 163 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 164 | continue; 165 | } 166 | 167 | /// 'String' 'value' 168 | if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { 169 | _spans.add(HighlightSpan(HighlightType.string, 170 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 171 | continue; 172 | } 173 | 174 | /// Double value 175 | if (_scanner.scan(RegExp(r'\d+\.\d+'))) { 176 | _spans.add(HighlightSpan(HighlightType.number, 177 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 178 | continue; 179 | } 180 | 181 | /// Integer value 182 | if (_scanner.scan(RegExp(r'\d+'))) { 183 | _spans.add(HighlightSpan(HighlightType.number, 184 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 185 | continue; 186 | } 187 | 188 | /// Punctuation 189 | if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) { 190 | _spans.add(HighlightSpan(HighlightType.punctuation, 191 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 192 | continue; 193 | } 194 | 195 | /// Meta data 196 | if (_scanner.scan(RegExp(r'@\w+'))) { 197 | _spans.add(HighlightSpan(HighlightType.keyword, 198 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 199 | continue; 200 | } 201 | 202 | /// Words 203 | if (_scanner.scan(RegExp(r'\w+'))) { 204 | HighlightType? type; 205 | 206 | String word = _scanner.lastMatch![0]!; 207 | if (word.startsWith('_')) { 208 | word = word.substring(1); 209 | } 210 | 211 | if (_keywords.contains(word)) { 212 | type = HighlightType.keyword; 213 | } else if (_builtInTypes.contains(word)) { 214 | type = HighlightType.keyword; 215 | } else if (_firstLetterIsUpperCase(word)) { 216 | type = HighlightType.klass; 217 | } else if (word.length >= 2 && 218 | word.startsWith('k') && 219 | _firstLetterIsUpperCase(word.substring(1))) { 220 | type = HighlightType.constant; 221 | } 222 | 223 | if (type != null) { 224 | _spans.add(HighlightSpan( 225 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 226 | } 227 | } 228 | 229 | /// Check if this loop did anything 230 | if (lastLoopPosition == _scanner.position) { 231 | /// Failed to parse this file, abort gracefully 232 | return false; 233 | } 234 | lastLoopPosition = _scanner.position; 235 | } 236 | 237 | _simplify(); 238 | return true; 239 | } 240 | 241 | void _simplify() { 242 | for (int i = _spans.length - 2; i >= 0; i -= 1) { 243 | if (_spans[i].type == _spans[i + 1].type && 244 | _spans[i].end == _spans[i + 1].start) { 245 | _spans[i] = 246 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 247 | _spans.removeAt(i + 1); 248 | } 249 | } 250 | } 251 | 252 | bool _firstLetterIsUpperCase(String str) { 253 | if (str.isNotEmpty) { 254 | final String first = str.substring(0, 1); 255 | return first == first.toUpperCase(); 256 | } 257 | return false; 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /lib/src/syntax/javascript.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | 4 | import 'index.dart'; 5 | 6 | class JavaScriptSyntaxHighlighter extends SyntaxBase { 7 | JavaScriptSyntaxHighlighter([this.syntaxTheme]) { 8 | _spans = []; 9 | syntaxTheme ??= SyntaxTheme.dracula(); 10 | } 11 | 12 | @override 13 | Syntax get type => Syntax.JAVASCRIPT; 14 | 15 | @override 16 | SyntaxTheme? syntaxTheme; 17 | 18 | static const List _keywords = const [ 19 | 'break', 20 | 'debugger', 21 | 'export', 22 | 'finally', 23 | 'in', 24 | 'let', 25 | 'null', 26 | 'public', 27 | 'super', 28 | 'try', 29 | 'arguments', 30 | 'byte', 31 | 'class', 32 | 'default', 33 | 'else', 34 | 'extends', 35 | 'if', 36 | 'instanceof', 37 | 'package', 38 | 'return', 39 | 'switch', 40 | 'typeof', 41 | 'while', 42 | 'await', 43 | 'case', 44 | 'delete', 45 | 'enum', 46 | 'false', 47 | 'implements', 48 | 'private', 49 | 'with', 50 | 'catch', 51 | 'continue', 52 | 'do', 53 | 'eval', 54 | 'function', 55 | 'import', 56 | 'interface', 57 | 'new', 58 | 'protected', 59 | 'static', 60 | 'this', 61 | 'true', 62 | 'void', 63 | 'yield' 64 | ]; 65 | 66 | static const List _builtInTypes = const [ 67 | 'let', 68 | 'var', 69 | 'const' 70 | ]; 71 | 72 | late String _src; 73 | late StringScanner _scanner; 74 | 75 | late List _spans; 76 | 77 | TextSpan format(String src) { 78 | _src = src; 79 | _scanner = StringScanner(_src); 80 | 81 | if (_generateSpans()) { 82 | /// Successfully parsed the code 83 | final List formattedText = []; 84 | int currentPosition = 0; 85 | 86 | for (HighlightSpan span in _spans) { 87 | if (currentPosition != span.start) { 88 | formattedText 89 | .add(TextSpan(text: _src.substring(currentPosition, span.start))); 90 | } 91 | formattedText.add(TextSpan( 92 | style: span.textStyle(syntaxTheme), text: span.textForSpan(_src))); 93 | 94 | currentPosition = span.end; 95 | } 96 | 97 | if (currentPosition != _src.length) { 98 | formattedText 99 | .add(TextSpan(text: _src.substring(currentPosition, _src.length))); 100 | } 101 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 102 | } else { 103 | /// Parsing failed, return with only basic formatting 104 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 105 | } 106 | } 107 | 108 | bool _generateSpans() { 109 | int lastLoopPosition = _scanner.position; 110 | 111 | while (!_scanner.isDone) { 112 | /// Skip White space 113 | _scanner.scan(RegExp(r'\s+')); 114 | 115 | /// Block comments 116 | if (_scanner.scan(RegExp('/\\*+[^*]*\\*+(?:[^/*][^*]*\\*+)*/'))) { 117 | _spans.add(HighlightSpan(HighlightType.comment, 118 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 119 | continue; 120 | } 121 | 122 | /// Line comments 123 | if (_scanner.scan('//')) { 124 | final int startComment = _scanner.lastMatch!.start; 125 | bool eof = false; 126 | int endComment; 127 | if (_scanner.scan(RegExp(r'.*'))) { 128 | endComment = _scanner.lastMatch!.end; 129 | } else { 130 | eof = true; 131 | endComment = _src.length; 132 | } 133 | _spans.add( 134 | HighlightSpan(HighlightType.comment, startComment, endComment)); 135 | 136 | if (eof) { 137 | break; 138 | } 139 | 140 | continue; 141 | } 142 | 143 | /// Raw r"String" 144 | if (_scanner.scan(RegExp(r'r".*"'))) { 145 | _spans.add(HighlightSpan(HighlightType.string, 146 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 147 | continue; 148 | } 149 | 150 | /// Raw r'String' 151 | if (_scanner.scan(RegExp(r"r'.*'"))) { 152 | _spans.add(HighlightSpan(HighlightType.string, 153 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 154 | continue; 155 | } 156 | 157 | /// Multiline """String""" 158 | if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { 159 | _spans.add(HighlightSpan(HighlightType.string, 160 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 161 | continue; 162 | } 163 | 164 | /// Multiline '''String''' 165 | if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { 166 | _spans.add(HighlightSpan(HighlightType.string, 167 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 168 | continue; 169 | } 170 | 171 | /// "String" "value" 172 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 173 | _spans.add(HighlightSpan(HighlightType.string, 174 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 175 | continue; 176 | } 177 | 178 | /// 'String' 'value' 179 | if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { 180 | _spans.add(HighlightSpan(HighlightType.string, 181 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 182 | continue; 183 | } 184 | 185 | /// Double value 186 | if (_scanner.scan(RegExp(r'\d+\.\d+'))) { 187 | _spans.add(HighlightSpan(HighlightType.number, 188 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 189 | continue; 190 | } 191 | 192 | /// Integer value 193 | if (_scanner.scan(RegExp(r'\d+'))) { 194 | _spans.add(HighlightSpan(HighlightType.number, 195 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 196 | continue; 197 | } 198 | 199 | /// Punctuation 200 | if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) { 201 | _spans.add(HighlightSpan(HighlightType.punctuation, 202 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 203 | continue; 204 | } 205 | 206 | /// Meta data 207 | if (_scanner.scan(RegExp(r'@\w+'))) { 208 | _spans.add(HighlightSpan(HighlightType.keyword, 209 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 210 | continue; 211 | } 212 | 213 | /// Words 214 | if (_scanner.scan(RegExp(r'\w+'))) { 215 | HighlightType? type; 216 | 217 | String word = _scanner.lastMatch![0]!; 218 | if (word.startsWith('_')) { 219 | word = word.substring(1); 220 | } 221 | 222 | if (_keywords.contains(word)) { 223 | type = HighlightType.keyword; 224 | } else if (_builtInTypes.contains(word)) { 225 | type = HighlightType.keyword; 226 | } else if (_firstLetterIsUpperCase(word)) { 227 | type = HighlightType.klass; 228 | } else if (word.length >= 2 && 229 | word.startsWith('k') && 230 | _firstLetterIsUpperCase(word.substring(1))) { 231 | type = HighlightType.constant; 232 | } 233 | 234 | if (type != null) { 235 | _spans.add(HighlightSpan( 236 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 237 | } 238 | } 239 | 240 | /// Check if this loop did anything 241 | if (lastLoopPosition == _scanner.position) { 242 | /// Failed to parse this file, abort gracefully 243 | return false; 244 | } 245 | lastLoopPosition = _scanner.position; 246 | } 247 | 248 | _simplify(); 249 | return true; 250 | } 251 | 252 | void _simplify() { 253 | for (int i = _spans.length - 2; i >= 0; i -= 1) { 254 | if (_spans[i].type == _spans[i + 1].type && 255 | _spans[i].end == _spans[i + 1].start) { 256 | _spans[i] = 257 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 258 | _spans.removeAt(i + 1); 259 | } 260 | } 261 | } 262 | 263 | bool _firstLetterIsUpperCase(String str) { 264 | if (str.isNotEmpty) { 265 | final String first = str.substring(0, 1); 266 | return first == first.toUpperCase(); 267 | } 268 | return false; 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /lib/src/syntax/lua.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | 4 | import 'index.dart'; 5 | 6 | class LuaSyntaxHighlighter extends SyntaxBase { 7 | LuaSyntaxHighlighter([this.syntaxTheme]) { 8 | _spans = []; 9 | syntaxTheme ??= SyntaxTheme.dracula(); 10 | } 11 | 12 | @override 13 | Syntax get type => Syntax.LUA; 14 | 15 | @override 16 | SyntaxTheme? syntaxTheme; 17 | 18 | static const List _keywords = [ 19 | 'and', 20 | 'break', 21 | 'do', 22 | 'else', 23 | 'elseif', 24 | 'end', 25 | 'false', 26 | 'for', 27 | 'function', 28 | 'if', 29 | 'in', 30 | 'local', 31 | 'nil', 32 | 'not', 33 | 'or', 34 | 'repeat', 35 | 'return', 36 | 'then', 37 | 'true', 38 | 'until', 39 | 'while', 40 | ]; 41 | 42 | static const List _builtInFunctions = [ 43 | 'assert', 44 | 'collectgarbage', 45 | 'dofile', 46 | 'error', 47 | 'getmetatable', 48 | 'ipairs', 49 | 'load', 50 | 'loadfile', 51 | 'next', 52 | 'pairs', 53 | 'pcall', 54 | 'print', 55 | 'rawequal', 56 | 'rawget', 57 | 'rawlen', 58 | 'rawset', 59 | 'require', 60 | 'select', 61 | 'setmetatable', 62 | 'tonumber', 63 | 'tostring', 64 | 'type', 65 | 'xpcall', 66 | ]; 67 | 68 | late String _src; 69 | late StringScanner _scanner; 70 | late List _spans; 71 | 72 | @override 73 | TextSpan format(String src) { 74 | _src = src; 75 | _scanner = StringScanner(_src); 76 | 77 | if (_generateSpans()) { 78 | /// Successfully parsed the code 79 | final List formattedText = []; 80 | int currentPosition = 0; 81 | 82 | for (HighlightSpan span in _spans) { 83 | if (currentPosition > span.start) continue; 84 | if (currentPosition != span.start) { 85 | formattedText.add( 86 | TextSpan( 87 | text: _src.substring(currentPosition, span.start), 88 | ), 89 | ); 90 | } 91 | 92 | formattedText.add(TextSpan( 93 | style: span.textStyle(syntaxTheme), 94 | text: span.textForSpan(_src), 95 | )); 96 | 97 | currentPosition = span.end; 98 | } 99 | 100 | if (currentPosition != _src.length) { 101 | formattedText.add(TextSpan( 102 | text: _src.substring(currentPosition, _src.length), 103 | )); 104 | } 105 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 106 | } else { 107 | /// Parsing failed, return with only basic formatting 108 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 109 | } 110 | } 111 | 112 | bool _generateSpans() { 113 | int lastLoopPosition = _scanner.position; 114 | 115 | while (!_scanner.isDone) { 116 | /// Skip White space 117 | _scanner.scan(RegExp(r'\s+')); 118 | 119 | /// Block comments 120 | if (_scanner.scan(RegExp(r'--\[(=*)\[[\s\S]*?\]\1\]'))) { 121 | _spans.add(HighlightSpan(HighlightType.comment, 122 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 123 | continue; 124 | } 125 | 126 | /// Line comments 127 | if (_scanner.scan(RegExp(r'--(?!\[)[^\n]*'))) { 128 | _spans.add(HighlightSpan(HighlightType.comment, 129 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 130 | continue; 131 | } 132 | 133 | /// String literals 134 | if (_scanner.scan(RegExp(r'\[(=*)\[[\s\S]*?\]\1\]'))) { 135 | _spans.add(HighlightSpan(HighlightType.string, 136 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 137 | continue; 138 | } 139 | 140 | /// Double quote Strings 141 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 142 | _spans.add(HighlightSpan(HighlightType.string, 143 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 144 | continue; 145 | } 146 | 147 | /// Single quote Strings 148 | if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { 149 | _spans.add(HighlightSpan(HighlightType.string, 150 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 151 | continue; 152 | } 153 | 154 | /// Numbers 155 | if (_scanner.scan(RegExp(r'\d+\.\d+([eE][+-]?\d+)?'))) { 156 | _spans.add(HighlightSpan(HighlightType.number, 157 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 158 | continue; 159 | } 160 | if (_scanner.scan(RegExp(r'\.\d+([eE][+-]?\d+)?'))) { 161 | _spans.add(HighlightSpan(HighlightType.number, 162 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 163 | continue; 164 | } 165 | if (_scanner.scan(RegExp(r'\d+([eE][+-]?\d+)?'))) { 166 | _spans.add(HighlightSpan(HighlightType.number, 167 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 168 | continue; 169 | } 170 | 171 | /// Operators 172 | if (_scanner.scan(RegExp(r'[\[\]{}().,;:+\-*/%^#<>~=]'))) { 173 | _spans.add(HighlightSpan(HighlightType.punctuation, 174 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 175 | continue; 176 | } 177 | 178 | /// Identifiers 179 | if (_scanner.scan(RegExp(r'\w+'))) { 180 | HighlightType? type; 181 | String word = _scanner.lastMatch![0]!; 182 | if (_keywords.contains(word)) { 183 | type = HighlightType.keyword; 184 | } else if (_builtInFunctions.contains(word)) { 185 | type = HighlightType.keyword; 186 | } 187 | if (type != null) { 188 | _spans.add(HighlightSpan( 189 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 190 | } 191 | continue; 192 | } 193 | 194 | /// Check if this loop did anything 195 | if (lastLoopPosition == _scanner.position) { 196 | /// Failed to parse this file, abort gracefully 197 | return false; 198 | } 199 | lastLoopPosition = _scanner.position; 200 | } 201 | 202 | _simplify(); 203 | return true; 204 | } 205 | 206 | void _simplify() { 207 | for (int i = _spans.length - 2; i >= 0; i--) { 208 | if (_spans[i].type == _spans[i + 1].type && 209 | _spans[i].end == _spans[i + 1].start) { 210 | _spans[i] = 211 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 212 | _spans.removeAt(i + 1); 213 | } 214 | } 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /lib/src/syntax/python.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | import 'index.dart'; 4 | 5 | class PythonSyntaxHighlighter extends SyntaxBase { 6 | PythonSyntaxHighlighter([this.syntaxTheme]) { 7 | _spans = []; 8 | syntaxTheme ??= SyntaxTheme.dracula(); 9 | } 10 | 11 | @override 12 | Syntax get type => Syntax.PYTHON; 13 | 14 | @override 15 | SyntaxTheme? syntaxTheme; 16 | 17 | static const List _keywords = const [ 18 | 'import', 19 | 'as', 20 | 'from', 21 | 'raise', 22 | 'match', 23 | 'continue', 24 | 'else', 25 | 'for', 26 | 'if', 27 | 'else', 28 | 'elif', 29 | 'return', 30 | 'def', 31 | 'case', 32 | 'while', 33 | 'expect', 34 | 'try', 35 | 'break', 36 | 'class', 37 | 'assert', 38 | 'return', 39 | 'finally', 40 | 'del', 41 | 'yield' 42 | ]; 43 | 44 | static const List _builtInTypes = const [ 45 | 'str', 46 | 'bool', 47 | 'bytes', 48 | 'int', 49 | 'tuple', 50 | 'list', 51 | 'dict', 52 | 'float', 53 | 'None' 54 | ]; 55 | 56 | late String _src; 57 | late StringScanner _scanner; 58 | 59 | late List _spans; 60 | 61 | TextSpan format(String src) { 62 | _src = src; 63 | _scanner = StringScanner(_src); 64 | 65 | if (_generateSpans()) { 66 | /// Successfully parsed the code 67 | final List formattedText = []; 68 | int currentPosition = 0; 69 | 70 | for (HighlightSpan span in _spans) { 71 | if (currentPosition > span.start) { 72 | continue; 73 | } 74 | if (currentPosition != span.start) { 75 | formattedText.add( 76 | TextSpan( 77 | text: _src.substring(currentPosition, span.start), 78 | ), 79 | ); 80 | } 81 | 82 | formattedText.add(TextSpan( 83 | style: span.textStyle(syntaxTheme), 84 | text: span.textForSpan(_src), 85 | )); 86 | 87 | currentPosition = span.end; 88 | } 89 | 90 | if (currentPosition != _src.length) { 91 | formattedText.add(TextSpan( 92 | text: _src.substring(currentPosition, _src.length), 93 | )); 94 | } 95 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 96 | } else { 97 | /// Parsing failed, return with only basic formatting 98 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 99 | } 100 | } 101 | 102 | bool _generateSpans() { 103 | int lastLoopPosition = _scanner.position; 104 | 105 | while (!_scanner.isDone) { 106 | /// Skip White space 107 | _scanner.scan(RegExp(r'\s+')); 108 | 109 | /// Block comments 110 | if (_scanner.scan(RegExp('\"\"\"(.)*[\n]*\"\"\"'))) { 111 | _spans.add(HighlightSpan(HighlightType.comment, 112 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 113 | continue; 114 | } 115 | 116 | /// Line comments 117 | if (_scanner.scan('#')) { 118 | final int startComment = _scanner.lastMatch!.start; 119 | bool eof = false; 120 | int endComment; 121 | if (_scanner.scan(RegExp(r'.*'))) { 122 | endComment = _scanner.lastMatch!.end; 123 | } else { 124 | eof = true; 125 | endComment = _src.length; 126 | } 127 | _spans.add( 128 | HighlightSpan(HighlightType.comment, startComment, endComment)); 129 | 130 | if (eof) { 131 | break; 132 | } 133 | 134 | continue; 135 | } 136 | 137 | /// Raw R"String" 138 | if (_scanner.scan(RegExp(r'[rR]".*"'))) { 139 | _spans.add(HighlightSpan(HighlightType.string, 140 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 141 | continue; 142 | } 143 | 144 | /// Multiline """String""" 145 | if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { 146 | _spans.add(HighlightSpan(HighlightType.string, 147 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 148 | continue; 149 | } 150 | 151 | /// Multiline '''String''' 152 | if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { 153 | _spans.add(HighlightSpan(HighlightType.string, 154 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 155 | continue; 156 | } 157 | 158 | /// "String" "value" 159 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 160 | _spans.add(HighlightSpan(HighlightType.string, 161 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 162 | continue; 163 | } 164 | 165 | /// 'String' 'value' 166 | if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { 167 | _spans.add(HighlightSpan(HighlightType.string, 168 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 169 | continue; 170 | } 171 | 172 | /// Float value x.x .x 173 | if (_scanner.scan(RegExp(r'\d+\.\d+|.\d+'))) { 174 | _spans.add(HighlightSpan(HighlightType.number, 175 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 176 | continue; 177 | } 178 | 179 | /// Integer value 180 | if (_scanner.scan(RegExp(r'\d+'))) { 181 | _spans.add(HighlightSpan(HighlightType.number, 182 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 183 | continue; 184 | } 185 | 186 | /// Punctuation TEST: https://www.regexpal.com/100066 187 | if (_scanner.scan(RegExp(r'[\[\]{}().!=><#&\|\?\+\-\*/%\^~;:,]'))) { 188 | _spans.add(HighlightSpan(HighlightType.punctuation, 189 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 190 | continue; 191 | } 192 | 193 | /// Meta data 194 | if (_scanner.scan(RegExp(r'@\w+'))) { 195 | _spans.add(HighlightSpan(HighlightType.keyword, 196 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 197 | continue; 198 | } 199 | 200 | /// Words 201 | if (_scanner.scan(RegExp(r'\w+'))) { 202 | HighlightType? type; 203 | 204 | String word = _scanner.lastMatch![0]!; 205 | if (word.startsWith('_')) { 206 | word = word.substring(1); 207 | } 208 | 209 | if (_keywords.contains(word)) { 210 | type = HighlightType.keyword; 211 | } else if (_builtInTypes.contains(word)) { 212 | type = HighlightType.keyword; 213 | } else if (_firstLetterIsUpperCase(word)) { 214 | type = HighlightType.klass; 215 | } else if (word.length >= 2 && 216 | word.startsWith('k') && 217 | _firstLetterIsUpperCase(word.substring(1))) { 218 | type = HighlightType.constant; 219 | } 220 | if (type != null) { 221 | _spans.add(HighlightSpan( 222 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 223 | } 224 | } 225 | 226 | /// Check if this loop did anything 227 | if (lastLoopPosition == _scanner.position) { 228 | /// Failed to parse this file, abort gracefully 229 | return false; 230 | } 231 | lastLoopPosition = _scanner.position; 232 | } 233 | 234 | _simplify(); 235 | return true; 236 | } 237 | 238 | void _simplify() { 239 | for (int i = _spans.length - 2; i >= 0; i -= 1) { 240 | if (_spans[i].type == _spans[i + 1].type && 241 | _spans[i].end == _spans[i + 1].start) { 242 | _spans[i] = 243 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 244 | _spans.removeAt(i + 1); 245 | } 246 | } 247 | } 248 | 249 | bool _firstLetterIsUpperCase(String str) { 250 | if (str.isNotEmpty) { 251 | final String first = str.substring(0, 1); 252 | return first == first.toUpperCase(); 253 | } 254 | return false; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /lib/src/syntax/rust.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | import 'index.dart'; 4 | 5 | class RustSyntaxHighlighter extends SyntaxBase { 6 | RustSyntaxHighlighter([this.syntaxTheme]) { 7 | _spans = []; 8 | syntaxTheme ??= SyntaxTheme.dracula(); 9 | } 10 | 11 | @override 12 | Syntax get type => Syntax.RUST; 13 | 14 | @override 15 | SyntaxTheme? syntaxTheme; 16 | 17 | /// List of Rust keywords for syntax highlighting 18 | static const List _keywords = [ 19 | 'as', 20 | 'async', 21 | 'await', 22 | 'break', 23 | 'const', 24 | 'continue', 25 | 'crate', 26 | 'dyn', 27 | 'else', 28 | 'enum', 29 | 'extern', 30 | 'false', 31 | 'fn', 32 | 'for', 33 | 'if', 34 | 'impl', 35 | 'in', 36 | 'let', 37 | 'loop', 38 | 'match', 39 | 'mod', 40 | 'move', 41 | 'mut', 42 | 'pub', 43 | 'ref', 44 | 'return', 45 | 'self', 46 | 'Self', 47 | 'static', 48 | 'struct', 49 | 'super', 50 | 'trait', 51 | 'true', 52 | 'type', 53 | 'unsafe', 54 | 'use', 55 | 'where', 56 | 'while', 57 | 'abstract', 58 | 'final', 59 | 'override', 60 | 'macro', 61 | 'try', 62 | 'union', 63 | 'yield', 64 | 'macro_rules' 65 | ]; 66 | 67 | /// List of Rust built-in types 68 | static const List _builtInTypes = [ 69 | 'i8', 70 | 'u8', 71 | 'i16', 72 | 'u16', 73 | 'i32', 74 | 'u32', 75 | 'i64', 76 | 'u64', 77 | 'i128', 78 | 'u128', 79 | 'isize', 80 | 'usize', 81 | 'f32', 82 | 'f64', 83 | 'bool', 84 | 'char', 85 | 'str' 86 | ]; 87 | 88 | /// Source code to be highlighted 89 | late String _src; 90 | 91 | /// Scanner to tokenize input 92 | late StringScanner _scanner; 93 | 94 | /// Stores highlighted spans 95 | late List _spans; 96 | 97 | /// Formats the input source code into a styled [TextSpan] 98 | TextSpan format(String src) { 99 | _src = src; 100 | _scanner = StringScanner(_src); 101 | 102 | if (_generateSpans()) { 103 | // If parsing is successful, create styled spans 104 | final List formattedText = []; 105 | int currentPosition = 0; 106 | 107 | for (HighlightSpan span in _spans) { 108 | // Add plain text before the current span 109 | if (currentPosition != span.start) { 110 | formattedText.add(TextSpan( 111 | text: _src.substring(currentPosition, span.start), 112 | )); 113 | } 114 | 115 | // Add the highlighted span 116 | formattedText.add(TextSpan( 117 | style: span.textStyle(syntaxTheme), 118 | text: span.textForSpan(_src), 119 | )); 120 | 121 | currentPosition = span.end; 122 | } 123 | 124 | // Add any remaining text after the last span 125 | if (currentPosition != _src.length) { 126 | formattedText.add(TextSpan( 127 | text: _src.substring(currentPosition), 128 | )); 129 | } 130 | 131 | // Return a [TextSpan] with all styled spans 132 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 133 | } else { 134 | // If parsing fails, return plain text 135 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 136 | } 137 | } 138 | 139 | /// Tokenizes the source code and generates spans for highlighting 140 | bool _generateSpans() { 141 | int lastLoopPosition = _scanner.position; 142 | 143 | while (!_scanner.isDone) { 144 | _scanner.scan(RegExp(r'\s+')); // Skip whitespace 145 | 146 | // Handle single-line comments (e.g., `// comment`) 147 | if (_scanner.scan('//')) { 148 | final start = _scanner.lastMatch!.start; 149 | _scanner.scan(RegExp(r'.*')); // Capture the rest of the line 150 | _spans.add( 151 | HighlightSpan(HighlightType.comment, start, _scanner.position)); 152 | continue; 153 | } 154 | 155 | // Handle raw strings (e.g., `r#"raw string"#`) 156 | if (_scanner.scan(RegExp(r'r#"(.*?)"#', dotAll: true))) { 157 | _spans.add(HighlightSpan(HighlightType.string, 158 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 159 | continue; 160 | } 161 | 162 | // Handle regular strings (e.g., `"string"`) 163 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 164 | _spans.add(HighlightSpan(HighlightType.string, 165 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 166 | continue; 167 | } 168 | 169 | // Handle numbers (e.g., integers, floats, binary, hex, octal) 170 | if (_scanner.scan(RegExp( 171 | r'\b0b[01_]+\b|\b0o[0-7_]+\b|\b0x[\da-fA-F_]+\b|\b\d+(_\d+)*(\.\d+)?\b'))) { 172 | _spans.add(HighlightSpan(HighlightType.number, 173 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 174 | continue; 175 | } 176 | 177 | // Handle attributes (e.g., `#[attribute]`) 178 | if (_scanner.scan(RegExp(r'#\[.*?\]', dotAll: true))) { 179 | _spans.add(HighlightSpan(HighlightType.keyword, 180 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 181 | continue; 182 | } 183 | 184 | // Handle punctuation (e.g., `{`, `}`, `;`, etc.) 185 | if (_scanner.scan(RegExp(r'[()\[\]{}:;.,<>/*&|~!=+\-@$%^?]'))) { 186 | _spans.add(HighlightSpan(HighlightType.punctuation, 187 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 188 | continue; 189 | } 190 | 191 | // Handle words (keywords, types, and class names) 192 | if (_scanner.scan(RegExp(r'\b\w+\b'))) { 193 | final word = _scanner.lastMatch![0]!; 194 | HighlightType? type; 195 | 196 | // Determine the type of the word 197 | if (_keywords.contains(word)) { 198 | type = HighlightType.keyword; // Highlight as a keyword 199 | } else if (_builtInTypes.contains(word)) { 200 | type = HighlightType.keyword; // Highlight as a type 201 | } else if (word.startsWith('r#')) { 202 | type = 203 | HighlightType.string; // Highlight raw strings starting with `r#` 204 | } else if (_firstLetterIsUpperCase(word)) { 205 | type = HighlightType.klass; // Highlight class names 206 | } 207 | 208 | // Add the span if a type is determined 209 | if (type != null) { 210 | _spans.add(HighlightSpan( 211 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 212 | } 213 | continue; 214 | } 215 | 216 | // If no match is found, exit to avoid infinite loop 217 | if (lastLoopPosition == _scanner.position) { 218 | return false; // Parsing failed 219 | } 220 | lastLoopPosition = _scanner.position; 221 | } 222 | 223 | _simplify(); 224 | return true; 225 | } 226 | 227 | /// Simplifies spans by merging adjacent ones of the same type 228 | void _simplify() { 229 | for (int i = _spans.length - 2; i >= 0; i--) { 230 | if (_spans[i].type == _spans[i + 1].type && 231 | _spans[i].end == _spans[i + 1].start) { 232 | // Merge the spans 233 | _spans[i] = 234 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 235 | _spans.removeAt(i + 1); // Remove the redundant span 236 | } 237 | } 238 | } 239 | 240 | /// Helper function to check if the first letter of a word is uppercase 241 | bool _firstLetterIsUpperCase(String str) { 242 | return str.isNotEmpty && str[0].toUpperCase() == str[0]; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /lib/src/syntax/swift.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | 4 | import 'index.dart'; 5 | 6 | class SwiftSyntaxHighlighter extends SyntaxBase { 7 | SwiftSyntaxHighlighter([this.syntaxTheme]) { 8 | _spans = []; 9 | syntaxTheme ??= SyntaxTheme.dracula(); 10 | } 11 | 12 | @override 13 | Syntax get type => Syntax.SWIFT; 14 | 15 | @override 16 | SyntaxTheme? syntaxTheme; 17 | 18 | static const List _keywords = const [ 19 | 'class', 20 | 'func', 21 | 'let', 22 | 'public', 23 | 'typealias', 24 | 'deinit', 25 | 'import', 26 | 'operator', 27 | 'static', 28 | 'var', 29 | 'enum', 30 | 'Init', 31 | 'private', 32 | 'struct', 33 | 'extension', 34 | 'internal', 35 | 'protocol', 36 | 'subscript', 37 | 'break', 38 | 'do', 39 | 'if', 40 | 'where', 41 | 'case', 42 | 'else', 43 | 'let', 44 | 'in', 45 | 'while', 46 | 'continue', 47 | 'fallthrough', 48 | 'return', 49 | 'default', 50 | 'for', 51 | 'switch', 52 | 'as', 53 | 'nil', 54 | 'true', 55 | '_LINE_', 56 | 'dynamicType', 57 | 'self', 58 | '_COLUMN_', 59 | 'false', 60 | 'Self', 61 | '_FILE_', 62 | 'is', 63 | 'super', 64 | '_FUNCTION_', 65 | 'associativity', 66 | 'final', 67 | 'lazy', 68 | 'nonmutating', 69 | 'precedence', 70 | 'right', 71 | 'weak', 72 | 'crossinline', 73 | 'get', 74 | 'left', 75 | 'optional', 76 | 'prefix', 77 | 'set', 78 | 'willSet', 79 | 'dynamic', 80 | 'infix', 81 | 'mutating', 82 | 'override', 83 | 'protocol', 84 | 'Type', 85 | 'didSet', 86 | 'none', 87 | 'postfix', 88 | 'required', 89 | 'unowned', 90 | ]; 91 | 92 | static const List _builtInTypes = const [ 93 | 'Int', 94 | 'Int8', 95 | 'UInt', 96 | 'Float', 97 | 'Double', 98 | 'Bool', 99 | 'String', 100 | 'Character' 101 | ]; 102 | 103 | late String _src; 104 | late StringScanner _scanner; 105 | 106 | late List _spans; 107 | 108 | TextSpan format(String src) { 109 | _src = src; 110 | _scanner = StringScanner(_src); 111 | 112 | if (_generateSpans()) { 113 | /// Successfully parsed the code 114 | final List formattedText = []; 115 | int currentPosition = 0; 116 | 117 | for (HighlightSpan span in _spans) { 118 | if (currentPosition != span.start) { 119 | formattedText 120 | .add(TextSpan(text: _src.substring(currentPosition, span.start))); 121 | } 122 | formattedText.add(TextSpan( 123 | style: span.textStyle(syntaxTheme), text: span.textForSpan(_src))); 124 | 125 | currentPosition = span.end; 126 | } 127 | 128 | if (currentPosition != _src.length) { 129 | formattedText 130 | .add(TextSpan(text: _src.substring(currentPosition, _src.length))); 131 | } 132 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 133 | } else { 134 | /// Parsing failed, return with only basic formatting 135 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 136 | } 137 | } 138 | 139 | bool _generateSpans() { 140 | int lastLoopPosition = _scanner.position; 141 | 142 | while (!_scanner.isDone) { 143 | /// Skip White space 144 | _scanner.scan(RegExp(r'\s+')); 145 | 146 | /// Block comments 147 | if (_scanner.scan(RegExp('/\\*+[^*]*\\*+(?:[^/*][^*]*\\*+)*/'))) { 148 | _spans.add(HighlightSpan(HighlightType.comment, 149 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 150 | continue; 151 | } 152 | 153 | /// Line comments 154 | if (_scanner.scan('//')) { 155 | final int startComment = _scanner.lastMatch!.start; 156 | bool eof = false; 157 | int endComment; 158 | if (_scanner.scan(RegExp(r'.*'))) { 159 | endComment = _scanner.lastMatch!.end; 160 | } else { 161 | eof = true; 162 | endComment = _src.length; 163 | } 164 | _spans.add( 165 | HighlightSpan(HighlightType.comment, startComment, endComment)); 166 | 167 | if (eof) { 168 | break; 169 | } 170 | 171 | continue; 172 | } 173 | 174 | /// Raw r"String" 175 | if (_scanner.scan(RegExp(r'r".*"'))) { 176 | _spans.add(HighlightSpan(HighlightType.string, 177 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 178 | continue; 179 | } 180 | 181 | /// Raw r'String' 182 | if (_scanner.scan(RegExp(r"r'.*'"))) { 183 | _spans.add(HighlightSpan(HighlightType.string, 184 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 185 | continue; 186 | } 187 | 188 | /// Multiline """String""" 189 | if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { 190 | _spans.add(HighlightSpan(HighlightType.string, 191 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 192 | continue; 193 | } 194 | 195 | /// Multiline '''String''' 196 | if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { 197 | _spans.add(HighlightSpan(HighlightType.string, 198 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 199 | continue; 200 | } 201 | 202 | /// "String" "value" 203 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 204 | _spans.add(HighlightSpan(HighlightType.string, 205 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 206 | continue; 207 | } 208 | 209 | /// 'String' 'value' 210 | if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { 211 | _spans.add(HighlightSpan(HighlightType.string, 212 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 213 | continue; 214 | } 215 | 216 | /// Double value 217 | if (_scanner.scan(RegExp(r'\d+\.\d+'))) { 218 | _spans.add(HighlightSpan(HighlightType.number, 219 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 220 | continue; 221 | } 222 | 223 | /// Integer value 224 | if (_scanner.scan(RegExp(r'\d+'))) { 225 | _spans.add(HighlightSpan(HighlightType.number, 226 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 227 | continue; 228 | } 229 | 230 | /// Punctuation 231 | if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) { 232 | _spans.add(HighlightSpan(HighlightType.punctuation, 233 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 234 | continue; 235 | } 236 | 237 | /// Meta data 238 | if (_scanner.scan(RegExp(r'@\w+'))) { 239 | _spans.add(HighlightSpan(HighlightType.keyword, 240 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 241 | continue; 242 | } 243 | 244 | /// Words 245 | if (_scanner.scan(RegExp(r'\w+'))) { 246 | HighlightType? type; 247 | 248 | String word = _scanner.lastMatch![0]!; 249 | if (word.startsWith('_')) { 250 | word = word.substring(1); 251 | } 252 | 253 | if (_keywords.contains(word)) { 254 | type = HighlightType.keyword; 255 | } else if (_builtInTypes.contains(word)) { 256 | type = HighlightType.keyword; 257 | } else if (_firstLetterIsUpperCase(word)) { 258 | type = HighlightType.klass; 259 | } else if (word.length >= 2 && 260 | word.startsWith('k') && 261 | _firstLetterIsUpperCase(word.substring(1))) { 262 | type = HighlightType.constant; 263 | } 264 | 265 | if (type != null) { 266 | _spans.add(HighlightSpan( 267 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 268 | } 269 | } 270 | 271 | /// Check if this loop did anything 272 | if (lastLoopPosition == _scanner.position) { 273 | /// Failed to parse this file, abort gracefully 274 | return false; 275 | } 276 | lastLoopPosition = _scanner.position; 277 | } 278 | 279 | _simplify(); 280 | return true; 281 | } 282 | 283 | void _simplify() { 284 | for (int i = _spans.length - 2; i >= 0; i -= 1) { 285 | if (_spans[i].type == _spans[i + 1].type && 286 | _spans[i].end == _spans[i + 1].start) { 287 | _spans[i] = 288 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 289 | _spans.removeAt(i + 1); 290 | } 291 | } 292 | } 293 | 294 | bool _firstLetterIsUpperCase(String str) { 295 | if (str.isNotEmpty) { 296 | final String first = str.substring(0, 1); 297 | return first == first.toUpperCase(); 298 | } 299 | return false; 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /lib/src/syntax/yaml.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:string_scanner/string_scanner.dart'; 3 | import 'index.dart'; 4 | 5 | class YamlSyntaxHighlighter extends SyntaxBase { 6 | YamlSyntaxHighlighter([this.syntaxTheme]) { 7 | _spans = []; 8 | syntaxTheme ??= SyntaxTheme.dracula(); 9 | } 10 | 11 | late String _src; 12 | 13 | late StringScanner _scanner; 14 | 15 | late List _spans; 16 | 17 | List noKeywords = [ 18 | 'http', 19 | 'https', 20 | ]; 21 | 22 | @override 23 | SyntaxTheme? syntaxTheme; 24 | 25 | @override 26 | Syntax get type => Syntax.YAML; 27 | 28 | @override 29 | TextSpan format(String src) { 30 | _src = src; 31 | _scanner = StringScanner(_src); 32 | 33 | if (_generateSpans()) { 34 | /// Successfully parsed the code 35 | final List formattedText = []; 36 | int currentPosition = 0; 37 | 38 | for (HighlightSpan span in _spans) { 39 | if (currentPosition > span.start) { 40 | continue; 41 | } 42 | if (currentPosition != span.start) { 43 | formattedText.add( 44 | TextSpan( 45 | text: _src.substring(currentPosition, span.start), 46 | ), 47 | ); 48 | } 49 | 50 | formattedText.add(TextSpan( 51 | style: span.textStyle(syntaxTheme), 52 | text: span.textForSpan(_src), 53 | )); 54 | 55 | currentPosition = span.end; 56 | } 57 | 58 | if (currentPosition != _src.length) { 59 | formattedText.add(TextSpan( 60 | text: _src.substring(currentPosition, _src.length), 61 | )); 62 | } 63 | 64 | return TextSpan(style: syntaxTheme!.baseStyle, children: formattedText); 65 | } else { 66 | /// Parsing failed, return with only basic formatting 67 | return TextSpan(style: syntaxTheme!.baseStyle, text: src); 68 | } 69 | } 70 | 71 | bool _generateSpans() { 72 | int lastLoopPosition = _scanner.position; 73 | 74 | while (!_scanner.isDone) { 75 | /// Skip White space 76 | _scanner.scan(RegExp(r'\s+')); 77 | 78 | /// Raw r"String" 79 | if (_scanner.scan(RegExp(r'r".*"'))) { 80 | _spans.add(HighlightSpan(HighlightType.string, 81 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 82 | continue; 83 | } 84 | 85 | /// Raw r'String' 86 | if (_scanner.scan(RegExp(r"r'.*'"))) { 87 | _spans.add(HighlightSpan(HighlightType.string, 88 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 89 | continue; 90 | } 91 | 92 | /// Multiline """String""" 93 | if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) { 94 | _spans.add(HighlightSpan(HighlightType.string, 95 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 96 | continue; 97 | } 98 | 99 | /// Multiline '''String''' 100 | if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) { 101 | _spans.add(HighlightSpan(HighlightType.string, 102 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 103 | continue; 104 | } 105 | 106 | /// "String" 107 | if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) { 108 | _spans.add(HighlightSpan(HighlightType.string, 109 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 110 | continue; 111 | } 112 | 113 | /// 'String' 114 | if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) { 115 | _spans.add(HighlightSpan(HighlightType.string, 116 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 117 | continue; 118 | } 119 | 120 | /// Line comments 121 | if (_scanner.scan('#')) { 122 | final int startComment = _scanner.lastMatch!.start; 123 | bool eof = false; 124 | int endComment; 125 | if (_scanner.scan(RegExp(r'.*'))) { 126 | endComment = _scanner.lastMatch!.end; 127 | } else { 128 | eof = true; 129 | endComment = _src.length; 130 | } 131 | _spans.add( 132 | HighlightSpan(HighlightType.comment, startComment, endComment)); 133 | 134 | if (eof) { 135 | break; 136 | } 137 | 138 | continue; 139 | } 140 | 141 | ///version 142 | if (_scanner.scan(RegExp(r'(\^)?[0-9]*\.[0-9]*\.[0-9]*(\+)?[0-9]*'))) { 143 | _spans.add(HighlightSpan( 144 | HighlightType.klass, 145 | _scanner.lastMatch!.start, 146 | _scanner.lastMatch!.end, 147 | )); 148 | continue; 149 | } 150 | 151 | /// Punctuation 152 | if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,""<>@]'))) { 153 | _spans.add(HighlightSpan(HighlightType.punctuation, 154 | _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 155 | continue; 156 | } 157 | 158 | /// Words 159 | if (_scanner.scan(RegExp(r'\w+'))) { 160 | HighlightType type; 161 | String? word = _scanner.lastMatch![0]; 162 | int wordEndIndex = _scanner.lastMatch!.end; 163 | if (wordEndIndex + 1 < _src.length && 164 | (_src.substring(wordEndIndex, wordEndIndex + 1) == ':' || 165 | _src.substring(wordEndIndex, wordEndIndex + 1) == '-') && 166 | !noKeywords.contains(word)) { 167 | type = HighlightType.keyword; 168 | } else { 169 | type = HighlightType.punctuation; // Treated as punctuation for now 170 | } 171 | 172 | _spans.add(HighlightSpan( 173 | type, _scanner.lastMatch!.start, _scanner.lastMatch!.end)); 174 | } 175 | 176 | /// Check if this loop did anything 177 | if (lastLoopPosition == _scanner.position) { 178 | /// Failed to parse this file, abort gracefully 179 | return false; 180 | } 181 | lastLoopPosition = _scanner.position; 182 | } 183 | 184 | _simplify(); 185 | return true; 186 | } 187 | 188 | void _simplify() { 189 | for (int i = _spans.length - 2; i >= 0; i -= 1) { 190 | if (_spans[i].type == _spans[i + 1].type && 191 | _spans[i].end == _spans[i + 1].start) { 192 | _spans[i] = 193 | HighlightSpan(_spans[i].type, _spans[i].start, _spans[i + 1].end); 194 | _spans.removeAt(i + 1); 195 | } 196 | } 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_syntax_view 2 | description: A static syntax highlighter widget which highlights code text according to the programming language syntax using native Dart code. 3 | version: 4.1.7 4 | homepage: https://github.com/baderouaich/flutter_syntax_view 5 | 6 | environment: 7 | sdk: '>=3.3.3 <4.0.0' 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | string_scanner: ^1.1.0 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | flutter: 19 | -------------------------------------------------------------------------------- /test/flutter_syntax_view_test.dart: -------------------------------------------------------------------------------- 1 | void main() {} 2 | -------------------------------------------------------------------------------- /theme_shots/ayuDark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/ayuDark.png -------------------------------------------------------------------------------- /theme_shots/ayuLight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/ayuLight.png -------------------------------------------------------------------------------- /theme_shots/dracula.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/dracula.png -------------------------------------------------------------------------------- /theme_shots/gravityDark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/gravityDark.png -------------------------------------------------------------------------------- /theme_shots/gravityLight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/gravityLight.png -------------------------------------------------------------------------------- /theme_shots/monokaiSublime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/monokaiSublime.png -------------------------------------------------------------------------------- /theme_shots/obsidian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/obsidian.png -------------------------------------------------------------------------------- /theme_shots/oceanSunset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/oceanSunset.png -------------------------------------------------------------------------------- /theme_shots/standard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/standard.png -------------------------------------------------------------------------------- /theme_shots/vscodeDark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/vscodeDark.png -------------------------------------------------------------------------------- /theme_shots/vscodeLight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baderouaich/flutter_syntax_view/f9c7f55dd577992552da5b65cb303adbd9772622/theme_shots/vscodeLight.png --------------------------------------------------------------------------------