├── .all-contributorsrc ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug-report--bug---.md │ ├── config.yml │ └── feature-request-------.md ├── jetbrains-variant.png ├── no-response.yml └── workflows │ ├── issue_labeler.yml │ └── runnable.yml ├── .gitignore ├── .metadata ├── .run ├── Generate localizations on MacOS_Linux.run.xml ├── Generate localizations on Windows.run.xml └── Generate models.run.xml ├── CODEOWNERS ├── LICENSE ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── app │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── ic_launcher-playstore.png │ │ ├── kotlin │ │ └── com │ │ │ └── fluttercandies │ │ │ └── juejin │ │ │ └── MainActivity.kt │ │ └── res │ │ ├── drawable-v21 │ │ └── launch_background.xml │ │ ├── drawable │ │ ├── ic_launcher_foreground.xml │ │ └── launch_background.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── styles.xml │ │ └── values │ │ ├── ic_launcher_background.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties ├── key.jks └── settings.gradle ├── assets ├── brand-with-text.svg ├── brand.svg └── icon │ ├── post │ └── hot_comment.png │ ├── topic │ └── pin_detail_head_bg.webp │ └── user │ ├── jy_lv1.webp │ ├── jy_lv2.webp │ ├── jy_lv3.webp │ ├── jy_lv4.webp │ ├── jy_lv5.webp │ ├── jy_lv6.webp │ ├── jy_lv7.webp │ ├── jy_lv8.webp │ ├── lv1.webp │ ├── lv2.webp │ ├── lv3.webp │ ├── lv4.webp │ ├── lv5.webp │ ├── lv6.webp │ ├── lv7.webp │ ├── lv8.webp │ ├── vip_lv1.webp │ ├── vip_lv2.webp │ ├── vip_lv3.webp │ ├── vip_lv4.webp │ └── vip_lv5.webp ├── build.yaml ├── ff_annotation_route_commands ├── ios ├── .gitignore ├── Flutter │ ├── AppFrameworkInfo.plist │ ├── Debug.xcconfig │ └── Release.xcconfig ├── Podfile ├── 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-1024.png │ │ ├── icon-20-ipad.png │ │ ├── icon-20@2x-ipad.png │ │ ├── icon-20@2x.png │ │ ├── icon-20@3x.png │ │ ├── icon-29-ipad.png │ │ ├── icon-29.png │ │ ├── icon-29@2x-ipad.png │ │ ├── icon-29@2x.png │ │ ├── icon-29@3x.png │ │ ├── icon-40.png │ │ ├── icon-40@2x.png │ │ ├── icon-40@3x.png │ │ ├── icon-60@2x.png │ │ ├── icon-60@3x.png │ │ ├── icon-76.png │ │ ├── icon-76@2x.png │ │ └── icon-83.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 ├── l10n.yaml ├── lib ├── apis │ ├── content_api.dart │ ├── interact_api.dart │ ├── passport_api.dart │ ├── recommend_api.dart │ └── tag_api.dart ├── app.dart ├── constants │ ├── constants.dart │ ├── resources.dart │ ├── screens.dart │ ├── styles.dart │ └── themes.dart ├── exports.dart ├── extensions │ ├── brightness_extension.dart │ ├── build_context_extension.dart │ ├── color_extension.dart │ ├── duration_extension.dart │ ├── future_extension.dart │ ├── num_extension.dart │ ├── state_extension.dart │ └── string_extension.dart ├── internals │ ├── instance.dart │ ├── methods.dart │ ├── navigator_observer.dart │ ├── special_text.dart │ └── urls.dart ├── l10n │ ├── app_en.arb │ ├── app_zh.arb │ └── gen │ │ ├── jj_localizations.dart │ │ ├── jj_localizations_en.dart │ │ └── jj_localizations_zh.dart ├── main.dart ├── models │ ├── data_model.d.dart │ ├── data_model.dart │ ├── data_model.g.dart │ ├── feed_model.dart │ ├── item │ │ ├── advertise_item_model.dart │ │ ├── article_item_model.dart │ │ ├── comment_item_model.dart │ │ └── post_item_model.dart │ ├── loading_base.dart │ ├── response_model.dart │ └── user_model.dart ├── pages │ ├── article │ │ └── detail.dart │ ├── club │ │ └── club.dart │ ├── components │ │ └── comments.dart │ ├── home.dart │ ├── home │ │ ├── articles.dart │ │ ├── mine.dart │ │ └── pins.dart │ └── splash.dart ├── routes │ ├── juejin_route.dart │ ├── juejin_routes.dart │ └── page_route.dart ├── utils │ ├── cache_util.dart │ ├── device_util.dart │ ├── haptic_util.dart │ ├── http_util.dart │ ├── log_util.dart │ ├── package_util.dart │ └── toast_util.dart └── widgets │ ├── _none.dart │ ├── error_widget.dart │ ├── gaps.dart │ ├── lazy_indexed_stack.dart │ ├── logo.dart │ ├── refresh │ ├── base_refresh_wrapper.dart │ ├── pull_to_refresh_header.dart │ ├── refresh_grid_wrapper.dart │ └── refresh_list_wrapper.dart │ ├── tapper.dart │ └── webview.dart ├── linux ├── .gitignore ├── CMakeLists.txt ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake ├── main.cc ├── my_application.cc └── my_application.h ├── macos ├── .gitignore ├── Flutter │ ├── Flutter-Debug.xcconfig │ ├── Flutter-Release.xcconfig │ └── GeneratedPluginRegistrant.swift ├── Podfile ├── Podfile.lock ├── 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 ├── pubspec.yaml ├── test └── api_test.dart ├── tools ├── internals │ ├── command.dart │ ├── constants.dart │ ├── defs.dart │ └── utils.dart ├── jj.dart └── src │ ├── models.dart │ ├── release.dart │ └── version.dart └── 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 /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "contributors": [ 8 | { 9 | "login": "AlexV525", 10 | "name": "Alex Li", 11 | "avatar_url": "https://avatars1.githubusercontent.com/u/15884415?v=4", 12 | "profile": "https://blog.alexv525.com", 13 | "contributions": [ 14 | "code", 15 | "design", 16 | "doc", 17 | "example", 18 | "ideas", 19 | "maintenance", 20 | "question", 21 | "review" 22 | ] 23 | }, 24 | { 25 | "login": "a1017480401", 26 | "name": "友人A", 27 | "avatar_url": "https://avatars.githubusercontent.com/u/58846244?v=4", 28 | "profile": "https://github.com/a1017480401", 29 | "contributions": [ 30 | "code" 31 | ] 32 | }, 33 | { 34 | "login": "shirne", 35 | "name": "shirne", 36 | "avatar_url": "https://avatars.githubusercontent.com/u/2263157?v=4", 37 | "profile": "https://www.shirne.com/", 38 | "contributions": [ 39 | "code", 40 | "bug", 41 | "translation" 42 | ] 43 | }, 44 | { 45 | "login": "MrDgbot", 46 | "name": "MrDgbot", 47 | "avatar_url": "https://avatars.githubusercontent.com/u/60038945?v=4", 48 | "profile": "https://github.com/MrDgbot", 49 | "contributions": [ 50 | "code" 51 | ] 52 | }, 53 | { 54 | "login": "DemoJameson", 55 | "name": "DemoJameson", 56 | "avatar_url": "https://avatars.githubusercontent.com/u/181192?v=4", 57 | "profile": "http://www.demojameson.com", 58 | "contributions": [ 59 | "code", 60 | "bug" 61 | ] 62 | }, 63 | { 64 | "login": "WeiJun0507", 65 | "name": "Wei Jun", 66 | "avatar_url": "https://avatars.githubusercontent.com/u/66726409?v=4", 67 | "profile": "https://github.com/WeiJun0507", 68 | "contributions": [ 69 | "code" 70 | ] 71 | } 72 | ], 73 | "contributorsPerLine": 7, 74 | "projectName": "flutter_juejin", 75 | "projectOwner": "fluttercandies", 76 | "repoType": "github", 77 | "repoHost": "https://github.com", 78 | "skipCi": true 79 | } 80 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.paypal.me/AlexV525', 'https://www.alexv525.com/wechat.png', 'https://www.alexv525.com/alipay.jpg'] 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report--bug---.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report (BUG模板) 3 | about: Create a bug report helping us fix it. (创建一个 BUG 报告以帮助我们进行修复) 4 | title: "[BUG] Error with something" 5 | labels: await investigate, bug 6 | 7 | --- 8 | 9 | **Describe the bug** 10 | 12 | 13 | **How to reproduce** 14 | 19 | 20 | Steps to reproduce the behavior: 21 | 22 | 23 | 1. Go to '...' 24 | 2. Click on '....' 25 | 3. Scroll down to '....' 26 | 4. Error occurred. 27 | 28 | **Expected behavior** 29 | 31 | 32 | **Screenshots (If contains)** 33 | 35 | 36 | **Version information** 37 | 38 | - Device: [e.g. iPhone X] 39 | - OS: [e.g. iOS 14.7.1] 40 | - Flutter Version: [e.g. v3.0.0] 41 | 42 | **Additional context** 43 | 45 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request-------.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request (功能请求) 3 | about: Request a new feature that the package didn't include. (请求一个依赖并未包含的功能) 4 | title: "[Feature] Request a feature with something" 5 | labels: feature, await investigate 6 | 7 | --- 8 | 9 | **Is your feature request related to a problem?** 10 | 12 | 13 | **Describe the solution you'd like** 14 | 16 | 17 | **Describe alternatives you've considered** 18 | 21 | 22 | **Additional context** 23 | 25 | 26 | **Version information** 27 | 28 | - Device: [e.g. iPhone X] 29 | - OS: [e.g. iOS 14.7.1] 30 | - Flutter Version: [e.g. v3.0.0] 31 | -------------------------------------------------------------------------------- /.github/jetbrains-variant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/.github/jetbrains-variant.png -------------------------------------------------------------------------------- /.github/no-response.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-no-response - https://github.com/probot/no-response 2 | 3 | # Number of days of inactivity before an Issue is closed for lack of response 4 | daysUntilClose: 14 5 | # Label requiring a response 6 | responseRequiredLabel: "await response" 7 | # Comment to post when closing an Issue for lack of response. Set to `false` to disable 8 | closeComment: > 9 | This issue has been automatically closed because there has been no response 10 | to our request for more information from the original author. Please reach 11 | out if you have or find the answers we need so that we can investigate further. 12 | -------------------------------------------------------------------------------- /.github/workflows/issue_labeler.yml: -------------------------------------------------------------------------------- 1 | name: "Issue Labeler" 2 | 3 | on: 4 | issues: 5 | types: [ opened ] 6 | 7 | jobs: 8 | label: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Auto label 12 | uses: Renato66/auto-label@v2.2.0 13 | with: 14 | repo-token: ${{ secrets.GITHUB_TOKEN }} 15 | ignore-comments: true 16 | default-labels: '["await triage"]' 17 | -------------------------------------------------------------------------------- /.github/workflows/runnable.yml: -------------------------------------------------------------------------------- 1 | name: Runnable (stable) 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | analyze: 10 | name: Analyze on ${{ matrix.os }} 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | matrix: 14 | os: [ ubuntu-latest ] 15 | steps: 16 | - uses: actions/checkout@v3 17 | - uses: actions/setup-java@v3 18 | with: 19 | distribution: 'adopt' 20 | java-version: '11.x' 21 | - uses: subosito/flutter-action@v2 22 | with: 23 | channel: 'stable' 24 | - name: Log Dart/Flutter versions 25 | run: | 26 | dart --version 27 | flutter --version 28 | - name: Prepare dependencies 29 | run: flutter pub get 30 | - name: Analyse the repo 31 | run: flutter analyze lib 32 | 33 | test_iOS: 34 | needs: analyze 35 | name: Test iOS on ${{ matrix.os }} 36 | runs-on: ${{ matrix.os }} 37 | strategy: 38 | matrix: 39 | os: [ macos-latest ] 40 | steps: 41 | - uses: actions/checkout@v3 42 | - uses: actions/setup-java@v3 43 | with: 44 | distribution: 'adopt' 45 | java-version: '11.x' 46 | - uses: subosito/flutter-action@v2 47 | with: 48 | architecture: x64 49 | channel: 'stable' 50 | - run: dart --version 51 | - run: flutter --version 52 | - run: flutter pub get 53 | - run: flutter build ios --no-codesign 54 | 55 | test_android: 56 | needs: analyze 57 | name: Test Android on ${{ matrix.os }} 58 | runs-on: ${{ matrix.os }} 59 | strategy: 60 | matrix: 61 | os: [ ubuntu-latest ] 62 | steps: 63 | - uses: actions/checkout@v3 64 | - uses: actions/setup-java@v3 65 | with: 66 | distribution: 'adopt' 67 | java-version: '11.x' 68 | - uses: subosito/flutter-action@v2 69 | with: 70 | channel: 'stable' 71 | - run: dart --version 72 | - run: flutter --version 73 | - run: flutter pub get 74 | - run: sudo echo "y" | sudo $ANDROID_HOME/tools/bin/sdkmanager "ndk;21.4.7075529" 75 | - run: flutter build apk --debug 76 | -------------------------------------------------------------------------------- /.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 | release/ 13 | 14 | # IntelliJ related 15 | *.iml 16 | *.ipr 17 | *.iws 18 | .idea/ 19 | 20 | # The .vscode folder contains launch configuration and tasks you configure in 21 | # VS Code which you may wish to be included in version control, so this line 22 | # is commented out by default. 23 | #.vscode/ 24 | 25 | # Flutter/Dart/Pub related 26 | **/doc/api/ 27 | **/ios/Flutter/.last_build_id 28 | .dart_tool/ 29 | .flutter-plugins 30 | .flutter-plugins-dependencies 31 | .packages 32 | .pub-cache/ 33 | .pub/ 34 | /build/ 35 | pubspec.lock 36 | lib/l10n/gen/jj_localizations_untranslated.txt 37 | 38 | # Web related 39 | lib/generated_plugin_registrant.dart 40 | 41 | # Symbolication related 42 | app.*.symbols 43 | 44 | # Obfuscation related 45 | app.*.map.json 46 | 47 | # Android Studio will place build artifacts here 48 | /android/app/debug 49 | /android/app/profile 50 | /android/app/release 51 | -------------------------------------------------------------------------------- /.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. 5 | 6 | version: 7 | revision: 762bd96f38711baf2672b8bccb0b75af46425806 8 | channel: stable 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 762bd96f38711baf2672b8bccb0b75af46425806 17 | base_revision: 762bd96f38711baf2672b8bccb0b75af46425806 18 | - platform: android 19 | create_revision: 762bd96f38711baf2672b8bccb0b75af46425806 20 | base_revision: 762bd96f38711baf2672b8bccb0b75af46425806 21 | - platform: ios 22 | create_revision: 762bd96f38711baf2672b8bccb0b75af46425806 23 | base_revision: 762bd96f38711baf2672b8bccb0b75af46425806 24 | - platform: linux 25 | create_revision: 762bd96f38711baf2672b8bccb0b75af46425806 26 | base_revision: 762bd96f38711baf2672b8bccb0b75af46425806 27 | - platform: macos 28 | create_revision: 762bd96f38711baf2672b8bccb0b75af46425806 29 | base_revision: 762bd96f38711baf2672b8bccb0b75af46425806 30 | - platform: web 31 | create_revision: 762bd96f38711baf2672b8bccb0b75af46425806 32 | base_revision: 762bd96f38711baf2672b8bccb0b75af46425806 33 | - platform: windows 34 | create_revision: 762bd96f38711baf2672b8bccb0b75af46425806 35 | base_revision: 762bd96f38711baf2672b8bccb0b75af46425806 36 | 37 | # User provided section 38 | 39 | # List of Local paths (relative to this file) that should be 40 | # ignored by the migrate tool. 41 | # 42 | # Files that are not part of the templates will be ignored by default. 43 | unmanaged_files: 44 | - 'lib/main.dart' 45 | - 'ios/Runner.xcodeproj/project.pbxproj' 46 | -------------------------------------------------------------------------------- /.run/Generate localizations on MacOS_Linux.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | -------------------------------------------------------------------------------- /.run/Generate localizations on Windows.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | -------------------------------------------------------------------------------- /.run/Generate models.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @AlexV525 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ACADEMIC PUBLIC LICENSE 2 | version 1.1 3 | 4 | Copyright (C) 2022 FlutterCandies 5 | 6 | This license contains the terms and conditions of using flutter_juejin in 7 | noncommercial settings: at academic institutions for teaching and research 8 | use and for personal or educational purposes. 9 | 10 | END OF TERMS AND CONDITIONS 11 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | analyzer: 4 | exclude: 5 | - 'lib/l10n/gen/*.dart' 6 | - "lib/models/**.g.dart" 7 | - "lib/routes/juejin_route**.dart" 8 | 9 | linter: 10 | rules: 11 | always_declare_return_types: true 12 | avoid_bool_literals_in_conditional_expressions: true 13 | avoid_classes_with_only_static_members: true 14 | avoid_print: true 15 | avoid_redundant_argument_values: true 16 | avoid_slow_async_io: true 17 | avoid_void_async: true 18 | constant_identifier_names: false 19 | directives_ordering: true 20 | prefer_const_constructors: true 21 | prefer_const_constructors_in_immutables: true 22 | prefer_const_declarations: true 23 | prefer_const_literals_to_create_immutables: true 24 | prefer_single_quotes: true 25 | require_trailing_commas: true 26 | sort_child_properties_last: true 27 | sort_constructors_first: true 28 | sort_pub_dependencies: true 29 | sort_unnamed_constructors_first: true 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion 33 30 | ndkVersion flutter.ndkVersion 31 | 32 | sourceSets { 33 | main.java.srcDirs += 'src/main/kotlin' 34 | } 35 | 36 | defaultConfig { 37 | applicationId "com.fluttercandies.juejin" 38 | minSdkVersion 21 39 | targetSdkVersion flutter.targetSdkVersion 40 | versionCode flutterVersionCode.toInteger() 41 | versionName flutterVersionName 42 | } 43 | 44 | signingConfigs { 45 | forAll { 46 | storeFile file("${rootDir.absolutePath}/key.jks") 47 | storePassword 'juejin' 48 | keyAlias 'juejin' 49 | keyPassword 'juejin' 50 | } 51 | } 52 | 53 | buildTypes { 54 | debug { 55 | signingConfig signingConfigs.forAll 56 | } 57 | profile { 58 | signingConfig signingConfigs.forAll 59 | } 60 | release { 61 | signingConfig signingConfigs.forAll 62 | } 63 | } 64 | } 65 | 66 | flutter { 67 | source '../..' 68 | } 69 | 70 | dependencies {} 71 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 16 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /android/app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/android/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/fluttercandies/juejin/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.fluttercandies.juejin 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 13 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.7.20' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.1.2' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | tasks.register("clean", Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip 7 | -------------------------------------------------------------------------------- /android/key.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/android/key.jks -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /assets/brand-with-text.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /assets/brand.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /assets/icon/post/hot_comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/post/hot_comment.png -------------------------------------------------------------------------------- /assets/icon/topic/pin_detail_head_bg.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/topic/pin_detail_head_bg.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv1.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv2.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv2.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv3.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv3.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv4.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv4.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv5.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv5.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv6.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv6.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv7.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv7.webp -------------------------------------------------------------------------------- /assets/icon/user/jy_lv8.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/jy_lv8.webp -------------------------------------------------------------------------------- /assets/icon/user/lv1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv1.webp -------------------------------------------------------------------------------- /assets/icon/user/lv2.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv2.webp -------------------------------------------------------------------------------- /assets/icon/user/lv3.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv3.webp -------------------------------------------------------------------------------- /assets/icon/user/lv4.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv4.webp -------------------------------------------------------------------------------- /assets/icon/user/lv5.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv5.webp -------------------------------------------------------------------------------- /assets/icon/user/lv6.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv6.webp -------------------------------------------------------------------------------- /assets/icon/user/lv7.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv7.webp -------------------------------------------------------------------------------- /assets/icon/user/lv8.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/lv8.webp -------------------------------------------------------------------------------- /assets/icon/user/vip_lv1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/vip_lv1.webp -------------------------------------------------------------------------------- /assets/icon/user/vip_lv2.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/vip_lv2.webp -------------------------------------------------------------------------------- /assets/icon/user/vip_lv3.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/vip_lv3.webp -------------------------------------------------------------------------------- /assets/icon/user/vip_lv4.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/vip_lv4.webp -------------------------------------------------------------------------------- /assets/icon/user/vip_lv5.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/assets/icon/user/vip_lv5.webp -------------------------------------------------------------------------------- /build.yaml: -------------------------------------------------------------------------------- 1 | targets: 2 | $default: 3 | builders: 4 | json_serializable: 5 | options: 6 | field_rename: snake 7 | explicit_to_json: true 8 | -------------------------------------------------------------------------------- /ff_annotation_route_commands: -------------------------------------------------------------------------------- 1 | --output=routes --routes-file-output=routes --super-arguments --save -------------------------------------------------------------------------------- /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 | Podfile.lock 16 | profile 17 | xcuserdata 18 | **/.generated/ 19 | Flutter/App.framework 20 | Flutter/Flutter.framework 21 | Flutter/Flutter.podspec 22 | Flutter/Generated.xcconfig 23 | Flutter/ephemeral/ 24 | Flutter/app.flx 25 | Flutter/app.zip 26 | Flutter/flutter_assets/ 27 | Flutter/flutter_export_environment.sh 28 | ServiceDefinitions.json 29 | Runner/GeneratedPluginRegistrant.* 30 | 31 | # Exceptions to above rules. 32 | !default.mode1v3 33 | !default.mode2v3 34 | !default.pbxuser 35 | !default.perspectivev3 36 | -------------------------------------------------------------------------------- /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 | 9.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | platform :ios, '9.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | def install_plugin_pods(application_path = nil, relative_symlink_dir, platform) 31 | # defined_in_file is set by CocoaPods and is a Pathname to the Podfile. 32 | application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file) 33 | raise 'Could not find application path' unless application_path 34 | 35 | # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock 36 | # referring to absolute paths on developers' machines. 37 | 38 | symlink_dir = File.expand_path(relative_symlink_dir, application_path) 39 | system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils. 40 | 41 | symlink_plugins_dir = File.expand_path('plugins', symlink_dir) 42 | system('mkdir', '-p', symlink_plugins_dir) 43 | 44 | plugins_file = File.join(application_path, '..', '.flutter-plugins-dependencies') 45 | plugin_pods = flutter_parse_plugins_file(plugins_file, platform) 46 | plugin_pods.each do |plugin_hash| 47 | plugin_name = plugin_hash['name'] 48 | plugin_path = plugin_hash['path'] 49 | has_native_build = plugin_hash.fetch('native_build', true) 50 | if (plugin_name && plugin_path && has_native_build) 51 | specPath = "#{plugin_path}/#{platform}/#{plugin_name}.podspec" 52 | pod plugin_name, :path => specPath 53 | end 54 | end 55 | end 56 | 57 | target 'Runner' do 58 | use_frameworks! 59 | use_modular_headers! 60 | 61 | flutter_install_ios_engine_pod(File.dirname(File.realpath(__FILE__))) 62 | install_plugin_pods(File.dirname(File.realpath(__FILE__)), '.symlinks', 'ios') 63 | end 64 | 65 | post_install do |installer| 66 | installer.pods_project.targets.each do |target| 67 | flutter_additional_ios_build_settings(target) 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images": [ 3 | { 4 | "size": "20x20", 5 | "idiom": "iphone", 6 | "filename": "icon-20@2x.png", 7 | "scale": "2x" 8 | }, 9 | { 10 | "size": "20x20", 11 | "idiom": "iphone", 12 | "filename": "icon-20@3x.png", 13 | "scale": "3x" 14 | }, 15 | { 16 | "size": "29x29", 17 | "idiom": "iphone", 18 | "filename": "icon-29.png", 19 | "scale": "1x" 20 | }, 21 | { 22 | "size": "29x29", 23 | "idiom": "iphone", 24 | "filename": "icon-29@2x.png", 25 | "scale": "2x" 26 | }, 27 | { 28 | "size": "29x29", 29 | "idiom": "iphone", 30 | "filename": "icon-29@3x.png", 31 | "scale": "3x" 32 | }, 33 | { 34 | "size": "40x40", 35 | "idiom": "iphone", 36 | "filename": "icon-40@2x.png", 37 | "scale": "2x" 38 | }, 39 | { 40 | "size": "40x40", 41 | "idiom": "iphone", 42 | "filename": "icon-40@3x.png", 43 | "scale": "3x" 44 | }, 45 | { 46 | "size": "60x60", 47 | "idiom": "iphone", 48 | "filename": "icon-60@2x.png", 49 | "scale": "2x" 50 | }, 51 | { 52 | "size": "60x60", 53 | "idiom": "iphone", 54 | "filename": "icon-60@3x.png", 55 | "scale": "3x" 56 | }, 57 | { 58 | "size": "20x20", 59 | "idiom": "ipad", 60 | "filename": "icon-20-ipad.png", 61 | "scale": "1x" 62 | }, 63 | { 64 | "size": "20x20", 65 | "idiom": "ipad", 66 | "filename": "icon-20@2x-ipad.png", 67 | "scale": "2x" 68 | }, 69 | { 70 | "size": "29x29", 71 | "idiom": "ipad", 72 | "filename": "icon-29-ipad.png", 73 | "scale": "1x" 74 | }, 75 | { 76 | "size": "29x29", 77 | "idiom": "ipad", 78 | "filename": "icon-29@2x-ipad.png", 79 | "scale": "2x" 80 | }, 81 | { 82 | "size": "40x40", 83 | "idiom": "ipad", 84 | "filename": "icon-40.png", 85 | "scale": "1x" 86 | }, 87 | { 88 | "size": "40x40", 89 | "idiom": "ipad", 90 | "filename": "icon-40@2x.png", 91 | "scale": "2x" 92 | }, 93 | { 94 | "size": "76x76", 95 | "idiom": "ipad", 96 | "filename": "icon-76.png", 97 | "scale": "1x" 98 | }, 99 | { 100 | "size": "76x76", 101 | "idiom": "ipad", 102 | "filename": "icon-76@2x.png", 103 | "scale": "2x" 104 | }, 105 | { 106 | "size": "83.5x83.5", 107 | "idiom": "ipad", 108 | "filename": "icon-83.5@2x.png", 109 | "scale": "2x" 110 | }, 111 | { 112 | "size": "1024x1024", 113 | "idiom": "ios-marketing", 114 | "filename": "icon-1024.png", 115 | "scale": "1x" 116 | } 117 | ], 118 | "info": { 119 | "version": 1, 120 | "author": "icon.wuruihong.com" 121 | } 122 | } -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-1024.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20-ipad.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20@2x-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20@2x-ipad.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-20@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29-ipad.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29@2x-ipad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29@2x-ipad.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-29@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-40.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-76.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Juejin 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | juejin 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 | UIViewControllerBasedStatusBarAppearance 45 | 46 | CADisableMinimumFrameDurationOnPhone 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /l10n.yaml: -------------------------------------------------------------------------------- 1 | arb-dir: lib/l10n 2 | output-class: JJLocalizations 3 | output-dir: lib/l10n/gen 4 | output-localization-file: jj_localizations.dart 5 | template-arb-file: app_en.arb 6 | synthetic-package: false 7 | untranslated-messages-file: lib/l10n/gen/jj_localizations_untranslated.txt 8 | -------------------------------------------------------------------------------- /lib/apis/content_api.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import '../internals/urls.dart'; 6 | import '../models/data_model.dart'; 7 | import '../models/response_model.dart'; 8 | import '../utils/http_util.dart'; 9 | 10 | class ContentAPI { 11 | const ContentAPI._(); 12 | 13 | static const String _api = '${Urls.apiHost}/content_api/v1'; 14 | static const String _articles = '$_api/article'; 15 | 16 | static Future> getDetailById(String id) { 17 | return HttpUtil.fetchModel( 18 | FetchType.post, 19 | url: '$_articles/detail', 20 | body: {'article_id': id}, 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/apis/interact_api.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import '../internals/urls.dart'; 6 | import '../models/data_model.dart'; 7 | import '../models/response_model.dart'; 8 | import '../utils/http_util.dart'; 9 | 10 | class InteractAPI { 11 | const InteractAPI._(); 12 | 13 | static const String _api = '${Urls.apiHost}/interact_api/v1'; 14 | static const String _comment = '$_api/comment'; 15 | 16 | static Future> getCommentByTypeAndId({ 17 | required FeedItemType type, 18 | required String id, 19 | String? lastId, 20 | int limit = 20, 21 | }) { 22 | return HttpUtil.fetchModel( 23 | FetchType.post, 24 | url: '$_comment/list', 25 | body: { 26 | 'item_type': type.type, 27 | 'item_id': id, 28 | 'cursor': lastId, 29 | 'limit': limit, 30 | }, 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/apis/passport_api.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:dio/dio.dart'; 6 | 7 | import '../constants/constants.dart'; 8 | import '../extensions/string_extension.dart'; 9 | import '../internals/urls.dart'; 10 | import '../models/data_model.dart'; 11 | import '../models/response_model.dart'; 12 | import '../utils/http_util.dart'; 13 | 14 | class PassportAPI { 15 | const PassportAPI._(); 16 | 17 | static const String _api = '${Urls.apiHost}/passport'; 18 | static const String _user = '$_api/user'; 19 | 20 | static Future> login(String u, String p) { 21 | return HttpUtil.fetchModel( 22 | FetchType.post, 23 | url: '$_user/login/', 24 | queryParameters: { 25 | 'aid': '$appId', 26 | 'iid': '2397406981526599', // TODO: 确认构造来源 27 | 'mix_mode': '1', 28 | }, 29 | body: { 30 | 'account': u.toEncrypted, 31 | 'password': p.toEncrypted, 32 | }, 33 | contentType: Headers.formUrlEncodedContentType, 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/apis/tag_api.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import '../internals/urls.dart'; 6 | import '../models/data_model.dart'; 7 | import '../models/response_model.dart'; 8 | import '../utils/http_util.dart'; 9 | 10 | class TagAPI { 11 | const TagAPI._(); 12 | 13 | static const String _api = '${Urls.apiHost}/tag_api/v1'; 14 | 15 | static Future> getCategoryBriefs() { 16 | return HttpUtil.fetchModel( 17 | FetchType.get, 18 | url: '$_api/query_category_briefs', 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/constants/constants.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:convert'; 6 | import 'dart:typed_data'; 7 | 8 | const int appId = 2606; 9 | 10 | const JsonEncoder globalJsonEncoder = JsonEncoder.withIndent(' '); 11 | 12 | const String urlScheme = r'http(s?)://'; 13 | final RegExp urlRegExp = RegExp(urlScheme); 14 | 15 | // transparent image 2:1 16 | final kTransparentImage = Uint8List.fromList([ 17 | 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, // 18 | 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, // 19 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, // 20 | 0x01, 0x03, 0x00, 0x00, 0x00, 0xce, 0xec, 0xed, // 21 | 0xc9, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4c, 0x54, // 22 | 0x45, 0x00, 0x00, 0x00, 0xc9, 0x45, 0x26, 0x64, // 23 | 0x1a, 0x2a, 0xbd, 0x00, 0x00, 0x00, 0x02, 0x74, 24 | 0x52, 0x4e, 0x53, 0xff, 0x00, 0xe5, 0xb7, 0x30, 25 | 0x4a, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 26 | 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b, 27 | 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 28 | 0x00, 0x0a, 0x49, 0x44, 0x41, 0x54, 0x08, 0x99, 29 | 0x63, 0x38, 0x00, 0x00, 0x00, 0xc2, 0x00, 0xc1, 30 | 0xee, 0x80, 0x97, 0x86, 0x00, 0x00, 0x00, 0x00, 31 | 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, 32 | ]); 33 | -------------------------------------------------------------------------------- /lib/constants/resources.dart: -------------------------------------------------------------------------------- 1 | /// Generate by [resource_generator](https://github.com/CaiJingLong/flutter_resource_generator) library. 2 | /// PLEASE DO NOT EDIT MANUALLY. 3 | // ignore_for_file: constant_identifier_names 4 | class R { 5 | const R._(); 6 | 7 | static const String ASSETS_BRAND_WITH_TEXT_SVG = 'assets/brand-with-text.svg'; 8 | 9 | static const String ASSETS_BRAND_SVG = 'assets/brand.svg'; 10 | 11 | static const String ASSETS_ICON_POST_HOT_COMMENT_PNG = 12 | 'assets/icon/post/hot_comment.png'; 13 | 14 | static const String ASSETS_ICON_USER_JY_LV1_WEBP = 15 | 'assets/icon/user/jy_lv1.webp'; 16 | 17 | static const String ASSETS_ICON_USER_JY_LV2_WEBP = 18 | 'assets/icon/user/jy_lv2.webp'; 19 | 20 | static const String ASSETS_ICON_USER_JY_LV3_WEBP = 21 | 'assets/icon/user/jy_lv3.webp'; 22 | 23 | static const String ASSETS_ICON_USER_JY_LV4_WEBP = 24 | 'assets/icon/user/jy_lv4.webp'; 25 | 26 | static const String ASSETS_ICON_USER_JY_LV5_WEBP = 27 | 'assets/icon/user/jy_lv5.webp'; 28 | 29 | static const String ASSETS_ICON_USER_JY_LV6_WEBP = 30 | 'assets/icon/user/jy_lv6.webp'; 31 | 32 | static const String ASSETS_ICON_USER_JY_LV7_WEBP = 33 | 'assets/icon/user/jy_lv7.webp'; 34 | 35 | static const String ASSETS_ICON_USER_JY_LV8_WEBP = 36 | 'assets/icon/user/jy_lv8.webp'; 37 | 38 | static const String ASSETS_ICON_USER_LV1_WEBP = 'assets/icon/user/lv1.webp'; 39 | 40 | static const String ASSETS_ICON_USER_LV2_WEBP = 'assets/icon/user/lv2.webp'; 41 | 42 | static const String ASSETS_ICON_USER_LV3_WEBP = 'assets/icon/user/lv3.webp'; 43 | 44 | static const String ASSETS_ICON_USER_LV4_WEBP = 'assets/icon/user/lv4.webp'; 45 | 46 | static const String ASSETS_ICON_USER_LV5_WEBP = 'assets/icon/user/lv5.webp'; 47 | 48 | static const String ASSETS_ICON_USER_LV6_WEBP = 'assets/icon/user/lv6.webp'; 49 | 50 | static const String ASSETS_ICON_USER_LV7_WEBP = 'assets/icon/user/lv7.webp'; 51 | 52 | static const String ASSETS_ICON_USER_LV8_WEBP = 'assets/icon/user/lv8.webp'; 53 | 54 | static const String ASSETS_ICON_USER_VIP_LV1_WEBP = 55 | 'assets/icon/user/vip_lv1.webp'; 56 | 57 | static const String ASSETS_ICON_USER_VIP_LV2_WEBP = 58 | 'assets/icon/user/vip_lv2.webp'; 59 | 60 | static const String ASSETS_ICON_USER_VIP_LV3_WEBP = 61 | 'assets/icon/user/vip_lv3.webp'; 62 | 63 | static const String ASSETS_ICON_USER_VIP_LV4_WEBP = 64 | 'assets/icon/user/vip_lv4.webp'; 65 | 66 | static const String ASSETS_ICON_USER_VIP_LV5_WEBP = 67 | 'assets/icon/user/vip_lv5.webp'; 68 | 69 | static const String PIN_DETAIL_HEAD_BG_WEBP = 70 | 'assets/icon/topic/pin_detail_head_bg.webp'; 71 | } 72 | -------------------------------------------------------------------------------- /lib/constants/screens.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:ui'; 6 | 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter/services.dart'; 9 | 10 | class Screens { 11 | const Screens._(); 12 | 13 | static MediaQueryData get mediaQuery => MediaQueryData.fromView( 14 | WidgetsBinding.instance.platformDispatcher.views.first, 15 | ); 16 | 17 | static double fixedFontSize(double fontSize) => fontSize / textScaleFactor; 18 | 19 | static double get scale => mediaQuery.devicePixelRatio; 20 | 21 | static double get width => mediaQuery.size.width; 22 | 23 | static int get widthPixels => (width * scale).toInt(); 24 | 25 | static double get height => mediaQuery.size.height; 26 | 27 | static int get heightPixels => (height * scale).toInt(); 28 | 29 | static double get aspectRatio => width / height; 30 | 31 | static double get textScaleFactor => mediaQuery.textScaleFactor; 32 | 33 | static double get navigationBarHeight => 34 | mediaQuery.padding.top + kToolbarHeight; 35 | 36 | static double get topSafeHeight => mediaQuery.padding.top; 37 | 38 | static double get bottomSafeHeight => mediaQuery.padding.bottom; 39 | 40 | static double get safeHeight => height - topSafeHeight - bottomSafeHeight; 41 | 42 | static FlutterView get window => 43 | WidgetsBinding.instance.platformDispatcher.views.first; 44 | 45 | static void updateStatusBarStyle(SystemUiOverlayStyle style) { 46 | SystemChrome.setSystemUIOverlayStyle(style); 47 | } 48 | } 49 | 50 | extension ScreenSizeDoubleExtension on double { 51 | int toPx() => (this * Screens.scale).toInt(); 52 | } 53 | -------------------------------------------------------------------------------- /lib/constants/styles.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | 7 | const Color failedColor = Color(0xffff6363); 8 | 9 | class RadiusConstants { 10 | const RadiusConstants._(); 11 | 12 | static const BorderRadius r1 = BorderRadius.all(Radius.circular(1)); 13 | static const BorderRadius r2 = BorderRadius.all(Radius.circular(2)); 14 | static const BorderRadius r3 = BorderRadius.all(Radius.circular(3)); 15 | static const BorderRadius r4 = BorderRadius.all(Radius.circular(4)); 16 | static const BorderRadius r5 = BorderRadius.all(Radius.circular(5)); 17 | static const BorderRadius r6 = BorderRadius.all(Radius.circular(6)); 18 | static const BorderRadius r7 = BorderRadius.all(Radius.circular(7)); 19 | static const BorderRadius r8 = BorderRadius.all(Radius.circular(8)); 20 | static const BorderRadius r9 = BorderRadius.all(Radius.circular(9)); 21 | static const BorderRadius r10 = BorderRadius.all(Radius.circular(10)); 22 | static const BorderRadius r12 = BorderRadius.all(Radius.circular(12)); 23 | static const BorderRadius r15 = BorderRadius.all(Radius.circular(15)); 24 | static const BorderRadius r16 = BorderRadius.all(Radius.circular(16)); 25 | static const BorderRadius r20 = BorderRadius.all(Radius.circular(20)); 26 | static const BorderRadius r25 = BorderRadius.all(Radius.circular(25)); 27 | static const BorderRadius max = BorderRadius.all(Radius.circular(999999)); 28 | } 29 | -------------------------------------------------------------------------------- /lib/exports.dart: -------------------------------------------------------------------------------- 1 | export 'package:collection/collection.dart'; 2 | export 'package:dio/dio.dart'; 3 | export 'package:ff_annotation_route_library/ff_annotation_route_library.dart'; 4 | export 'package:flutter/services.dart' show HapticFeedback, TextInputFormatter; 5 | export 'package:flutter_svg/flutter_svg.dart' show SvgPicture; 6 | export 'package:pull_to_refresh_notification/pull_to_refresh_notification.dart'; 7 | 8 | export 'apis/content_api.dart'; 9 | export 'apis/interact_api.dart'; 10 | export 'apis/passport_api.dart'; 11 | export 'apis/recommend_api.dart'; 12 | export 'apis/tag_api.dart'; 13 | export 'constants/constants.dart'; 14 | export 'constants/resources.dart'; 15 | export 'constants/screens.dart'; 16 | export 'constants/styles.dart'; 17 | export 'constants/themes.dart'; 18 | export 'extensions/brightness_extension.dart'; 19 | export 'extensions/build_context_extension.dart'; 20 | export 'extensions/color_extension.dart'; 21 | export 'extensions/duration_extension.dart'; 22 | export 'extensions/future_extension.dart'; 23 | export 'extensions/num_extension.dart'; 24 | export 'extensions/state_extension.dart'; 25 | export 'extensions/string_extension.dart'; 26 | export 'internals/instance.dart'; 27 | export 'internals/methods.dart'; 28 | export 'internals/special_text.dart'; 29 | export 'internals/urls.dart'; 30 | export 'l10n/gen/jj_localizations.dart'; 31 | export 'models/data_model.dart'; 32 | export 'models/loading_base.dart'; 33 | export 'models/response_model.dart'; 34 | export 'routes/juejin_routes.dart'; 35 | export 'routes/page_route.dart'; 36 | export 'utils/cache_util.dart'; 37 | export 'utils/device_util.dart'; 38 | export 'utils/haptic_util.dart'; 39 | export 'utils/http_util.dart'; 40 | export 'utils/log_util.dart'; 41 | export 'utils/package_util.dart'; 42 | export 'utils/toast_util.dart'; 43 | export 'widgets/_none.dart'; 44 | export 'widgets/error_widget.dart'; 45 | export 'widgets/gaps.dart'; 46 | export 'widgets/lazy_indexed_stack.dart'; 47 | export 'widgets/logo.dart'; 48 | export 'widgets/refresh/base_refresh_wrapper.dart'; 49 | export 'widgets/refresh/refresh_grid_wrapper.dart'; 50 | export 'widgets/refresh/refresh_list_wrapper.dart'; 51 | export 'widgets/tapper.dart'; 52 | export 'widgets/webview.dart'; 53 | -------------------------------------------------------------------------------- /lib/extensions/brightness_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:ui'; 6 | 7 | extension BrightnessExtension on Brightness { 8 | bool get isDark => this == Brightness.dark; 9 | 10 | bool get isLight => this == Brightness.light; 11 | } 12 | -------------------------------------------------------------------------------- /lib/extensions/build_context_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | 7 | import '../l10n/gen/jj_localizations.dart'; 8 | 9 | extension BuildContextExtension on BuildContext { 10 | JJLocalizations get l10n => JJLocalizations.of(this)!; 11 | 12 | NavigatorState get navigator => Navigator.of(this); 13 | 14 | ThemeData get theme => Theme.of(this); 15 | 16 | TextTheme get textTheme => theme.textTheme; 17 | 18 | Brightness get brightness => theme.brightness; 19 | 20 | ButtonThemeData get buttonTheme => ButtonTheme.of(this); 21 | 22 | IconThemeData get iconTheme => IconTheme.of(this); 23 | 24 | MediaQueryData get mediaQuery => MediaQuery.of(this); 25 | 26 | double get topPadding => mediaQuery.padding.top; 27 | 28 | double get bottomPadding => mediaQuery.padding.bottom; 29 | 30 | double get bottomViewInsets => mediaQuery.viewInsets.bottom; 31 | 32 | ColorScheme get colorScheme => theme.colorScheme; 33 | 34 | Color get surfaceColor => colorScheme.surface; 35 | } 36 | -------------------------------------------------------------------------------- /lib/extensions/color_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | 7 | extension ColorExtension on Color { 8 | bool get isTransparent => alpha == 0; 9 | 10 | MaterialColor get swatch { 11 | return Colors.primaries.firstWhere( 12 | (Color c) => c.value == value, 13 | orElse: () => MaterialColor(value, getMaterialColorValues), 14 | ); 15 | } 16 | 17 | Map get getMaterialColorValues { 18 | return { 19 | 50: _swatchShade(50), 20 | 100: _swatchShade(100), 21 | 200: _swatchShade(200), 22 | 300: _swatchShade(300), 23 | 400: _swatchShade(400), 24 | 500: _swatchShade(500), 25 | 600: _swatchShade(600), 26 | 700: _swatchShade(700), 27 | 800: _swatchShade(800), 28 | 900: _swatchShade(900), 29 | }; 30 | } 31 | 32 | Color _swatchShade(int swatchValue) => HSLColor.fromColor(this) 33 | .withLightness(1 - (swatchValue / 1000)) 34 | .toColor(); 35 | } 36 | 37 | /// https://stackoverflow.com/a/50081214/10064463 38 | extension HexColor on Color { 39 | /// Format: "aabbcc" or "ffaabbcc" with an optional leading "#". 40 | static Color fromHex(String hexString) { 41 | final StringBuffer buffer = StringBuffer(); 42 | if (hexString.length == 6 || hexString.length == 7) { 43 | buffer.write('ff'); 44 | } 45 | buffer.write(hexString.replaceFirst('#', '')); 46 | return Color(int.parse(buffer.toString(), radix: 16)); 47 | } 48 | 49 | /// Prefixes a hash sign if [leadingHashSign] is set to `true`. 50 | String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}' 51 | '${alpha.toRadixString(16).padLeft(2, '0')}' 52 | '${red.toRadixString(16).padLeft(2, '0')}' 53 | '${green.toRadixString(16).padLeft(2, '0')}' 54 | '${blue.toRadixString(16).padLeft(2, '0')}'; 55 | } 56 | -------------------------------------------------------------------------------- /lib/extensions/duration_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/widgets.dart'; 6 | 7 | import 'build_context_extension.dart'; 8 | 9 | extension DurationExtension on Duration { 10 | Future get delay => Future.delayed(this); 11 | 12 | String differenceString(BuildContext context) { 13 | final localization = context.l10n; 14 | if (this >= const Duration(days: 365)) { 15 | return localization.durationYears(inDays ~/ 365); 16 | } 17 | if (this >= const Duration(days: 30)) { 18 | return localization.durationMonths(inDays ~/ 30); 19 | } 20 | if (this >= const Duration(days: 1)) { 21 | return localization.durationDays(inDays); 22 | } 23 | if (this >= const Duration(hours: 1)) { 24 | return localization.durationHours(inHours); 25 | } 26 | return localization.durationMinutes(inMinutes); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/extensions/future_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:async'; 6 | 7 | import '../utils/log_util.dart'; 8 | 9 | extension FutureExtension on Future { 10 | Future atLeast(Duration duration) async { 11 | final List futures = await Future.wait( 12 | >[this, Future.delayed(duration)], 13 | ); 14 | return futures.first as T; 15 | } 16 | 17 | Future> plus(Future b, {bool eagerError = false}) { 18 | return Future.wait(>[this, b], eagerError: eagerError); 19 | } 20 | } 21 | 22 | extension StopwatchExtension on Stopwatch { 23 | void logElapsed([String? tag]) { 24 | LogUtil.d( 25 | '${tag ?? 'Stopwatch'} elapsed: $elapsed', 26 | tag: '⌚ Stopwatch', 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/extensions/num_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:math' as math; 6 | 7 | final math.Random _random = math.Random(); 8 | 9 | extension NumExtension on T { 10 | T get lessThanOne => math.min((this is int ? 1 : 1.0) as T, this); 11 | 12 | T get lessThanZero => math.min((this is int ? 0 : 0.0) as T, this); 13 | 14 | T get moreThanOne => math.max((this is int ? 1 : 1.0) as T, this); 15 | 16 | T get moreThanZero => math.max((this is int ? 0 : 0.0) as T, this); 17 | 18 | T get betweenZeroAndOne => lessThanOne.moreThanZero; 19 | } 20 | 21 | extension IntExtension on int { 22 | String get fileSizeFromBytes { 23 | const int kb = 1024; 24 | const int mb = 1024 * kb; 25 | const int gb = 1024 * mb; 26 | if (this >= gb) { 27 | return '${(this / gb).toStringAsFixed(2)} GB'; 28 | } 29 | if (this >= mb) { 30 | return '${(this / mb).toStringAsFixed(2)} MB'; 31 | } 32 | if (this >= kb) { 33 | return '${(this / kb).toStringAsFixed(2)} KB'; 34 | } 35 | return '$this B'; 36 | } 37 | 38 | int nextRandom([int min = 0]) => min + _random.nextInt(this - min); 39 | 40 | Duration get days => Duration(days: this); 41 | 42 | Duration get hours => Duration(hours: this); 43 | 44 | Duration get minutes => Duration(minutes: this); 45 | 46 | Duration get seconds => Duration(seconds: this); 47 | 48 | Duration get milliseconds => Duration(milliseconds: this); 49 | 50 | Duration get microseconds => Duration(microseconds: this); 51 | 52 | DateTime get toDateTimeInMicroseconds => 53 | DateTime.fromMicrosecondsSinceEpoch(this); 54 | 55 | DateTime get toDateTimeInMilliseconds => 56 | DateTime.fromMillisecondsSinceEpoch(this); 57 | } 58 | 59 | extension DoubleExtension on double { 60 | double nextRandom([int min = 0]) => min + _random.nextDouble() * (this - min); 61 | 62 | /// 根据位数四舍五入 63 | double roundAsFixed(int size) { 64 | final num pow = math.pow(10, size); 65 | return (this * pow).round() / pow; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/extensions/state_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:async'; 6 | 7 | import 'package:flutter/widgets.dart'; 8 | 9 | extension SafeSetStateExtension on State { 10 | /// [setState] when it's not building, then wait until next frame built. 11 | FutureOr safeSetState(FutureOr Function() fn) async { 12 | await fn(); 13 | if (mounted && 14 | !context.debugDoingBuild && 15 | context.owner?.debugBuilding == false) { 16 | // ignore: invalid_use_of_protected_member 17 | setState(() {}); 18 | } 19 | final Completer completer = Completer(); 20 | WidgetsBinding.instance.addPostFrameCallback((_) { 21 | completer.complete(); 22 | }); 23 | return completer.future; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/extensions/string_extension.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/widgets.dart' show Characters; 6 | 7 | extension StringExtension on String { 8 | String get notBreak => Characters(this).join('\u{200B}'); 9 | 10 | int toInt() => int.parse(this); 11 | 12 | double toDouble() => double.parse(this); 13 | 14 | String removeAll(Pattern pattern) => replaceAll(pattern, ''); 15 | 16 | String removeFirst(Pattern pattern, [int startIndex = 0]) => 17 | replaceFirst(pattern, '', startIndex); 18 | } 19 | 20 | extension NullableStringExtension on String? { 21 | bool get isNullOrEmpty => this == null || this!.isEmpty; 22 | 23 | bool get isNotNullOrEmpty => this != null && this!.isNotEmpty; 24 | 25 | int? toIntOrNull() => this == null ? null : int.tryParse(this!); 26 | 27 | double? toDoubleOrNull() => this == null ? null : double.tryParse(this!); 28 | } 29 | 30 | /// Try with the DartPad: 31 | /// https://dartpad.cn/?id=98317a28d0cc65f63454c0329f5316ba 32 | /// 33 | /// Thanks to @DemoJameson . 34 | extension EncryptStringExtension on String { 35 | String get toEncrypted { 36 | return split('') 37 | .map((String e) { 38 | final int ascii = e.codeUnitAt(0); 39 | final int r = ascii % 8; 40 | final int offset = 41 | {2: 7, 3: 6, 0: 5, 1: 4, 6: 3, 7: 2, 4: 1, 5: 0}[r]!; 42 | return (ascii + offset - r).toRadixString(16); 43 | }) 44 | .join() 45 | .toLowerCase(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/internals/instance.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | 7 | import '../app.dart'; 8 | 9 | class JJ { 10 | const JJ._(); 11 | 12 | static final GlobalKey navigatorKey = GlobalKey(); 13 | static final RouteObserver> routeObserver = 14 | RouteObserver>(); 15 | static final GlobalKey repaintBoundaryKey = GlobalKey(); 16 | static final GlobalKey appKey = GlobalKey(); 17 | } 18 | 19 | NavigatorState get navigator => JJ.navigatorKey.currentState!; 20 | 21 | BuildContext get overlayContext => navigator.overlay!.context; 22 | 23 | DateTime get currentTime => DateTime.now(); 24 | 25 | int get currentTimeStamp => currentTime.millisecondsSinceEpoch; 26 | -------------------------------------------------------------------------------- /lib/internals/methods.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:convert'; 7 | import 'dart:io'; 8 | 9 | import 'package:flutter/material.dart'; 10 | import 'package:flutter/services.dart'; 11 | 12 | import '../utils/log_util.dart'; 13 | // import 'package:permission_handler/permission_handler.dart'; 14 | 15 | /// Check permissions and only return whether they succeed or not. 16 | // Future checkPermissions(List permissions) async { 17 | // try { 18 | // final Map status = 19 | // await permissions.request(); 20 | // // Delay until next frame. 21 | // await 300.milliseconds.delay; 22 | // return status.values.every((PermissionStatus p) => p.isGranted); 23 | // } catch (e, stack) { 24 | // LogUtil.e('Error when requesting permission: $e', stackTrace: stack); 25 | // return false; 26 | // } 27 | // } 28 | 29 | /// Iterate element and its children to request rebuild. 30 | void rebuildAllChildren(BuildContext context) { 31 | LogUtil.d('Rebuilding all elements...', tag: 'rebuildAllChildren'); 32 | void rebuild(Element el) { 33 | el.markNeedsBuild(); 34 | el.visitChildren(rebuild); 35 | } 36 | 37 | (context as Element).visitChildren(rebuild); 38 | } 39 | 40 | Map decodeAsJson(String value) { 41 | return jsonDecode(value) as Map; 42 | } 43 | 44 | Future exitApp() async { 45 | await SystemNavigator.pop(animated: true); 46 | exit(0); 47 | } 48 | -------------------------------------------------------------------------------- /lib/internals/navigator_observer.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | import '../utils/log_util.dart'; 4 | 5 | enum RouteAction { pop, push, remove, replace } 6 | 7 | class JJNavigatorObserver extends NavigatorObserver { 8 | static final List> history = >[]; 9 | 10 | @override 11 | void didPop(Route route, Route? previousRoute) { 12 | super.didPop(route, previousRoute); 13 | _didRouteChange(RouteAction.pop, previousRoute, route); 14 | history.removeLast(); 15 | } 16 | 17 | @override 18 | void didPush(Route route, Route? previousRoute) { 19 | super.didPush(route, previousRoute); 20 | _didRouteChange(RouteAction.push, route, previousRoute); 21 | history.add(route); 22 | } 23 | 24 | @override 25 | void didRemove(Route route, Route? previousRoute) { 26 | super.didRemove(route, previousRoute); 27 | _didRouteChange(RouteAction.remove, previousRoute, route); 28 | final bool removed = history.remove(route); 29 | if (!removed) { 30 | history.removeLast(); 31 | } 32 | } 33 | 34 | @override 35 | void didReplace({Route? newRoute, Route? oldRoute}) { 36 | super.didReplace(newRoute: newRoute, oldRoute: oldRoute); 37 | _didRouteChange(RouteAction.replace, newRoute, oldRoute); 38 | if (oldRoute != null) { 39 | final int index = history.indexOf(oldRoute); 40 | if (index != -1) { 41 | if (newRoute == null) { 42 | history.remove(oldRoute); 43 | } else { 44 | history[index] = newRoute; 45 | } 46 | } 47 | } else if (oldRoute == null && newRoute != null) { 48 | history.add(newRoute); 49 | } 50 | } 51 | 52 | void _didRouteChange( 53 | RouteAction action, 54 | Route? newRoute, 55 | Route? oldRoute, 56 | ) { 57 | LogUtil.dd( 58 | () => '[${action.name.toUpperCase().padLeft(7)}] ' 59 | '${oldRoute?.settings.name} => ${newRoute?.settings.name}', 60 | tag: runtimeType.toString(), 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /lib/internals/special_text.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:extended_text/extended_text.dart'; 6 | import 'package:flutter/gestures.dart'; 7 | import 'package:flutter/material.dart'; 8 | 9 | import '../constants/themes.dart'; 10 | 11 | class TopicText extends RegExpSpecialText { 12 | /// [7118934098294341672#理财经验分享#] 13 | /// 14 | /// - Match numeric ID at start. 15 | /// - Match paired #. 16 | /// - Match not empty content between pairing #. 17 | @override 18 | final RegExp regExp = RegExp(r'\[(\d{18,})#(\S+?|\S((?!#\]).)+?\S)#\]'); 19 | 20 | @override 21 | InlineSpan finishText( 22 | int start, 23 | Match match, { 24 | TextStyle? textStyle, 25 | SpecialTextGestureTapCallback? onTap, 26 | }) { 27 | final String actualText = toString(); 28 | return SpecialTextSpan( 29 | text: '#${match.group(2)}#', 30 | actualText: actualText, 31 | start: start, 32 | style: (textStyle ?? const TextStyle()).copyWith( 33 | color: themeColorLight, 34 | ), 35 | recognizer: onTap != null 36 | ? (TapGestureRecognizer()..onTap = () => onTap(actualText)) 37 | : null, 38 | ); 39 | } 40 | } 41 | 42 | class JJRegExpSpecialTextSpanBuilder extends RegExpSpecialTextSpanBuilder { 43 | @override 44 | List get regExps { 45 | return [TopicText()]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/internals/urls.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:url_launcher/url_launcher_string.dart'; 6 | 7 | class Urls { 8 | const Urls._(); 9 | 10 | static const String domain = 'juejin.cn'; 11 | static const String apiHost = 'api.$domain'; 12 | 13 | static Future canLaunch(String urlString) { 14 | return canLaunchUrlString(urlString); 15 | } 16 | 17 | static Future launchOnDevice( 18 | String urlString, { 19 | LaunchMode mode = LaunchMode.externalApplication, 20 | WebViewConfiguration webViewConfiguration = const WebViewConfiguration(), 21 | String? webOnlyWindowName, 22 | }) { 23 | return launchUrlString( 24 | urlString, 25 | mode: mode, 26 | webViewConfiguration: webViewConfiguration, 27 | webOnlyWindowName: webOnlyWindowName, 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/l10n/app_en.arb: -------------------------------------------------------------------------------- 1 | { 2 | "@@locale": "en", 3 | "appTitle": "Juejin", 4 | 5 | "exceptionAuthenticationExpired": "Authentication has expired, please login manually.", 6 | "exceptionError": "error", 7 | "exceptionErrorWidget": "Exception thrown during building this widget...", 8 | "exceptionFailed": "failed", 9 | "exceptionPoorNetwork": "Poor network condition, please retry later.", 10 | "exceptionRequest": "Request error: (-1 {message})", 11 | "@exceptionRequest": {"placeholders": {"message": {}}}, 12 | "exceptionRouteNotFound": "{routeName} route not found.", 13 | "@exceptionRouteNotFound": {"placeholders": {"routeName": {"type": "String"}}}, 14 | "exceptionRouteUnknown": "Unknown", 15 | "notSupported": "Not supported yet", 16 | 17 | "close": "Close", 18 | 19 | "listEmpty": "It's empty here.", 20 | "listLoadingMore": "Loading more content...", 21 | "listNetworkErrorClickRetry": "Network exceptions thrown. Click to retry.", 22 | "listNoMoreToLoad": "Nothing left.", 23 | "listRefreshing": "Refreshing...", 24 | "listRefreshWaiting": "Pull down more to refresh", 25 | "listRefreshArmed": "Release to refresh", 26 | "listRefreshSucceed": "Refreshed with new contents", 27 | "listRefreshFailed": "Failed to refresh", 28 | 29 | "webViewTitle": "Web page", 30 | 31 | "navHome": "Home", 32 | "navPins": "Pins", 33 | "navMe": "Me", 34 | 35 | "actionLike": "Like", 36 | "actionComment": "Comment", 37 | "actionReply": "Reply", 38 | "actionMore": "More", 39 | "actionFold": "Fold", 40 | "actionCollect": "Favorite", 41 | "actionShare": "Share", 42 | "advertiseAbbr": "Ad", 43 | 44 | "articleViews": "{num} views", 45 | "@articleViews": { 46 | "placeholders": {"num": {"type": "int"}} 47 | }, 48 | 49 | "pinLiked": "and others liked", 50 | "pinHotCommentLikes": "{num} likes", 51 | "@pinHotCommentLikes": { 52 | "placeholders": {"num": {"type": "int"}} 53 | }, 54 | "pinTotalCommentCount": "Total comments {count}", 55 | "@pinTotalCommentCount": { 56 | "placeholders": {"count": {"type": "int"}} 57 | }, 58 | 59 | "userLikes": "Likes", 60 | "userFavorites": "Favorites", 61 | "userFollows": "Follows", 62 | "userComments": "Comments", 63 | "userFollowing": "Following", 64 | "userNotFollow": "Not follow", 65 | "userSignInOrUp": "Sign in/Sign up", 66 | 67 | "arrangement": "Sort By", 68 | "recommend": "Hot", 69 | "latest": "Latest", 70 | 71 | 72 | "join": "Join", 73 | 74 | "categoryTabFollowing": "Following", 75 | "categoryTabRecommend": "Recommend", 76 | 77 | "tagAll": "All", 78 | "sortRecommend": "Recommend", 79 | "sortLatest": "Latest", 80 | 81 | "durationYears": "{many, plural, =1{1 year} other{{many} years}} ago", 82 | "@durationYears": { 83 | "placeholders": {"many": {"type": "int"}} 84 | }, 85 | "durationMonths": "{many, plural, =1{1 month} other{{many} months}} ago", 86 | "@durationMonths": { 87 | "placeholders": {"many": {"type": "int"}} 88 | }, 89 | "durationDays": "{many, plural, =1{1 day} other{{many} days}} ago", 90 | "@durationDays": { 91 | "placeholders": {"many": {"type": "int"}} 92 | }, 93 | "durationHours": "{many, plural, =1{1 hour} other{{many} hours}} ago", 94 | "@durationHours": { 95 | "placeholders": {"many": {"type": "int"}} 96 | }, 97 | "durationMinutes": "{many, plural, =0{Just now} =1{1 minute ago} other{{many} minutes ago}}", 98 | "@durationMinutes": { 99 | "placeholders": {"many": {"type": "int"}} 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /lib/l10n/app_zh.arb: -------------------------------------------------------------------------------- 1 | { 2 | "@@locale": "zh", 3 | "appTitle": "掘金", 4 | 5 | "exceptionAuthenticationExpired": "身份已失效,请重新登录", 6 | "exceptionError": "错误", 7 | "exceptionErrorWidget": "构建时遇到未知错误...", 8 | "exceptionFailed": "失败", 9 | "exceptionPoorNetwork": "网络状况差,请稍后重试", 10 | "exceptionRequest": "请求失败:(-1 {message})", 11 | "exceptionRouteNotFound": "{routeName} 无效路由。", 12 | "exceptionRouteUnknown": "未知", 13 | "notSupported": "尚未实现", 14 | 15 | "close": "关闭", 16 | 17 | "listEmpty": "空空如也", 18 | "listLoadingMore": "加载中...", 19 | "listNetworkErrorClickRetry": "网络出错了~点此重试", 20 | "listNoMoreToLoad": "已经到底啦~", 21 | "listRefreshing": "正在刷新...", 22 | "listRefreshWaiting": "下拉更多以刷新", 23 | "listRefreshArmed": "松手以刷新", 24 | "listRefreshSucceed": "刷新成功", 25 | "listRefreshFailed": "刷新失败", 26 | 27 | "webViewTitle": "网页链接", 28 | 29 | "navHome": "首页", 30 | "navPins": "沸点", 31 | "navMe": "我", 32 | 33 | "actionLike": "赞", 34 | "actionComment": "评论", 35 | "actionReply": "回复", 36 | "actionMore": "展开", 37 | "actionFold": "收起", 38 | "actionCollect": "收藏", 39 | "actionShare": "分享", 40 | "advertiseAbbr": "广告", 41 | 42 | "articleViews": "阅读 {num}", 43 | 44 | "pinLiked": "等人赞过", 45 | "pinHotCommentLikes": "{num}人赞", 46 | "pinTotalCommentCount": "全部评论 {count}", 47 | 48 | "userLikes": "点赞", 49 | "userFavorites": "收藏", 50 | "userFollows": "关注", 51 | "userComments": "评论", 52 | "userFollowing": "已关注", 53 | "userNotFollow": "未关注", 54 | "userSignInOrUp": "登录/注册", 55 | 56 | "arrangement": "排序", 57 | "recommend": "热门", 58 | "latest": "最新", 59 | 60 | "categoryTabFollowing": "关注", 61 | "categoryTabRecommend": "推荐", 62 | 63 | "tagAll": "全部", 64 | "sortRecommend": "推荐", 65 | "sortLatest": "最新", 66 | 67 | "join": "加入", 68 | 69 | "durationYears": "{many, plural, other{{many}年前}}", 70 | "durationMonths": "{many, plural, other{{many}月前}}", 71 | "durationDays": "{many, plural, other{{many}天前}}", 72 | "durationHours": "{many, plural, other{{many}小时前}}", 73 | "durationMinutes": "{many, plural,=0{刚刚} other{{many}分钟前}}" 74 | } 75 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/foundation.dart'; 6 | import 'package:flutter/material.dart'; 7 | 8 | import 'app.dart'; 9 | import 'exports.dart'; 10 | 11 | void main() { 12 | PlatformDispatcher.instance.onError = (e, s) { 13 | if (e is ModelError) { 14 | return true; 15 | } 16 | if (e is DioException && e.type == DioExceptionType.cancel) { 17 | return true; 18 | } 19 | HapticUtil.notifyFailure(); 20 | LogUtil.e( 21 | 'Caught unhandled exception: $e', 22 | stackTrace: s, 23 | tag: '💂 PlatformDispatcher', 24 | ); 25 | showErrorToast('$e'); 26 | return true; 27 | }; 28 | JJErrorWidget.takeOver(); 29 | runApp(JJApp(key: JJ.appKey)); 30 | } 31 | -------------------------------------------------------------------------------- /lib/models/data_model.d.dart: -------------------------------------------------------------------------------- 1 | part of 'data_model.dart'; 2 | 3 | final Map dataModelFactories = { 4 | EmptyDataModel: EmptyDataModel.fromJson, 5 | FeedModel: FeedModel.fromJson, 6 | AdvertiseItemModel: AdvertiseItemModel.fromJson, 7 | ArticleItemModel: ArticleItemModel.fromJson, 8 | ArticleInfo: ArticleInfo.fromJson, 9 | ArticleStatus: ArticleStatus.fromJson, 10 | ArticleExtra: ArticleExtra.fromJson, 11 | Category: Category.fromJson, 12 | Tag: Tag.fromJson, 13 | CommentItemModel: CommentItemModel.fromJson, 14 | CommentInfo: CommentInfo.fromJson, 15 | CommentReply: CommentReply.fromJson, 16 | ReplyInfo: ReplyInfo.fromJson, 17 | PinItemModel: PinItemModel.fromJson, 18 | PinInfo: PinInfo.fromJson, 19 | PinTopic: PinTopic.fromJson, 20 | PinTheme: PinTheme.fromJson, 21 | HotComment: HotComment.fromJson, 22 | UserInfoModel: UserInfoModel.fromJson, 23 | UserUniversity: UserUniversity.fromJson, 24 | UserMajor: UserMajor.fromJson, 25 | UserGrowthInfo: UserGrowthInfo.fromJson, 26 | UserInteract: UserInteract.fromJson, 27 | UserOrg: UserOrg.fromJson, 28 | }; 29 | -------------------------------------------------------------------------------- /lib/models/data_model.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:equatable/equatable.dart'; 6 | import 'package:flutter/material.dart'; 7 | import 'package:json_annotation/json_annotation.dart'; 8 | 9 | import '../constants/constants.dart'; 10 | import '../constants/resources.dart'; 11 | import '../extensions/build_context_extension.dart'; 12 | import '../extensions/duration_extension.dart'; 13 | import '../extensions/num_extension.dart'; 14 | import '../utils/log_util.dart'; 15 | 16 | part 'data_model.d.dart'; 17 | part 'data_model.g.dart'; 18 | part 'feed_model.dart'; 19 | part 'item/advertise_item_model.dart'; 20 | part 'item/article_item_model.dart'; 21 | part 'item/comment_item_model.dart'; 22 | part 'item/post_item_model.dart'; 23 | part 'user_model.dart'; 24 | 25 | typedef Json = Map; 26 | typedef JsonList = List; 27 | typedef QueryMap = Map; 28 | 29 | abstract class DataModel extends Equatable { 30 | const DataModel(); 31 | 32 | Json toJson(); 33 | 34 | @override 35 | String toString() => globalJsonEncoder.convert(toJson()); 36 | } 37 | 38 | typedef DataFactory = T Function(Json json); 39 | 40 | T makeModel(Json json) { 41 | if (!dataModelFactories.containsKey(T)) { 42 | LogUtil.e( 43 | "You're inflating an unregistered type: $T\n" 44 | "Please check if it's registered in `dataModelFactories`.", 45 | tag: '🏭 DataModel', 46 | ); 47 | throw ModelNotRegisteredError(); 48 | } 49 | try { 50 | return dataModelFactories[T]!(json) as T; 51 | } catch (e, s) { 52 | LogUtil.e( 53 | 'Error when making model with $T type: $e\n' 54 | '${json.containsKey('id') ? 'Model contains id: ${json['id']}\n' : ''}' 55 | 'The raw data which make this error is: ' 56 | '${globalJsonEncoder.convert(json)}', 57 | stackTrace: s, 58 | tag: '🏭 DataModel', 59 | ); 60 | throw ModelMakeError(json, e); 61 | } 62 | } 63 | 64 | class EmptyDataModel extends DataModel { 65 | const EmptyDataModel(); 66 | 67 | factory EmptyDataModel.fromJson(dynamic _) => const EmptyDataModel(); 68 | 69 | @override 70 | Json toJson() => const {}; 71 | 72 | @override 73 | List get props => [null]; 74 | } 75 | 76 | class ModelError extends TypeError {} 77 | 78 | class ModelMakeError extends ModelError { 79 | ModelMakeError(this.json, this.error); 80 | 81 | final Json json; 82 | final Object error; 83 | } 84 | 85 | class ModelNotRegisteredError extends ModelError { 86 | ModelNotRegisteredError(); 87 | 88 | @override 89 | String toString() { 90 | return "You're inflating an unregistered type: $T\n" 91 | "Please check if it's registered in `dataModelFactories`."; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /lib/models/feed_model.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | part of 'data_model.dart'; 6 | 7 | @JsonSerializable() 8 | class FeedModel extends DataModel { 9 | const FeedModel({ 10 | required this.itemType, 11 | required this.itemInfo, 12 | }); 13 | 14 | factory FeedModel.fromJson(Map json) => 15 | _$FeedModelFromJson(json); 16 | 17 | @JsonKey(fromJson: _feedItemTypeFromJson, toJson: _feedItemTypeToJson) 18 | final FeedItemType itemType; 19 | @JsonKey(readValue: _handleItemInfoType) 20 | final Object itemInfo; 21 | 22 | static FeedItemType _feedItemTypeFromJson(int value) { 23 | return FeedItemType.fromInt(value); 24 | } 25 | 26 | static int _feedItemTypeToJson(FeedItemType type) => type.type; 27 | 28 | static Object _handleItemInfoType(Map json, String key) { 29 | final FeedItemType itemType = FeedItemType.fromInt(json['item_type']); 30 | final Json itemInfo = json[key]!; 31 | switch (itemType) { 32 | case FeedItemType.article: 33 | return ArticleItemModel.fromJson(itemInfo); 34 | case FeedItemType.advertisement: 35 | return AdvertiseItemModel.fromJson(itemInfo); 36 | default: 37 | throw UnsupportedError('Unsupported type $itemType: $itemInfo'); 38 | } 39 | } 40 | 41 | @override 42 | Map toJson() => _$FeedModelToJson(this); 43 | 44 | @override 45 | List get props => [itemType, itemInfo]; 46 | } 47 | 48 | enum FeedItemType { 49 | article(2), 50 | pin(4), 51 | advertisement(14); 52 | 53 | const FeedItemType(this.type); 54 | 55 | factory FeedItemType.fromInt(int value) { 56 | return values.singleWhere((FeedItemType e) => e.type == value); 57 | } 58 | 59 | final int type; 60 | } 61 | -------------------------------------------------------------------------------- /lib/models/item/advertise_item_model.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | part of '../data_model.dart'; 6 | 7 | @JsonSerializable() 8 | class AdvertiseItemModel extends DataModel { 9 | const AdvertiseItemModel({ 10 | required this.id, 11 | required this.advertId, 12 | required this.userId, 13 | required this.itemId, 14 | required this.itemType, 15 | required this.platform, 16 | required this.layout, 17 | required this.position, 18 | required this.advertType, 19 | required this.stationType, 20 | required this.authorName, 21 | required this.authorId, 22 | required this.title, 23 | required this.brief, 24 | required this.url, 25 | required this.picture, 26 | required this.avatar, 27 | required this.startTime, 28 | required this.endTime, 29 | required this.ctime, 30 | required this.mtime, 31 | required this.saleCount, 32 | required this.salePrice, 33 | required this.discountRate, 34 | required this.diggCount, 35 | required this.commentCount, 36 | required this.topic, 37 | required this.topicId, 38 | required this.status, 39 | required this.itemUserInfo, 40 | }); 41 | 42 | factory AdvertiseItemModel.fromJson(Map json) => 43 | _$AdvertiseItemModelFromJson(json); 44 | 45 | final int id; 46 | final String advertId; 47 | final String userId; 48 | final String itemId; 49 | final int itemType; 50 | final int platform; 51 | final int layout; 52 | final int position; 53 | final int advertType; 54 | final int stationType; 55 | final String authorName; 56 | final String authorId; 57 | final String title; 58 | final String brief; 59 | final String url; 60 | final String picture; 61 | final String avatar; 62 | final String startTime; 63 | final String endTime; 64 | final String ctime; 65 | final String mtime; 66 | final int saleCount; 67 | final int salePrice; 68 | final int discountRate; 69 | final int diggCount; 70 | final int commentCount; 71 | final String topic; 72 | final String topicId; 73 | final int status; 74 | final UserInfoModel itemUserInfo; 75 | 76 | String createTimeString(BuildContext context) { 77 | return DateTime.now() 78 | .difference((int.parse(ctime) * 1000).toDateTimeInMilliseconds) 79 | .differenceString(context); 80 | } 81 | 82 | @override 83 | Map toJson() => _$AdvertiseItemModelToJson(this); 84 | 85 | @override 86 | List get props => [ 87 | id, 88 | advertId, 89 | userId, 90 | itemId, 91 | itemType, 92 | platform, 93 | layout, 94 | position, 95 | advertType, 96 | stationType, 97 | authorName, 98 | authorId, 99 | title, 100 | brief, 101 | url, 102 | picture, 103 | avatar, 104 | startTime, 105 | endTime, 106 | ctime, 107 | mtime, 108 | saleCount, 109 | salePrice, 110 | discountRate, 111 | diggCount, 112 | topic, 113 | topicId, 114 | status, 115 | itemUserInfo, 116 | ]; 117 | } 118 | -------------------------------------------------------------------------------- /lib/models/loading_base.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:convert'; 6 | 7 | import 'package:dio/dio.dart' show DioException, DioExceptionType; 8 | import 'package:flutter/foundation.dart'; 9 | import 'package:loading_more_list/loading_more_list.dart'; 10 | 11 | import '../utils/log_util.dart'; 12 | import 'data_model.dart'; 13 | import 'response_model.dart'; 14 | 15 | enum CursorType { 16 | json, 17 | raw, 18 | } 19 | 20 | class LoadingBase extends LoadingMoreBase { 21 | LoadingBase({ 22 | required this.request, 23 | this.onRefresh, 24 | this.onLoadSucceed, 25 | this.onLoadFailed, 26 | this.getCursorType, 27 | }); 28 | 29 | Future> Function(int page, String? lastId) request; 30 | final VoidCallback? onRefresh; 31 | final Function(LoadingBase lb, bool isMore)? onLoadSucceed; 32 | final Function(LoadingBase lb, bool isMore, Object e)? onLoadFailed; 33 | final CursorType Function()? getCursorType; 34 | 35 | int total = 0; 36 | int page = 1; 37 | String? lastId; 38 | bool canRequestMore = true; 39 | 40 | CursorType get cursorType => getCursorType?.call() ?? CursorType.json; 41 | 42 | @override 43 | bool get hasMore => canRequestMore; 44 | 45 | @override 46 | Future refresh([bool notifyStateChanged = false]) async { 47 | canRequestMore = true; 48 | page = 1; 49 | lastId = null; 50 | onRefresh?.call(); 51 | return super.refresh(notifyStateChanged); 52 | } 53 | 54 | @override 55 | // ignore: avoid_renaming_method_parameters 56 | Future loadData([bool isLoadMoreAction = false]) async { 57 | try { 58 | final int newPage = isLoadMoreAction ? page + 1 : page; 59 | final ResponseModel response = await request(newPage, lastId); 60 | if (response.isSucceed) { 61 | if (!isLoadMoreAction) { 62 | clear(); 63 | } 64 | addAll(response.models!); 65 | total = response.total!; 66 | page = response.page ?? newPage; 67 | lastId = cursorType == CursorType.json 68 | ? (_decodeCursor(response.cursor)?['v']) 69 | : response.cursor; 70 | canRequestMore = response.canLoadMore; 71 | onLoadSucceed?.call(this, isLoadMoreAction); 72 | } else { 73 | onLoadFailed?.call(this, isLoadMoreAction, response.msg); 74 | } 75 | setState(); 76 | return response.isSucceed; 77 | } catch (e, s) { 78 | if (e is DioException && e.type == DioExceptionType.cancel) { 79 | return false; 80 | } 81 | LogUtil.e( 82 | 'Error when loading `$T` list in loading base: $e', 83 | stackTrace: s, 84 | ); 85 | onLoadFailed?.call(this, isLoadMoreAction, e); 86 | return false; 87 | } 88 | } 89 | 90 | bool get isOnlyFirstPage => page == 1 && !hasMore; 91 | 92 | Map? _decodeCursor(String? cursor) { 93 | if (cursor == null) { 94 | return null; 95 | } 96 | try { 97 | return jsonDecode(utf8.decode(base64Decode(cursor))); 98 | } catch (_) { 99 | return null; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /lib/pages/home.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | @FFArgumentImport() 7 | import 'package:juejin/exports.dart'; 8 | 9 | import 'home/articles.dart'; 10 | import 'home/mine.dart'; 11 | import 'home/pins.dart'; 12 | 13 | @FFRoute(name: 'home-page') 14 | class HomePage extends StatefulWidget { 15 | const HomePage({super.key}); 16 | 17 | @override 18 | State createState() => _HomePageState(); 19 | } 20 | 21 | class _HomePageState extends State { 22 | int _currentIndex = 0; 23 | 24 | void _selectIndex(int index) { 25 | setState(() { 26 | _currentIndex = index; 27 | }); 28 | } 29 | 30 | Widget _buildBody(BuildContext context) { 31 | return MediaQuery.removePadding( 32 | context: context, 33 | removeBottom: true, 34 | child: LazyIndexedStack( 35 | index: _currentIndex, 36 | children: const [ArticlesPage(), PinsPage(), MinePage()], 37 | ), 38 | ); 39 | } 40 | 41 | Widget _buildBottomNavigationBar(BuildContext context) { 42 | return BottomNavigationBar( 43 | currentIndex: _currentIndex, 44 | onTap: _selectIndex, 45 | items: [ 46 | BottomNavigationBarItem( 47 | icon: const Icon(Icons.home_outlined), 48 | activeIcon: const Icon(Icons.home), 49 | label: context.l10n.navHome, 50 | ), 51 | BottomNavigationBarItem( 52 | icon: const Icon(Icons.local_fire_department_outlined), 53 | activeIcon: const Icon(Icons.local_fire_department), 54 | label: context.l10n.navPins, 55 | ), 56 | BottomNavigationBarItem( 57 | icon: const Icon(Icons.manage_accounts_outlined), 58 | activeIcon: const Icon(Icons.manage_accounts), 59 | label: context.l10n.navMe, 60 | ), 61 | ], 62 | ); 63 | } 64 | 65 | @override 66 | Widget build(BuildContext context) { 67 | return Scaffold( 68 | body: Column( 69 | children: [ 70 | Expanded(child: _buildBody(context)), 71 | _buildBottomNavigationBar(context), 72 | ], 73 | ), 74 | ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /lib/pages/home/mine.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | import 'package:juejin/exports.dart'; 7 | 8 | class MinePage extends StatefulWidget { 9 | const MinePage({super.key}); 10 | 11 | @override 12 | State createState() => _MinePageState(); 13 | } 14 | 15 | class _MinePageState extends State { 16 | Widget _buildHeaderActions(BuildContext context) { 17 | return Container( 18 | alignment: AlignmentDirectional.centerEnd, 19 | child: IconTheme.merge( 20 | data: IconThemeData(color: context.textTheme.bodyMedium?.color), 21 | child: Row( 22 | mainAxisSize: MainAxisSize.min, 23 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 24 | children: [ 25 | Icon( 26 | context.brightness.isDark 27 | ? Icons.light_mode_outlined 28 | : Icons.dark_mode_outlined, 29 | ), 30 | const Gap.h(16), 31 | const Icon(Icons.notifications_none_outlined), 32 | const Gap.h(16), 33 | const Icon(Icons.settings_outlined), 34 | ], 35 | ), 36 | ), 37 | ); 38 | } 39 | 40 | Widget _buildUserAvatar(BuildContext context) { 41 | return Container( 42 | padding: const EdgeInsets.all(8), 43 | color: context.theme.dividerColor, 44 | child: SvgPicture.asset(R.ASSETS_BRAND_SVG), 45 | ); 46 | } 47 | 48 | Widget _buildUsername(BuildContext context) { 49 | return Text( 50 | context.l10n.userSignInOrUp, 51 | style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600), 52 | ); 53 | } 54 | 55 | Widget _buildUser(BuildContext context) { 56 | return SizedBox( 57 | height: 54, 58 | child: Row( 59 | children: [ 60 | AspectRatio( 61 | aspectRatio: 1, 62 | child: ClipOval( 63 | child: _buildUserAvatar(context), 64 | ), 65 | ), 66 | const Gap.h(16), 67 | _buildUsername(context), 68 | ], 69 | ), 70 | ); 71 | } 72 | 73 | Widget _buildCounters(BuildContext context) { 74 | Widget counter(int? value, String name) { 75 | return Column( 76 | children: [ 77 | Text( 78 | value?.toString() ?? '0', 79 | style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold), 80 | ), 81 | Text(name, style: context.textTheme.bodySmall), 82 | ], 83 | ); 84 | } 85 | 86 | return Padding( 87 | padding: const EdgeInsets.symmetric(horizontal: 14), 88 | child: Row( 89 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 90 | children: [ 91 | counter(0, context.l10n.userLikes), 92 | counter(0, context.l10n.userFavorites), 93 | counter(0, context.l10n.userFollows), 94 | ], 95 | ), 96 | ); 97 | } 98 | 99 | @override 100 | Widget build(BuildContext context) { 101 | return SafeArea( 102 | child: Padding( 103 | padding: const EdgeInsets.symmetric(horizontal: 16), 104 | child: Column( 105 | children: [ 106 | _buildHeaderActions(context), 107 | const Gap.v(28), 108 | _buildUser(context), 109 | const Gap.v(20), 110 | _buildCounters(context), 111 | ], 112 | ), 113 | ), 114 | ); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /lib/pages/splash.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | import 'package:flutter/services.dart'; 7 | import 'package:juejin/exports.dart'; 8 | 9 | @FFRoute(name: 'splash-page') 10 | class SplashPage extends StatefulWidget { 11 | const SplashPage({super.key}); 12 | 13 | @override 14 | State createState() => _SplashPageState(); 15 | } 16 | 17 | class _SplashPageState extends State { 18 | @override 19 | void initState() { 20 | super.initState(); 21 | _initialize(); 22 | } 23 | 24 | Future _initialize() async { 25 | await SystemChrome.setPreferredOrientations([ 26 | DeviceOrientation.portraitUp, 27 | DeviceOrientation.portraitDown, 28 | ]); 29 | SystemChrome.setSystemUIOverlayStyle( 30 | const SystemUiOverlayStyle( 31 | statusBarColor: Colors.transparent, 32 | systemNavigationBarColor: Colors.transparent, 33 | ), 34 | ); 35 | await Future.wait(>[ 36 | DeviceUtil.initDeviceInfo(forceRefresh: true), 37 | PackageUtil.initInfo(), 38 | HttpUtil.init(), 39 | ]); 40 | await DeviceUtil.setHighestRefreshRate(); 41 | await HttpUtil.fetch(FetchType.get, url: 'https://${Urls.domain}'); 42 | if (mounted) { 43 | navigator.pushReplacementNamed(Routes.homePage.name); 44 | } 45 | } 46 | 47 | @override 48 | Widget build(BuildContext context) { 49 | return const Scaffold( 50 | body: Center( 51 | child: JJLogo(heroTag: defaultLogoHeroTag, width: 90), 52 | ), 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/routes/juejin_route.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY MANUALLY 2 | // ************************************************************************** 3 | // Auto generated by https://github.com/fluttercandies/ff_annotation_route 4 | // ************************************************************************** 5 | // ignore_for_file: prefer_const_literals_to_create_immutables,unused_local_variable,unused_import,unnecessary_import 6 | import 'package:ff_annotation_route_library/ff_annotation_route_library.dart'; 7 | import 'package:flutter/widgets.dart'; 8 | import 'package:juejin/exports.dart'; 9 | 10 | import '../pages/article/detail.dart'; 11 | import '../pages/club/club.dart'; 12 | import '../pages/home.dart'; 13 | import '../pages/splash.dart'; 14 | 15 | FFRouteSettings getRouteSettings({ 16 | required String name, 17 | Map? arguments, 18 | PageBuilder? notFoundPageBuilder, 19 | }) { 20 | final Map safeArguments = 21 | arguments ?? const {}; 22 | switch (name) { 23 | case 'article-detail-page': 24 | return FFRouteSettings( 25 | name: name, 26 | arguments: arguments, 27 | builder: () => ArticleDetailPage( 28 | asT( 29 | safeArguments['id'], 30 | )!, 31 | key: asT( 32 | safeArguments['key'], 33 | ), 34 | item: asT( 35 | safeArguments['item'], 36 | ), 37 | ), 38 | ); 39 | case 'club-page': 40 | return FFRouteSettings( 41 | name: name, 42 | arguments: arguments, 43 | builder: () => ClubPage( 44 | asT( 45 | safeArguments['id'], 46 | )!, 47 | key: asT( 48 | safeArguments['key'], 49 | ), 50 | topic: asT( 51 | safeArguments['topic'], 52 | ), 53 | ), 54 | ); 55 | case 'home-page': 56 | return FFRouteSettings( 57 | name: name, 58 | arguments: arguments, 59 | builder: () => HomePage( 60 | key: asT( 61 | safeArguments['key'], 62 | ), 63 | ), 64 | ); 65 | case 'splash-page': 66 | return FFRouteSettings( 67 | name: name, 68 | arguments: arguments, 69 | builder: () => SplashPage( 70 | key: asT( 71 | safeArguments['key'], 72 | ), 73 | ), 74 | ); 75 | default: 76 | return FFRouteSettings( 77 | name: FFRoute.notFoundName, 78 | routeName: FFRoute.notFoundRouteName, 79 | builder: notFoundPageBuilder ?? () => Container(), 80 | ); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /lib/routes/juejin_routes.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY MANUALLY 2 | // ************************************************************************** 3 | // Auto generated by https://github.com/fluttercandies/ff_annotation_route 4 | // ************************************************************************** 5 | // ignore_for_file: prefer_const_literals_to_create_immutables,unused_local_variable,unused_import,unnecessary_import 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:juejin/exports.dart'; 8 | 9 | const List routeNames = [ 10 | 'article-detail-page', 11 | 'club-page', 12 | 'home-page', 13 | 'splash-page', 14 | ]; 15 | 16 | class Routes { 17 | const Routes._(); 18 | 19 | /// 'article-detail-page' 20 | /// 21 | /// [name] : 'article-detail-page' 22 | /// 23 | /// [constructors] : 24 | /// 25 | /// ArticleDetailPage : [String(required) id, Key? key, ArticleItemModel? item] 26 | static const _ArticleDetailPage articleDetailPage = _ArticleDetailPage(); 27 | 28 | /// 'club-page' 29 | /// 30 | /// [name] : 'club-page' 31 | /// 32 | /// [constructors] : 33 | /// 34 | /// ClubPage : [String(required) id, Key? key, PinTopic? topic] 35 | static const _ClubPage clubPage = _ClubPage(); 36 | 37 | /// 'home-page' 38 | /// 39 | /// [name] : 'home-page' 40 | /// 41 | /// [constructors] : 42 | /// 43 | /// HomePage : [Key? key] 44 | static const _HomePage homePage = _HomePage(); 45 | 46 | /// 'splash-page' 47 | /// 48 | /// [name] : 'splash-page' 49 | /// 50 | /// [constructors] : 51 | /// 52 | /// SplashPage : [Key? key] 53 | static const _SplashPage splashPage = _SplashPage(); 54 | } 55 | 56 | class _ArticleDetailPage { 57 | const _ArticleDetailPage(); 58 | 59 | String get name => 'article-detail-page'; 60 | 61 | Map d( 62 | String id, { 63 | Key? key, 64 | ArticleItemModel? item, 65 | }) => 66 | { 67 | 'id': id, 68 | 'key': key, 69 | 'item': item, 70 | }; 71 | 72 | @override 73 | String toString() => name; 74 | } 75 | 76 | class _ClubPage { 77 | const _ClubPage(); 78 | 79 | String get name => 'club-page'; 80 | 81 | Map d( 82 | String id, { 83 | Key? key, 84 | PinTopic? topic, 85 | }) => 86 | { 87 | 'id': id, 88 | 'key': key, 89 | 'topic': topic, 90 | }; 91 | 92 | @override 93 | String toString() => name; 94 | } 95 | 96 | class _HomePage { 97 | const _HomePage(); 98 | 99 | String get name => 'home-page'; 100 | 101 | Map d({ 102 | Key? key, 103 | }) => 104 | { 105 | 'key': key, 106 | }; 107 | 108 | @override 109 | String toString() => name; 110 | } 111 | 112 | class _SplashPage { 113 | const _SplashPage(); 114 | 115 | String get name => 'splash-page'; 116 | 117 | Map d({ 118 | Key? key, 119 | }) => 120 | { 121 | 'key': key, 122 | }; 123 | 124 | @override 125 | String toString() => name; 126 | } 127 | -------------------------------------------------------------------------------- /lib/routes/page_route.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/cupertino.dart'; 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:flutter/material.dart'; 8 | 9 | PageRoute defaultPageRoute({ 10 | required WidgetBuilder builder, 11 | RouteSettings? settings, 12 | bool maintainState = true, 13 | bool fullscreenDialog = false, 14 | }) { 15 | switch (defaultTargetPlatform) { 16 | case TargetPlatform.iOS: 17 | case TargetPlatform.macOS: 18 | return CupertinoPageRoute( 19 | builder: builder, 20 | settings: settings, 21 | maintainState: maintainState, 22 | fullscreenDialog: fullscreenDialog, 23 | ); 24 | default: 25 | return MaterialPageRoute( 26 | builder: builder, 27 | settings: settings, 28 | maintainState: maintainState, 29 | fullscreenDialog: fullscreenDialog, 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/utils/cache_util.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:io'; 6 | 7 | import 'package:path_provider/path_provider.dart'; 8 | 9 | class CacheManager { 10 | const CacheManager._(); 11 | 12 | static const int kb = 1024; 13 | static const int mb = 1024 * kb; 14 | static const int gb = 1024 * mb; 15 | 16 | static Future cacheDir() => getTemporaryDirectory(); 17 | 18 | static Future clear() async { 19 | final Directory dir = await cacheDir(); 20 | await Future.wait( 21 | >[ 22 | for (final FileSystemEntity f in dir.listSync()) 23 | f.delete(recursive: true), 24 | ], 25 | ); 26 | } 27 | 28 | static Future cacheSize() async { 29 | final Directory dir = await cacheDir(); 30 | final List listSync = dir.listSync(recursive: true); 31 | int size = 0; 32 | for (final FileSystemEntity file in listSync) { 33 | size += file.statSync().size; 34 | } 35 | return size; 36 | } 37 | 38 | static Future formatCacheSize() async { 39 | final int size = await cacheSize(); 40 | if (size >= gb) { 41 | return '${(size / gb).toStringAsFixed(2)} GB'; 42 | } 43 | if (size >= mb) { 44 | return '${(size / mb).toStringAsFixed(2)} MB'; 45 | } 46 | if (size >= kb) { 47 | return '${(size / kb).toStringAsFixed(2)} KB'; 48 | } 49 | return '$size B'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/utils/haptic_util.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:async'; 6 | 7 | import 'package:flutter/foundation.dart'; 8 | import 'package:flutter/services.dart'; 9 | 10 | class HapticUtil { 11 | const HapticUtil._(); 12 | 13 | static Future notifySuccess() { 14 | return _shouldUseHapticWrapper( 15 | () => _sequenceWithGap( 16 | haptics: Function()>[ 17 | HapticFeedback.mediumImpact, 18 | HapticFeedback.heavyImpact, 19 | ], 20 | gapInMilliseconds: 150, 21 | ), 22 | ); 23 | } 24 | 25 | static Future notifyWarning() { 26 | return _shouldUseHapticWrapper( 27 | () => _sequenceWithGap( 28 | haptics: Function()>[ 29 | HapticFeedback.heavyImpact, 30 | HapticFeedback.mediumImpact, 31 | ], 32 | gapInMilliseconds: 200, 33 | ), 34 | ); 35 | } 36 | 37 | static Future notifyFailure() { 38 | return _shouldUseHapticWrapper( 39 | () => _sequenceWithGap( 40 | haptics: Function()>[ 41 | HapticFeedback.mediumImpact, 42 | HapticFeedback.mediumImpact, 43 | HapticFeedback.heavyImpact, 44 | HapticFeedback.lightImpact, 45 | ], 46 | gapInMilliseconds: 100, 47 | ), 48 | ); 49 | } 50 | 51 | static Future _sequenceWithGap({ 52 | required List Function()> haptics, 53 | required int gapInMilliseconds, 54 | }) async { 55 | for (int i = 0; i < haptics.length * 2 - 1; i++) { 56 | if (i.isOdd) { 57 | await Future.delayed(Duration(milliseconds: gapInMilliseconds)); 58 | continue; 59 | } 60 | await haptics[i ~/ 2](); 61 | } 62 | } 63 | 64 | static bool get _shouldUseHaptic => 65 | defaultTargetPlatform == TargetPlatform.iOS || 66 | defaultTargetPlatform == TargetPlatform.macOS; 67 | 68 | static Future _shouldUseHapticWrapper(Future Function() fn) { 69 | if (_shouldUseHaptic) { 70 | return fn(); 71 | } 72 | return SynchronousFuture(null); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /lib/utils/package_util.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:convert'; 7 | 8 | import 'package:flutter/foundation.dart'; 9 | import 'package:package_info_plus/package_info_plus.dart'; 10 | 11 | import 'log_util.dart'; 12 | 13 | class PackageUtil { 14 | const PackageUtil._(); 15 | 16 | static late final PackageInfo packageInfo; 17 | static late final String versionName; 18 | static late final int versionCode; 19 | 20 | /// x.y.z+a 21 | static String get versionNameAndCode => '$versionName+$versionCode'; 22 | 23 | static Future initInfo() async { 24 | initInfoManual(await PackageInfo.fromPlatform()); 25 | } 26 | 27 | @visibleForTesting 28 | static void initInfoManual(PackageInfo info) { 29 | packageInfo = info; 30 | if (const bool.hasEnvironment('meAppVersion')) { 31 | final List version = const String.fromEnvironment( 32 | 'meAppVersion', 33 | ).split('+'); 34 | versionName = version.first; 35 | versionCode = int.parse(version.last); 36 | } else { 37 | versionName = packageInfo.version; 38 | versionCode = int.tryParse(packageInfo.buildNumber) ?? 1; 39 | } 40 | LogUtil.d( 41 | 'Package info: ${const JsonEncoder.withIndent(' ').convert( 42 | { 43 | 'appName': packageInfo.appName, 44 | 'packageName': packageInfo.packageName, 45 | 'version': versionName, 46 | 'buildNumber': versionCode, 47 | }, 48 | )}', 49 | tag: '📦 PackageUtil', 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/utils/toast_util.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:oktoast/oktoast.dart' as ok; 6 | 7 | import '../constants/styles.dart' show failedColor; 8 | 9 | void showToast(String text, {Duration? duration}) { 10 | ok.showToast(text, duration: duration); 11 | } 12 | 13 | void showCenterToast(String text) { 14 | ok.showToast( 15 | text, 16 | position: ok.ToastPosition.center, 17 | ); 18 | } 19 | 20 | void showErrorToast(String text) { 21 | ok.showToast( 22 | text, 23 | backgroundColor: failedColor, 24 | ); 25 | } 26 | 27 | void showCenterErrorToast(String text) { 28 | ok.showToast( 29 | text, 30 | position: ok.ToastPosition.center, 31 | backgroundColor: failedColor, 32 | ); 33 | } 34 | 35 | void showTopToast(String text) { 36 | ok.showToast( 37 | text, 38 | position: ok.ToastPosition.top, 39 | ); 40 | } 41 | 42 | void showToastWithPosition(String text, {ok.ToastPosition? position}) { 43 | ok.showToast( 44 | text, 45 | position: position, 46 | ); 47 | } 48 | 49 | void showErrorToastWithPosition(String text, {ok.ToastPosition? position}) { 50 | ok.showToast( 51 | text, 52 | position: position, 53 | ); 54 | } 55 | 56 | void dismissAllToast({bool showAnim = false}) { 57 | ok.dismissAllToast(showAnim: showAnim); 58 | } 59 | -------------------------------------------------------------------------------- /lib/widgets/_none.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/widgets.dart'; 6 | 7 | const None none = None(); 8 | 9 | class None extends Widget { 10 | const None({super.key}); 11 | 12 | @override 13 | Element createElement() => _NoneElement(this); 14 | } 15 | 16 | class _NoneElement extends Element { 17 | _NoneElement(super.widget); 18 | 19 | @override 20 | void mount(Element? parent, dynamic newSlot) { 21 | assert( 22 | parent is! MultiChildRenderObjectElement, 23 | 'You are using None under a MultiChildRenderObjectElement. ' 24 | 'Typically means the None is not needed or is being used improperly. ' 25 | "Make sure it can't be replaced with an inline conditional or " 26 | 'omission of the target widget from a list.', 27 | ); 28 | super.mount(parent, newSlot); 29 | } 30 | 31 | @override 32 | bool get debugDoingBuild => false; 33 | 34 | @override 35 | void performRebuild() { 36 | super.performRebuild(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/widgets/error_widget.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | 7 | import '../constants/themes.dart'; 8 | import '../extensions/build_context_extension.dart'; 9 | import '../utils/log_util.dart'; 10 | import 'logo.dart'; 11 | 12 | class JJErrorWidget extends StatelessWidget { 13 | const JJErrorWidget._(this.details); 14 | 15 | final FlutterErrorDetails details; 16 | 17 | static void takeOver() { 18 | ErrorWidget.builder = (FlutterErrorDetails d) { 19 | LogUtil.e( 20 | 'Error has been delivered to the ErrorWidget: ${d.exception}', 21 | stackTrace: d.stack, 22 | ); 23 | return JJErrorWidget._(d); 24 | }; 25 | } 26 | 27 | @override 28 | Widget build(BuildContext context) { 29 | return Material( 30 | type: MaterialType.transparency, 31 | child: Container( 32 | margin: const EdgeInsets.all(16), 33 | padding: const EdgeInsets.all(16), 34 | decoration: BoxDecoration( 35 | borderRadius: BorderRadius.circular(13), 36 | color: Color.lerp( 37 | Theme.of(context).canvasColor, 38 | themeColorLight, 39 | 0.1, 40 | ), 41 | ), 42 | child: DefaultTextStyle.merge( 43 | style: TextStyle(color: Theme.of(context).textTheme.bodySmall?.color), 44 | child: Column( 45 | mainAxisSize: MainAxisSize.min, 46 | children: [ 47 | const FractionallySizedBox(widthFactor: 0.25, child: JJLogo()), 48 | const SizedBox(height: 20), 49 | Text( 50 | context.l10n.exceptionErrorWidget, 51 | style: const TextStyle(fontSize: 20), 52 | ), 53 | const SizedBox(height: 10), 54 | Text( 55 | details.exception.toString(), 56 | style: const TextStyle( 57 | fontSize: 18, 58 | fontWeight: FontWeight.bold, 59 | ), 60 | ), 61 | const SizedBox(height: 10), 62 | Text( 63 | details.stack.toString(), 64 | style: const TextStyle(fontSize: 13), 65 | maxLines: 10, 66 | overflow: TextOverflow.ellipsis, 67 | ), 68 | ], 69 | ), 70 | ), 71 | ), 72 | ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /lib/widgets/gaps.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | 7 | class Gap extends StatelessWidget { 8 | const Gap.h( 9 | double width, { 10 | super.key, 11 | double? height, 12 | this.color, 13 | }) : _width = width, 14 | _height = height; 15 | 16 | const Gap.v( 17 | double height, { 18 | super.key, 19 | double? width, 20 | this.color, 21 | }) : _width = width, 22 | _height = height; 23 | 24 | factory Gap.bottomInsets(BuildContext context) { 25 | return Gap.v(MediaQuery.of(context).viewInsets.bottom); 26 | } 27 | 28 | final double? _width; 29 | final double? _height; 30 | final Color? color; 31 | 32 | @override 33 | Widget build(BuildContext context) { 34 | Widget w = SizedBox(width: _width, height: _height); 35 | if (color != null) { 36 | w = ColoredBox(color: color!, child: w); 37 | } 38 | return w; 39 | } 40 | } 41 | 42 | class SliverGap extends StatelessWidget { 43 | const SliverGap.h( 44 | double width, { 45 | super.key, 46 | double? height, 47 | this.color, 48 | }) : _width = width, 49 | _height = height; 50 | 51 | const SliverGap.v( 52 | double height, { 53 | super.key, 54 | double? width, 55 | this.color, 56 | }) : _width = width, 57 | _height = height; 58 | 59 | factory SliverGap.bottomInsets(BuildContext context) { 60 | return SliverGap.v(MediaQuery.of(context).viewInsets.bottom); 61 | } 62 | 63 | final double? _width; 64 | final double? _height; 65 | final Color? color; 66 | 67 | @override 68 | Widget build(BuildContext context) { 69 | Widget child; 70 | if (_width != null) { 71 | child = Gap.h(_width!, height: _height, color: color); 72 | } else if (_height != null) { 73 | child = Gap.v(_height!, width: _width, color: color); 74 | } else { 75 | child = const SizedBox.shrink(); 76 | } 77 | return SliverToBoxAdapter(child: child); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /lib/widgets/lazy_indexed_stack.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | 7 | /// A lazy-[IndexedStack] written by [Alex Li](https://github.com/AlexV525) 💙. 8 | /// it lazily build children only when they are first activated. 9 | /// 10 | /// The _lazily build_ here indicates the processes of `Widget`s inflating 11 | /// `Element`s are lazy. 12 | /// 13 | /// See also: 14 | /// https://github.com/AlexV525/dartpad_workshops/tree/main/implement_lazy_indexed_stack 15 | class LazyIndexedStack extends StatefulWidget { 16 | const LazyIndexedStack({ 17 | super.key, 18 | this.alignment = AlignmentDirectional.topStart, 19 | this.textDirection, 20 | this.sizing = StackFit.loose, 21 | this.index = 0, 22 | this.children = const [], 23 | }); 24 | 25 | final AlignmentGeometry alignment; 26 | final TextDirection? textDirection; 27 | final StackFit sizing; 28 | final int? index; 29 | final List children; 30 | 31 | @override 32 | State createState() => _LazyIndexedStackState(); 33 | } 34 | 35 | class _LazyIndexedStackState extends State { 36 | late final List _activatedList = List.generate( 37 | widget.children.length, 38 | (int i) => i == widget.index, 39 | ); 40 | 41 | @override 42 | void didUpdateWidget(LazyIndexedStack oldWidget) { 43 | super.didUpdateWidget(oldWidget); 44 | // Activate new index when it's changed between widgets update. 45 | if (oldWidget.index != widget.index) { 46 | _activateIndex(widget.index); 47 | } 48 | } 49 | 50 | void _activateIndex(int? index) { 51 | if (index == null) { 52 | return; 53 | } 54 | if (!_activatedList[index]) { 55 | setState(() { 56 | _activatedList[index] = true; 57 | }); 58 | } 59 | } 60 | 61 | List _buildChildren(BuildContext context) { 62 | return List.generate( 63 | widget.children.length, 64 | (int i) { 65 | if (_activatedList[i]) { 66 | return widget.children[i]; 67 | } 68 | return const SizedBox.shrink(); 69 | }, 70 | ); 71 | } 72 | 73 | @override 74 | Widget build(BuildContext context) { 75 | return IndexedStack( 76 | alignment: widget.alignment, 77 | textDirection: widget.textDirection, 78 | sizing: widget.sizing, 79 | index: widget.index, 80 | children: _buildChildren(context), 81 | ); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lib/widgets/logo.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | import 'package:flutter_svg/flutter_svg.dart'; 7 | 8 | import '../constants/resources.dart'; 9 | 10 | const String defaultLogoHeroTag = 'jj-hero-default'; 11 | 12 | class JJLogo extends StatelessWidget { 13 | const JJLogo({ 14 | super.key, 15 | this.width, 16 | this.height, 17 | this.heroTag, 18 | this.withText = false, 19 | }); 20 | 21 | final double? width; 22 | final double? height; 23 | final String? heroTag; 24 | final bool withText; 25 | 26 | @override 27 | Widget build(BuildContext context) { 28 | final Widget body = SvgPicture.asset( 29 | withText ? R.ASSETS_BRAND_WITH_TEXT_SVG : R.ASSETS_BRAND_SVG, 30 | width: width, 31 | height: height, 32 | ); 33 | if (heroTag != null) { 34 | return Hero(tag: heroTag!, child: body); 35 | } 36 | return body; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/widgets/refresh/pull_to_refresh_header.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/cupertino.dart' hide RefreshIndicatorMode; 6 | import 'package:flutter/material.dart'; 7 | import 'package:pull_to_refresh_notification/pull_to_refresh_notification.dart'; 8 | 9 | import '../../extensions/build_context_extension.dart'; 10 | import '../tapper.dart'; 11 | 12 | class PullToRefreshHeader extends StatelessWidget { 13 | const PullToRefreshHeader({ 14 | super.key, 15 | this.info, 16 | this.textStyle, 17 | }); 18 | 19 | final PullToRefreshScrollNotificationInfo? info; 20 | final TextStyle? textStyle; 21 | 22 | TextStyle _effectiveTextStyle(BuildContext context) { 23 | if (textStyle != null) { 24 | return textStyle!; 25 | } 26 | return TextStyle( 27 | color: context.theme.dividerColor.withOpacity(0.375), 28 | fontSize: 14, 29 | height: 1.4, 30 | ); 31 | } 32 | 33 | @override 34 | Widget build(BuildContext context) { 35 | Widget widget; 36 | if (info == null) { 37 | return const SliverToBoxAdapter(); 38 | } 39 | 40 | final double dragOffset = info?.dragOffset ?? 0.0; 41 | final PullToRefreshIndicatorMode? mode = info?.mode; 42 | bool isRefreshingMode = false; 43 | 44 | String text; 45 | switch (mode) { 46 | case PullToRefreshIndicatorMode.snap: 47 | case PullToRefreshIndicatorMode.refresh: 48 | isRefreshingMode = true; 49 | text = context.l10n.listRefreshing; 50 | break; 51 | case PullToRefreshIndicatorMode.armed: 52 | text = context.l10n.listRefreshArmed; 53 | break; 54 | case PullToRefreshIndicatorMode.done: 55 | text = context.l10n.listRefreshSucceed; 56 | break; 57 | case PullToRefreshIndicatorMode.error: 58 | text = context.l10n.listRefreshFailed; 59 | break; 60 | default: 61 | text = context.l10n.listRefreshWaiting; 62 | break; 63 | } 64 | 65 | if (mode == PullToRefreshIndicatorMode.done) { 66 | widget = const SizedBox.expand(); 67 | } else { 68 | widget = Row( 69 | mainAxisAlignment: MainAxisAlignment.center, 70 | children: [ 71 | AnimatedSwitcher( 72 | duration: kTabScrollDuration, 73 | child: isRefreshingMode 74 | ? CupertinoActivityIndicator(animating: isRefreshingMode) 75 | : const SizedBox.shrink(), 76 | ), 77 | AnimatedContainer( 78 | duration: kTabScrollDuration, 79 | width: isRefreshingMode ? 10 : 0, 80 | ), 81 | Text(text, style: Theme.of(context).textTheme.bodySmall), 82 | ], 83 | ); 84 | } 85 | 86 | widget = SizedBox(height: dragOffset, child: widget); 87 | 88 | if (mode == PullToRefreshIndicatorMode.error) { 89 | widget = Tapper( 90 | onTap: () => info?.pullToRefreshNotificationState.show(), 91 | child: SizedBox( 92 | height: dragOffset, 93 | child: Center(child: Text(context.l10n.listNetworkErrorClickRetry)), 94 | ), 95 | ); 96 | } 97 | 98 | return SliverToBoxAdapter( 99 | child: DefaultTextStyle( 100 | style: _effectiveTextStyle(context), 101 | child: widget, 102 | ), 103 | ); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /lib/widgets/refresh/refresh_grid_wrapper.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | import 'package:loading_more_list/loading_more_list.dart'; 7 | 8 | import '../../models/data_model.dart'; 9 | import 'base_refresh_wrapper.dart'; 10 | 11 | class RefreshGridWrapper extends BaseRefreshWrapper { 12 | const RefreshGridWrapper({ 13 | super.key, 14 | required super.loadingBase, 15 | required super.itemBuilder, 16 | required this.gridDelegate, 17 | super.sliversBuilder, 18 | super.controller, 19 | super.scrollDirection, 20 | super.enableRefresh, 21 | super.padding, 22 | super.shouldIndicatorFillRemaining, 23 | super.indicatorBuilder, 24 | super.indicatorPlaceholder, 25 | super.indicatorIcon, 26 | super.indicatorPackage, 27 | super.indicatorText, 28 | super.indicatorTextStyle, 29 | super.refreshHeaderBuilder, 30 | super.refreshHeaderTextStyle, 31 | }); 32 | 33 | RefreshGridWrapper.count({ 34 | super.key, 35 | required super.loadingBase, 36 | required super.itemBuilder, 37 | required int crossAxisCount, 38 | double mainAxisSpacing = 0.0, 39 | double crossAxisSpacing = 0.0, 40 | double childAspectRatio = 1.0, 41 | double? mainAxisExtent, 42 | super.controller, 43 | super.scrollDirection, 44 | super.enableRefresh, 45 | super.padding, 46 | super.shouldIndicatorFillRemaining, 47 | super.indicatorBuilder, 48 | super.indicatorPlaceholder, 49 | super.indicatorIcon, 50 | super.indicatorPackage, 51 | super.indicatorText, 52 | super.indicatorTextStyle, 53 | super.indicatorWidth, 54 | super.refreshHeaderBuilder, 55 | super.refreshHeaderTextStyle, 56 | super.lastChildLayoutType, 57 | }) : gridDelegate = SliverGridDelegateWithFixedCrossAxisCount( 58 | crossAxisCount: crossAxisCount, 59 | mainAxisSpacing: mainAxisSpacing, 60 | crossAxisSpacing: crossAxisSpacing, 61 | childAspectRatio: childAspectRatio, 62 | mainAxisExtent: mainAxisExtent, 63 | ); 64 | 65 | final SliverGridDelegate gridDelegate; 66 | 67 | @override 68 | SliverListConfig buildConfig(BuildContext context) { 69 | return SliverListConfig( 70 | sourceList: loadingBase, 71 | padding: buildEffectivePadding(context), 72 | indicatorBuilder: effectiveIndicatorBuilder, 73 | gridDelegate: gridDelegate, 74 | itemBuilder: (_, T model, __) => itemBuilder(model), 75 | lastChildLayoutType: lastChildLayoutType, 76 | ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /lib/widgets/refresh/refresh_list_wrapper.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'package:flutter/material.dart'; 6 | import 'package:juejin/exports.dart'; 7 | import 'package:loading_more_list/loading_more_list.dart'; 8 | 9 | class RefreshListWrapper extends BaseRefreshWrapper { 10 | const RefreshListWrapper({ 11 | super.key, 12 | required super.loadingBase, 13 | required super.itemBuilder, 14 | super.sliversBuilder, 15 | super.controller, 16 | super.scrollDirection, 17 | super.enableRefresh, 18 | super.padding, 19 | super.shouldIndicatorFillRemaining, 20 | super.indicatorBuilder, 21 | super.indicatorPlaceholder, 22 | super.indicatorIcon, 23 | super.indicatorPackage, 24 | super.indicatorText, 25 | super.indicatorTextStyle, 26 | super.indicatorWidth, 27 | super.refreshHeaderBuilder, 28 | super.refreshHeaderTextStyle, 29 | super.lastChildLayoutType, 30 | this.dividerBuilder, 31 | super.physics, 32 | }); 33 | 34 | final IndexedWidgetBuilder? dividerBuilder; 35 | 36 | @override 37 | SliverListConfig buildConfig(BuildContext context) { 38 | return SliverListConfig( 39 | sourceList: loadingBase, 40 | itemBuilder: (BuildContext c, T model, int index) { 41 | if (dividerBuilder == null) { 42 | return itemBuilder(model); 43 | } 44 | if (index.isEven) { 45 | return itemBuilder(loadingBase[index ~/ 2]); 46 | } 47 | return dividerBuilder!(c, index); 48 | }, 49 | indicatorBuilder: effectiveIndicatorBuilder, 50 | childCountBuilder: dividerBuilder != null 51 | ? (int length) => length == 0 ? 0 : length * 2 - 1 52 | : null, 53 | getActualIndex: dividerBuilder != null ? (int index) => index ~/ 2 : null, 54 | padding: buildEffectivePadding(context), 55 | lastChildLayoutType: lastChildLayoutType, 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | #include 10 | 11 | void fl_register_plugins(FlPluginRegistry* registry) { 12 | g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = 13 | fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); 14 | url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); 15 | } 16 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | url_launcher_linux 7 | ) 8 | 9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /linux/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 | -------------------------------------------------------------------------------- /linux/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 | -------------------------------------------------------------------------------- /macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import device_info_plus 9 | import package_info_plus 10 | import path_provider_foundation 11 | import url_launcher_macos 12 | 13 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 14 | DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) 15 | FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) 16 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) 17 | UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) 18 | } 19 | -------------------------------------------------------------------------------- /macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '10.11' 2 | 3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 5 | 6 | project 'Runner', { 7 | 'Debug' => :debug, 8 | 'Profile' => :release, 9 | 'Release' => :release, 10 | } 11 | 12 | def flutter_root 13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) 14 | unless File.exist?(generated_xcode_build_settings_path) 15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" 16 | end 17 | 18 | File.foreach(generated_xcode_build_settings_path) do |line| 19 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 20 | return matches[1].strip if matches 21 | end 22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" 23 | end 24 | 25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 26 | 27 | flutter_macos_podfile_setup 28 | 29 | target 'Runner' do 30 | use_frameworks! 31 | use_modular_headers! 32 | 33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) 34 | end 35 | 36 | post_install do |installer| 37 | installer.pods_project.targets.each do |target| 38 | flutter_additional_macos_build_settings(target) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /macos/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - device_info_plus_macos (0.0.1): 3 | - FlutterMacOS 4 | - FlutterMacOS (1.0.0) 5 | - package_info_plus_macos (0.0.1): 6 | - FlutterMacOS 7 | - path_provider_macos (0.0.1): 8 | - FlutterMacOS 9 | - url_launcher_macos (0.0.1): 10 | - FlutterMacOS 11 | 12 | DEPENDENCIES: 13 | - device_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos`) 14 | - FlutterMacOS (from `Flutter/ephemeral`) 15 | - package_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus_macos/macos`) 16 | - path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`) 17 | - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) 18 | 19 | EXTERNAL SOURCES: 20 | device_info_plus_macos: 21 | :path: Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos 22 | FlutterMacOS: 23 | :path: Flutter/ephemeral 24 | package_info_plus_macos: 25 | :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus_macos/macos 26 | path_provider_macos: 27 | :path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos 28 | url_launcher_macos: 29 | :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos 30 | 31 | SPEC CHECKSUMS: 32 | device_info_plus_macos: 1ad388a1ef433505c4038e7dd9605aadd1e2e9c7 33 | FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 34 | package_info_plus_macos: f010621b07802a241d96d01876d6705f15e77c1c 35 | path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19 36 | url_launcher_macos: 597e05b8e514239626bcf4a850fcf9ef5c856ec3 37 | 38 | PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c 39 | 40 | COCOAPODS: 1.11.3 41 | -------------------------------------------------------------------------------- /macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /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 = juejin 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.fluttercandies.juejin 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2022 com.fluttercandies. All rights reserved. 15 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.client 10 | 11 | com.apple.security.network.server 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 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 | -------------------------------------------------------------------------------- /macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.network.client 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: juejin 2 | description: Xitu Juejin APP on Flutter. 3 | publish_to: 'none' 4 | version: 1.0.0+1 5 | 6 | environment: 7 | sdk: ">=3.1.0" 8 | flutter: ">=3.13.0" 9 | 10 | dependencies: 11 | collection: ^1.16.0 12 | cookie_jar: ^4.0.8 13 | device_info_plus: ^9.1.0 14 | dio: ^5.1.0 15 | dio_cookie_manager: ^3.1.1 16 | equatable: ^2.0.3 17 | extended_sliver: ^2.1.3 18 | extended_text: ^11.1.0 19 | ff_annotation_route_library: ^3.0.0 20 | flutter: 21 | sdk: flutter 22 | flutter_displaymode: ^0.6.0 23 | flutter_inappwebview: ^5.4.3+7 24 | flutter_localizations: 25 | sdk: flutter 26 | flutter_svg: ^2.0.7 27 | intl: any 28 | json_annotation: ^4.6.0 29 | loading_more_list: ^5.0.0 30 | logging: ^1.0.2 31 | oktoast: ^3.2.0 32 | package_info_plus: ^4.2.0 33 | path_provider: ^2.0.11 34 | pull_to_refresh_notification: ^3.1.0 35 | url_launcher: ^6.1.5 36 | visibility_detector: ^0.4.0+2 37 | 38 | dev_dependencies: 39 | archive: ^3.3.0 40 | args: ^2.3.1 41 | build_runner: ^2.2.0 42 | crypto: ^3.0.2 43 | flutter_lints: ^3.0.0 44 | flutter_test: 45 | sdk: flutter 46 | json_serializable: ^6.3.1 47 | path: ^1.8.1 48 | process_run: ^0.13.2 49 | yaml: ^3.1.1 50 | 51 | flutter: 52 | uses-material-design: true 53 | assets: 54 | - assets/ 55 | - assets/icon/ 56 | - assets/icon/post/ 57 | - assets/icon/user/ 58 | - assets/icon/topic/ 59 | -------------------------------------------------------------------------------- /test/api_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:juejin/exports.dart'; 5 | import 'package:package_info_plus/package_info_plus.dart'; 6 | 7 | void main() { 8 | TestWidgetsFlutterBinding.ensureInitialized(); 9 | 10 | PackageUtil.initInfoManual( 11 | PackageInfo( 12 | appName: 'JJ Test', 13 | buildNumber: '1', 14 | packageName: 'com.juejin', 15 | version: '1', 16 | ), 17 | ); 18 | 19 | // uncomment this line to test api 20 | // HttpOverrides.global = null; 21 | 22 | // HttpUtil.isLogging = true; 23 | 24 | HttpUtil.initFromDirectory(Directory.systemTemp); 25 | 26 | test('RecommendAPI', () async { 27 | final cates = await RecommendAPI.getAllFeedArticles(); 28 | assert(cates.isSucceed); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /tools/internals/command.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:io'; 7 | 8 | import 'package:args/args.dart'; 9 | import 'package:args/command_runner.dart'; 10 | import 'package:process_run/shell.dart'; 11 | 12 | import 'constants.dart'; 13 | import 'utils.dart'; 14 | 15 | abstract class JJCommand extends Command { 16 | /// Remember to call `super` when constructing with a subclass. 17 | JJCommand() { 18 | argParser.addFlag( 19 | KEY_VERBOSE, 20 | help: 'Display full outputs.', 21 | ); 22 | } 23 | 24 | ArgResults get validArgResults => argResults ?? _fallbackResults; 25 | late ArgResults _fallbackResults; 26 | late final bool argResultVerbose = 27 | validArgResults[KEY_VERBOSE] as bool? ?? false; 28 | final Stopwatch stopwatch = Stopwatch(); 29 | 30 | Future runProcess(); 31 | 32 | FutureOr afterRan() async {} 33 | 34 | @override 35 | Future run() async { 36 | _throwIfNotSupported(); 37 | try { 38 | stopwatch.start(); 39 | await runProcess(); 40 | stopwatch.stop(); 41 | await afterRan(); 42 | } catch (e, s) { 43 | log(composeLogString('Exception occurred: $e')); 44 | if (e is ShellException) { 45 | log(composeLogString('========== STD ERR ==========')); 46 | log(composeLogString(e.result?.stdout)); 47 | log(composeLogString(e.result?.stderr)); 48 | } 49 | if (s != StackTrace.empty) { 50 | log(composeLogString('========== STACK TRACE ==========')); 51 | log(composeLogString(s)); 52 | } 53 | exit(-1); 54 | } 55 | } 56 | 57 | /// This allow the command to be ran as a standalone. 58 | void runStandalone(List arguments) { 59 | _fallbackResults = argParser.parse(arguments); 60 | runZonedGuarded(runProcess, (Object e, StackTrace s) { 61 | log(composeLogString('Exception occurred: $e')); 62 | if (e is ShellException) { 63 | log(composeLogString('========== STD ERR ==========')); 64 | log(composeLogString(e.result?.stdout)); 65 | log(composeLogString(e.result?.stderr)); 66 | } 67 | if (s != StackTrace.empty) { 68 | log(composeLogString('========== STACK TRACE ==========')); 69 | log(composeLogString(s)); 70 | } 71 | exit(-1); 72 | }); 73 | } 74 | 75 | void _throwIfNotSupported() { 76 | if (!Platform.isMacOS && !Platform.isWindows && !Platform.isLinux) { 77 | throw OSError('${Platform.operatingSystem} is not supported.'); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tools/internals/constants.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | typedef Json = Map; 6 | 7 | const String PROJECT_NAME = 'juejin'; 8 | 9 | const String IOS_METHOD_ADHOC = 'AdHoc'; 10 | const String IOS_METHOD_STORE = 'AppStore'; 11 | 12 | const String RELEASE_DIR = 'release'; 13 | 14 | //////////////////////////////////////////////////////////////////////////////// 15 | /////////////////////////////// Builder options //////////////////////////////// 16 | //////////////////////////////////////////////////////////////////////////////// 17 | 18 | const String COMMAND_MODEL = 'model'; 19 | const String COMMAND_RELEASE = 'release'; 20 | const String COMMAND_VERSION = 'version'; 21 | 22 | const String KEY_VERBOSE = 'verbose'; 23 | const String KEY_APP_CHANNEL = 'channel'; 24 | const String KEY_ANDROID_BUILD_TYPE = 'android-build-type'; 25 | const String KEY_IOS_METHOD = 'ios-method'; 26 | const String KEY_WITH = 'with'; 27 | const String KEY_VERSION = 'version'; 28 | const String KEY_INCREASE_BUILD = 'increase-build'; 29 | const String KEY_BUILD_NUMBER = 'build-number'; 30 | const String KEY_COMMIT = 'commit'; 31 | const String KEY_PUSH = 'push'; 32 | -------------------------------------------------------------------------------- /tools/internals/defs.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | class AndroidBuildType { 6 | const AndroidBuildType({ 7 | required this.name, 8 | required this.outputPath, 9 | required this.extension, 10 | }); 11 | 12 | factory AndroidBuildType.apk() { 13 | return const AndroidBuildType( 14 | name: 'apk', 15 | outputPath: 'flutter-apk', 16 | extension: 'apk', 17 | ); 18 | } 19 | 20 | factory AndroidBuildType.bundle() { 21 | return const AndroidBuildType( 22 | name: 'appbundle', 23 | outputPath: 'bundle/release', 24 | extension: 'aab', 25 | ); 26 | } 27 | 28 | final String name; 29 | final String outputPath; 30 | final String? extension; 31 | } 32 | -------------------------------------------------------------------------------- /tools/internals/utils.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:io'; 6 | 7 | import 'package:path/path.dart' as path; 8 | import 'package:process_run/shell.dart'; 9 | import 'package:yaml/yaml.dart'; 10 | 11 | Future obtainYamlFromPath(String path) async { 12 | return loadYaml( 13 | await File('$path/pubspec.yaml').readAsString(), 14 | ) as YamlMap; 15 | } 16 | 17 | String composeLogString(Object v, {int background = 1, int color = 31}) { 18 | return '\x1B[$background;${color}m$v\x1B[0m'; 19 | } 20 | 21 | /// [background] 背景色 22 | /// * 40 - 白 23 | /// * 41 - 红 24 | /// * 42 - 绿 25 | /// * 43 - 黄 26 | /// * 44 - 橙 27 | /// * 45 - 紫 28 | /// * 46 - 靛 29 | /// * 47 - 灰黑 30 | /// 31 | /// [color] 文字颜色 32 | /// * 31 - 红 33 | /// * 32 - 绿 34 | /// * 33 - 黄 35 | /// * 34 - 蓝 36 | /// * 35 - 紫 37 | /// * 36 - 靛 38 | /// * 37 - 灰黑 39 | void log(Object content, {int background = 1, int color = 31}) { 40 | // ignore: avoid_print 41 | print(composeLogString(content, background: background, color: color)); 42 | } 43 | 44 | void catchingError(Object e, String executionName) { 45 | log('$e'); 46 | log("\nRun '$executionName -h' for available commands and options."); 47 | exit(-1); 48 | } 49 | 50 | Future> pullFromDirectory( 51 | String directory, { 52 | bool verbose = false, 53 | }) { 54 | log( 55 | '📥 [git] Pulling ${directory.split('/').last}...', 56 | color: 34, 57 | ); 58 | return Shell( 59 | workingDirectory: directory, 60 | verbose: verbose, 61 | commandVerbose: verbose, 62 | commentVerbose: verbose, 63 | ).run('git pull'); 64 | } 65 | 66 | Shell obtainShell({bool verbose = false}) { 67 | return Shell( 68 | workingDirectory: path.current, 69 | verbose: verbose, 70 | commandVerbose: verbose, 71 | commentVerbose: verbose, 72 | ); 73 | } 74 | 75 | extension FileExtension on File { 76 | Future writeFirstLineStartsWith( 77 | String startsWith, 78 | String content, 79 | ) async { 80 | final List lines = await readAsLines(); 81 | int versionLine = 0; 82 | for (final String line in lines) { 83 | if (line.startsWith(startsWith)) { 84 | break; 85 | } 86 | versionLine++; 87 | } 88 | lines[versionLine] = content; 89 | await writeAsString(lines.join('\n')); 90 | return content; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tools/jj.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The FlutterCandies author. All rights reserved. 2 | // Use of this source code is governed by a MIT license that can be found in the 3 | // LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:io'; 7 | 8 | import 'package:args/command_runner.dart'; 9 | import 'package:process_run/shell.dart'; 10 | 11 | import 'internals/command.dart'; 12 | import 'internals/utils.dart'; 13 | import 'src/models.dart'; 14 | import 'src/release.dart'; 15 | import 'src/version.dart'; 16 | 17 | void main(List arguments) { 18 | runZonedGuarded(() async { 19 | final CommandRunner runner = CommandRunner( 20 | 'jj', 21 | 'Manage your Juejin app development', 22 | ); 23 | _command.forEach(runner.addCommand); 24 | await runner.run(arguments); 25 | }, (Object e, StackTrace s) { 26 | log(composeLogString('Exception occurred: $e')); 27 | if (e is ShellException) { 28 | log(composeLogString('========== STD ERR ==========')); 29 | log(composeLogString(e.result?.stderr)); 30 | } 31 | if (s != StackTrace.empty) { 32 | log(composeLogString('========== STACK TRACE ==========')); 33 | log(composeLogString(s)); 34 | } 35 | exit(-1); 36 | }); 37 | } 38 | 39 | final List _command = [ 40 | ModelsCommand(), 41 | ReleaseCommand(), 42 | VersionCommand(), 43 | ]; 44 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | #include 10 | 11 | void RegisterPlugins(flutter::PluginRegistry* registry) { 12 | UrlLauncherWindowsRegisterWithRegistrar( 13 | registry->GetRegistrarForPlugin("UrlLauncherWindows")); 14 | } 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | url_launcher_windows 7 | ) 8 | 9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /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 | # Disable Windows macros that collide with C++ standard library functions. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 25 | 26 | # Add dependency libraries and include directories. Add any application-specific 27 | # dependencies here. 28 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 29 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 30 | 31 | # Run the Flutter tool portions of the build. This must not be removed. 32 | add_dependencies(${BINARY_NAME} flutter_assemble) 33 | -------------------------------------------------------------------------------- /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 | #ifdef FLUTTER_BUILD_NUMBER 64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0 67 | #endif 68 | 69 | #ifdef FLUTTER_BUILD_NAME 70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME 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.fluttercandies" "\0" 93 | VALUE "FileDescription", "juejin" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "juejin" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.fluttercandies. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "juejin.exe" "\0" 98 | VALUE "ProductName", "juejin" "\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 | -------------------------------------------------------------------------------- /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 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.CreateAndShow(L"juejin", 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fluttercandies/flutter_juejin/09a5c2de8b882dc46c1b6b79ce8cf1070a05bdaa/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /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 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 and shows a win32 window with |title| and position and size 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 to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | --------------------------------------------------------------------------------