├── linux ├── .gitignore ├── main.cc ├── flutter │ ├── generated_plugin_registrant.h │ ├── generated_plugin_registrant.cc │ ├── generated_plugins.cmake │ └── CMakeLists.txt ├── my_application.h ├── my_application.cc └── CMakeLists.txt ├── lib ├── app │ ├── views │ │ ├── news │ │ │ ├── news_hotcomment_view.dart │ │ │ ├── news_rank_view.dart │ │ │ ├── news_category_view.dart │ │ │ └── news_new_view.dart │ │ ├── quan_page.dart │ │ ├── user_page.dart │ │ └── news_page.dart │ ├── route │ │ ├── route_path.dart │ │ └── app_pages.dart │ ├── controller │ │ ├── app_settings_controller.dart │ │ ├── index_controller.dart │ │ ├── news │ │ │ ├── news_category_controller.dart │ │ │ ├── news_new_controller.dart │ │ │ └── news_detail_controller.dart │ │ ├── base_controller.dart │ │ └── news_controller.dart │ ├── common │ │ ├── log.dart │ │ ├── app_dialog.dart │ │ ├── event_bus.dart │ │ ├── app_navigator.dart │ │ ├── utils.dart │ │ └── app_style.dart │ ├── service │ │ ├── app_settings_service.dart │ │ └── app_storage_service.dart │ └── my_app.dart ├── model │ ├── category_item.dart │ ├── ff_convert.dart │ ├── news_banner_model.dart │ ├── news_item_model.dart │ └── news_detail_model.dart ├── request │ ├── api.dart │ ├── http_client.dart │ └── news_request.dart ├── storage │ ├── news_collect.dart │ ├── news_history.dart │ ├── news_collect.g.dart │ └── news_history.g.dart ├── widget │ ├── keep_alive_wrapper.dart │ ├── loadding.dart │ ├── adjustable_scroll_controller.dart │ ├── error.dart │ ├── empty.dart │ ├── net_image.dart │ ├── controller_widget.dart │ ├── bilibili_video_card.dart │ └── news_item.dart └── main.dart ├── ios ├── Runner │ ├── Runner-Bridging-Header.h │ ├── Assets.xcassets │ │ ├── LaunchImage.imageset │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ ├── README.md │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-83.5x83.5@2x.png │ │ │ └── Contents.json │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── Main.storyboard │ │ └── LaunchScreen.storyboard │ └── Info.plist ├── Flutter │ ├── Debug.xcconfig │ ├── Release.xcconfig │ └── AppFrameworkInfo.plist ├── Runner.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── WorkspaceSettings.xcsettings │ │ └── IDEWorkspaceChecks.plist ├── .gitignore ├── Podfile └── Podfile.lock ├── web ├── favicon.png ├── icons │ ├── Icon-192.png │ ├── Icon-512.png │ ├── Icon-maskable-192.png │ └── Icon-maskable-512.png ├── manifest.json └── index.html ├── assets ├── logo │ ├── logo.png │ ├── about_logo.png │ └── about_logo_night2.png ├── icon │ ├── nav_find.png │ ├── nav_me.png │ ├── nav_quan.png │ ├── nav_ithome.png │ └── nav_lapin.png └── status │ └── empty.png ├── android ├── gradle.properties ├── app │ ├── src │ │ ├── main │ │ │ ├── res │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── drawable │ │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable-v21 │ │ │ │ │ └── launch_background.xml │ │ │ │ ├── values │ │ │ │ │ └── styles.xml │ │ │ │ └── values-night │ │ │ │ │ └── styles.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── flutter_ithome │ │ │ │ │ └── MainActivity.kt │ │ │ └── AndroidManifest.xml │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ └── profile │ │ │ └── AndroidManifest.xml │ └── build.gradle ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle └── build.gradle ├── macos ├── Runner │ ├── Configs │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ ├── Warnings.xcconfig │ │ └── AppInfo.xcconfig │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ ├── app_icon_128.png │ │ │ ├── app_icon_16.png │ │ │ ├── app_icon_256.png │ │ │ ├── app_icon_32.png │ │ │ ├── app_icon_512.png │ │ │ ├── app_icon_64.png │ │ │ ├── app_icon_1024.png │ │ │ └── Contents.json │ ├── AppDelegate.swift │ ├── Release.entitlements │ ├── MainFlutterWindow.swift │ ├── DebugProfile.entitlements │ └── Info.plist ├── .gitignore ├── Flutter │ ├── Flutter-Debug.xcconfig │ ├── Flutter-Release.xcconfig │ └── GeneratedPluginRegistrant.swift ├── Runner.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── Runner.xcodeproj │ ├── project.xcworkspace │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── Runner.xcscheme ├── Podfile └── Podfile.lock ├── windows ├── runner │ ├── resources │ │ └── app_icon.ico │ ├── resource.h │ ├── utils.h │ ├── runner.exe.manifest │ ├── flutter_window.h │ ├── CMakeLists.txt │ ├── main.cpp │ ├── utils.cpp │ ├── flutter_window.cpp │ ├── Runner.rc │ ├── win32_window.h │ └── win32_window.cpp ├── .gitignore ├── flutter │ ├── generated_plugin_registrant.h │ ├── generated_plugin_registrant.cc │ ├── generated_plugins.cmake │ └── CMakeLists.txt └── CMakeLists.txt ├── README.md ├── pubspec.yaml ├── .gitignore ├── analysis_options.yaml └── .metadata /linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /lib/app/views/news/news_hotcomment_view.dart: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/web/favicon.png -------------------------------------------------------------------------------- /assets/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/logo/logo.png -------------------------------------------------------------------------------- /assets/icon/nav_find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/icon/nav_find.png -------------------------------------------------------------------------------- /assets/icon/nav_me.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/icon/nav_me.png -------------------------------------------------------------------------------- /assets/icon/nav_quan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/icon/nav_quan.png -------------------------------------------------------------------------------- /assets/status/empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/status/empty.png -------------------------------------------------------------------------------- /web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/web/icons/Icon-192.png -------------------------------------------------------------------------------- /web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/web/icons/Icon-512.png -------------------------------------------------------------------------------- /assets/icon/nav_ithome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/icon/nav_ithome.png -------------------------------------------------------------------------------- /assets/icon/nav_lapin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/icon/nav_lapin.png -------------------------------------------------------------------------------- /assets/logo/about_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/logo/about_logo.png -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /assets/logo/about_logo_night2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/assets/logo/about_logo_night2.png -------------------------------------------------------------------------------- /macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/app/route/route_path.dart: -------------------------------------------------------------------------------- 1 | class RoutePath { 2 | /// 首页 3 | static const kIndex = "/index"; 4 | static const kNewsDetail = "/news/detail"; 5 | } 6 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /lib/model/category_item.dart: -------------------------------------------------------------------------------- 1 | class CategoryItem { 2 | final String name; 3 | final String id; 4 | CategoryItem({required this.id, required this.name}); 5 | } 6 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaoyaocz/flutter_ithome/HEAD/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/example/flutter_ithome/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.flutter_ithome 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IT之家Flutter 2 | 3 | 全平台支持的IT之家第三方客户端 4 | 5 | 个人练习用,施工中... 6 | 7 | ![macos.png](https://vip2.loli.io/2022/06/12/yE1eQRMoGlYH5AJ.png) 8 | 9 | 支持的平台: 10 | ✅ iOS 11 | ✅ Android 12 | ✅ Windows 13 | ✅ MacOS 14 | ✅ Linux 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /lib/app/views/quan_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:get/get.dart'; 3 | 4 | class QuanPage extends GetWidget { 5 | const QuanPage({Key? key}) : super(key: key); 6 | 7 | @override 8 | Widget build(BuildContext context) { 9 | return Container(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/request/api.dart: -------------------------------------------------------------------------------- 1 | class Api { 2 | static const String kApiBaseUrl = "https://api.ithome.com"; 3 | static const String kWebApiBaseUrl = "https://m.ithome.com"; 4 | static const String kQuanApiBaseUrl = "https://qapi.ithome.com"; 5 | static const String kCommentApiBaseUrl = "https://cmt.ithome.com"; 6 | } 7 | -------------------------------------------------------------------------------- /macos/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 | -------------------------------------------------------------------------------- /macos/Runner.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/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.network.client 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/storage/news_collect.dart: -------------------------------------------------------------------------------- 1 | import 'package:hive/hive.dart'; 2 | 3 | part 'news_collect.g.dart'; 4 | 5 | @HiveType(typeId: 1) 6 | class NewsCollect { 7 | @HiveField(0) 8 | int? id; 9 | 10 | @HiveField(1) 11 | String? image; 12 | 13 | @HiveField(2) 14 | String? title; 15 | 16 | @HiveField(3) 17 | String? url; 18 | 19 | @HiveField(4) 20 | DateTime? addDate; 21 | } 22 | -------------------------------------------------------------------------------- /lib/storage/news_history.dart: -------------------------------------------------------------------------------- 1 | import 'package:hive/hive.dart'; 2 | 3 | part 'news_history.g.dart'; 4 | 5 | @HiveType(typeId: 2) 6 | class NewsHistory { 7 | @HiveField(0) 8 | int? id; 9 | 10 | @HiveField(1) 11 | String? image; 12 | 13 | @HiveField(2) 14 | String? title; 15 | 16 | @HiveField(3) 17 | String? url; 18 | 19 | @HiveField(4) 20 | DateTime? addDate; 21 | } 22 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_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 | -------------------------------------------------------------------------------- /lib/app/views/news/news_rank_view.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class NewsRankView extends StatelessWidget { 4 | const NewsRankView({Key? key}) : super(key: key); 5 | 6 | @override 7 | Widget build(BuildContext context) { 8 | return Scaffold( 9 | body: Column( 10 | children: [ 11 | Row( 12 | children: [], 13 | ), 14 | ], 15 | ), 16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 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 | -------------------------------------------------------------------------------- /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/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/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | com.apple.security.network.client 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/widget/keep_alive_wrapper.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class KeepAliveWrapper extends StatefulWidget { 4 | final Widget child; 5 | 6 | const KeepAliveWrapper({Key? key, required this.child}) : super(key: key); 7 | 8 | @override 9 | State createState() => _KeepAliveWrapperState(); 10 | } 11 | 12 | class _KeepAliveWrapperState extends State 13 | with AutomaticKeepAliveClientMixin { 14 | @override 15 | Widget build(BuildContext context) { 16 | super.build(context); 17 | return widget.child; 18 | } 19 | 20 | @override 21 | bool get wantKeepAlive => true; 22 | } 23 | -------------------------------------------------------------------------------- /lib/widget/loadding.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/common/app_style.dart'; 3 | 4 | class LoaddingWidget extends StatelessWidget { 5 | const LoaddingWidget({Key? key}) : super(key: key); 6 | 7 | @override 8 | Widget build(BuildContext context) { 9 | return Center( 10 | child: Container( 11 | padding: AppStyle.edgeInsetsA24, 12 | decoration: BoxDecoration( 13 | color: Theme.of(context).cardColor, 14 | borderRadius: BorderRadius.circular(12), 15 | ), 16 | child: const CircularProgressIndicator(), 17 | ), 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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/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 = IT之家Flutter 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterIthome 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2022 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import path_provider_macos 9 | import share_plus_macos 10 | import url_launcher_macos 11 | import wakelock_macos 12 | 13 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 14 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) 15 | SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) 16 | UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) 17 | WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin")) 18 | } 19 | -------------------------------------------------------------------------------- /lib/app/controller/app_settings_controller.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/service/app_settings_service.dart'; 3 | import 'package:get/get.dart'; 4 | 5 | class AppSettingsController extends GetxController { 6 | var darkMode = false.obs; 7 | @override 8 | void onInit() { 9 | // 繁体名称转简体 10 | darkMode.value = AppSettingsService.instance 11 | .getValue(AppSettingsService.kDarkMode, false); 12 | super.onInit(); 13 | } 14 | 15 | void changeDarkMode(bool e) { 16 | darkMode.value = e; 17 | AppSettingsService.instance.setValue(AppSettingsService.kDarkMode, e); 18 | Get.changeThemeMode(e ? ThemeMode.dark : ThemeMode.light); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.6.10' 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 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/app/controller/index_controller.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_ithome/app/common/event_bus.dart'; 2 | import 'package:flutter_ithome/app/views/news_page.dart'; 3 | import 'package:flutter_ithome/app/views/quan_page.dart'; 4 | import 'package:flutter_ithome/app/views/user_page.dart'; 5 | import 'package:get/get.dart'; 6 | 7 | class IndexController extends GetxController { 8 | final index = 0.obs; 9 | final showContent = false.obs; 10 | final pages = [ 11 | const NewsPage(), 12 | const QuanPage(), 13 | UserPage(), 14 | ]; 15 | @override 16 | void onClose() {} 17 | 18 | void setIndex(i) { 19 | if (index.value == i) { 20 | EventBus.instance.emit(EventBus.kEventRefreshNews, 0); 21 | return; 22 | } 23 | index.value = i; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/app/common/log.dart: -------------------------------------------------------------------------------- 1 | import 'package:logger/logger.dart'; 2 | 3 | class Log { 4 | static Logger logger = Logger( 5 | printer: PrettyPrinter( 6 | methodCount: 0, 7 | errorMethodCount: 8, 8 | lineLength: 120, 9 | colors: true, 10 | printEmojis: true, 11 | printTime: false, 12 | ), 13 | ); 14 | 15 | static d(String message) { 16 | logger.d("${DateTime.now().toString()}\n$message"); 17 | } 18 | 19 | static i(String message) { 20 | logger.i("${DateTime.now().toString()}\n$message"); 21 | } 22 | 23 | static e(String message, StackTrace stackTrace) { 24 | logger.e("${DateTime.now().toString()}\n$message", null, stackTrace); 25 | } 26 | 27 | static w(String message) { 28 | logger.w("${DateTime.now().toString()}\n$message"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/app/service/app_settings_service.dart: -------------------------------------------------------------------------------- 1 | import 'package:get/get.dart'; 2 | import 'package:hive/hive.dart'; 3 | 4 | class AppSettingsService extends GetxService { 5 | static AppSettingsService get instance => Get.find(); 6 | 7 | /// 新闻-自定义的栏目 8 | static const String kNewsCategores = "NewsCategores"; 9 | static const String kDarkMode = "DarkMode"; 10 | static const String kThemeColor = "ThemeColor"; 11 | static const String kReadFontSize = "ReadFontSize"; 12 | 13 | late Box settingsBox; 14 | Future init() async { 15 | settingsBox = await Hive.openBox("Settings"); 16 | } 17 | 18 | T getValue(dynamic key, T defaultValue) { 19 | return settingsBox.get(key, defaultValue: defaultValue) as T; 20 | } 21 | 22 | Future setValue(dynamic key, T value) async { 23 | return await settingsBox.put(key, value); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/app/common/app_dialog.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:get/get.dart'; 3 | 4 | class AppDialog { 5 | /// 显示确定弹窗 6 | static Future showConfirmDialog( 7 | {required String title, required String content}) async { 8 | return (await Get.dialog( 9 | AlertDialog( 10 | title: Text(title), 11 | content: Text(content), 12 | actions: [ 13 | TextButton( 14 | onPressed: () { 15 | Get.back(result: false); 16 | }, 17 | child: const Text("取消"), 18 | ), 19 | TextButton( 20 | onPressed: () { 21 | Get.back(result: true); 22 | }, 23 | child: const Text("确定"), 24 | ), 25 | ], 26 | ), 27 | )) ?? 28 | false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/widget/adjustable_scroll_controller.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'dart:math'; 3 | import 'package:flutter/rendering.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | class AdjustableScrollController extends ScrollController { 7 | AdjustableScrollController([int extraScrollSpeed = 60]) { 8 | if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) { 9 | super.addListener(() { 10 | ScrollDirection scrollDirection = super.position.userScrollDirection; 11 | if (scrollDirection != ScrollDirection.idle) { 12 | double scrollEnd = super.offset + 13 | (scrollDirection == ScrollDirection.reverse 14 | ? extraScrollSpeed 15 | : -extraScrollSpeed); 16 | scrollEnd = min(super.position.maxScrollExtent, 17 | max(super.position.minScrollExtent, scrollEnd)); 18 | jumpTo(scrollEnd); 19 | } 20 | }); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_ithome 2 | version: 1.0.0+1 3 | publish_to: none 4 | description: A new Flutter project. 5 | environment: 6 | sdk: '>=2.17.0 <3.0.0' 7 | 8 | dependencies: 9 | cupertino_icons: ^1.0.2 10 | 11 | dio: ^4.0.6 12 | flutter_html: ^2.2.1 13 | logger: ^1.1.0 14 | url_launcher: ^6.1.2 15 | flutter_easyrefresh: ^2.2.1 16 | extended_image: ^6.2.0 17 | oktoast: ^3.2.0 18 | remixicon: ^1.0.0 19 | hive: ^2.2.1 20 | hive_flutter: ^1.1.0 21 | intl: 0.17.0 22 | carousel_slider: 4.1.1 23 | badges: ^2.0.3 24 | get: ^4.6.5 25 | share_plus: ^4.0.7 26 | dart_des: ^1.0.2 27 | flutter: 28 | sdk: flutter 29 | 30 | dev_dependencies: 31 | flutter_lints: ^2.0.0 32 | build_runner: ^2.1.11 33 | hive_generator: ^1.1.3 34 | flutter_test: 35 | sdk: flutter 36 | 37 | flutter: 38 | assets: 39 | - assets/icon/ 40 | - assets/logo/ 41 | - assets/status/ 42 | uses-material-design: true 43 | 44 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .packages 31 | .pub-cache/ 32 | .pub/ 33 | /build/ 34 | 35 | # Web related 36 | lib/generated_plugin_registrant.dart 37 | 38 | # Symbolication related 39 | app.*.symbols 40 | 41 | # Obfuscation related 42 | app.*.map.json 43 | 44 | # Android Studio will place build artifacts here 45 | /android/app/debug 46 | /android/app/profile 47 | /android/app/release 48 | 49 | android/key.properties -------------------------------------------------------------------------------- /lib/app/route/app_pages.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_ithome/app/controller/index_controller.dart'; 2 | import 'package:flutter_ithome/app/controller/news_controller.dart'; 3 | import 'package:flutter_ithome/app/route/route_path.dart'; 4 | import 'package:flutter_ithome/app/views/news/news_detail_page.dart'; 5 | import 'package:get/get.dart'; 6 | 7 | import '../views/index_page.dart'; 8 | 9 | class AppPages { 10 | AppPages._(); 11 | static const kIndex = RoutePath.kIndex; 12 | static final routes = [ 13 | GetPage( 14 | name: RoutePath.kIndex, 15 | page: () => IndexPage(), 16 | bindings: [ 17 | BindingsBuilder.put( 18 | () => IndexController(), 19 | ), 20 | BindingsBuilder.put( 21 | () => NewsController(), 22 | ), 23 | ], 24 | ), 25 | GetPage( 26 | name: RoutePath.kNewsDetail, 27 | page: () => NewsDetailPage( 28 | int.parse(Get.parameters["newsId"] ?? "0"), 29 | ), 30 | ), 31 | ]; 32 | } 33 | -------------------------------------------------------------------------------- /lib/widget/error.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class AppErrorWidget extends StatelessWidget { 4 | final String message; 5 | final Function()? onRefresh; 6 | const AppErrorWidget(this.message, {this.onRefresh, Key? key}) 7 | : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Center( 12 | child: Column( 13 | mainAxisSize: MainAxisSize.min, 14 | children: [ 15 | const Icon( 16 | Icons.warning, 17 | size: 48, 18 | ), 19 | const SizedBox( 20 | height: 12, 21 | ), 22 | Text( 23 | message, 24 | style: const TextStyle(color: Colors.grey), 25 | ), 26 | Visibility( 27 | visible: onRefresh != null, 28 | child: TextButton( 29 | onPressed: onRefresh, 30 | child: const Text("刷新"), 31 | ), 32 | ), 33 | ], 34 | ), 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flutter_ithome", 3 | "short_name": "flutter_ithome", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /lib/app/common/event_bus.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/foundation.dart'; 4 | 5 | /// 全局事件 6 | class EventBus { 7 | /// 刷新新闻事件 8 | static const String kEventRefreshNews = "RefreshNews"; 9 | 10 | /// 刷新新闻ITEM 11 | static const String kEventRefreshNewsItem = "RefreshNewsItem"; 12 | 13 | static EventBus? _instance; 14 | 15 | static EventBus get instance { 16 | _instance ??= EventBus(); 17 | return _instance!; 18 | } 19 | 20 | final Map _streams = {}; 21 | 22 | /// 触发事件 23 | void emit(String name, dynamic data) { 24 | if (!_streams.containsKey(name)) { 25 | _streams.addAll({name: StreamController.broadcast()}); 26 | } 27 | debugPrint("------------触发事件$name;参数:$data------------"); 28 | _streams[name]!.add(data); 29 | } 30 | 31 | /// 监听事件 32 | StreamSubscription listen(String name, Function(dynamic)? onData) { 33 | if (!_streams.containsKey(name)) { 34 | _streams.addAll({name: StreamController.broadcast()}); 35 | } 36 | return _streams[name]!.stream.listen(onData); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/app/common/app_navigator.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | import 'package:get/get.dart'; 4 | 5 | class AppNavigator { 6 | /// 当前内容路由的名称 7 | static String currentContentRouteName = "/"; 8 | static final GlobalKey? contentKey = Get.nestedKey(1); 9 | 10 | static BuildContext get contentBuildContext => contentKey!.currentContext!; 11 | 12 | static void toPage(String name, {dynamic arg}) { 13 | Get.toNamed(name, arguments: arg); 14 | } 15 | 16 | static void toContentPage(String name, {dynamic arg, bool replace = true}) { 17 | if (currentContentRouteName == name && replace) { 18 | Get.offAndToNamed(name, arguments: arg, id: 1); 19 | } else { 20 | Get.toNamed(name, arguments: arg, id: 1); 21 | } 22 | } 23 | 24 | static void closePage() { 25 | if (Navigator.canPop(Get.context!)) { 26 | Get.back(); 27 | } else { 28 | Get.back(id: 1); 29 | } 30 | } 31 | 32 | static void showBottomSheet(Widget widget) { 33 | showModalBottomSheet( 34 | context: contentKey!.currentContext!, 35 | builder: (context) => widget, 36 | routeSettings: const RouteSettings(name: "/modalBottomSheet"), 37 | ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/app/controller/news/news_category_controller.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'package:flutter_ithome/app/controller/base_controller.dart'; 3 | import 'package:flutter_ithome/model/news_banner_model.dart'; 4 | import 'package:flutter_ithome/model/news_item_model.dart'; 5 | import 'package:flutter_ithome/request/news_request.dart'; 6 | import 'package:get/get.dart'; 7 | 8 | class NewsCategoryController extends BasePageController { 9 | final String categoryId; 10 | NewsCategoryController(this.categoryId); 11 | 12 | final NewsRequest request = NewsRequest(); 13 | 14 | RxList topNews = [].obs; 15 | 16 | RxList banner = [].obs; 17 | 18 | StreamSubscription? streamSubscription; 19 | 20 | @override 21 | void onInit() { 22 | refreshData(); 23 | super.onInit(); 24 | } 25 | 26 | @override 27 | Future> getData(int page, int pageSize) async { 28 | var ot = ""; 29 | if (page != 1) { 30 | ot = list.last.orderdate.millisecondsSinceEpoch.toString(); 31 | return await request.getNewsMore(ot: ot, tag: categoryId); 32 | } else { 33 | return await request.getNews(tag: categoryId); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:flutter_ithome/app/common/log.dart'; 4 | import 'package:flutter_ithome/app/common/utils.dart'; 5 | import 'package:flutter_ithome/app/my_app.dart'; 6 | import 'package:flutter_ithome/app/service/app_settings_service.dart'; 7 | import 'package:flutter_ithome/app/service/app_storage_service.dart'; 8 | import 'package:flutter_ithome/storage/news_collect.dart'; 9 | import 'package:flutter_ithome/storage/news_history.dart'; 10 | import 'package:get/get.dart'; 11 | import 'package:hive_flutter/hive_flutter.dart'; 12 | 13 | void main() async { 14 | WidgetsFlutterBinding.ensureInitialized(); 15 | 16 | Hive.registerAdapter(NewsHistoryAdapter()); 17 | Hive.registerAdapter(NewsCollectAdapter()); 18 | await Hive.initFlutter(); 19 | //初始化服务 20 | await initServices(); 21 | //设置状态栏为透明 22 | SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle( 23 | statusBarColor: Colors.transparent, 24 | statusBarIconBrightness: Brightness.dark, 25 | ); 26 | SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle); 27 | runApp(MyApp()); 28 | } 29 | 30 | Future initServices() async { 31 | await Get.put(AppSettingsService()).init(); 32 | await Get.put(AppStorageService()).init(); 33 | } 34 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/widget/empty.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/common/app_style.dart'; 3 | import 'package:remixicon/remixicon.dart'; 4 | 5 | class EmptyWidget extends StatelessWidget { 6 | final bool showRefresh; 7 | final String? text; 8 | final Function()? onRefresh; 9 | 10 | const EmptyWidget({ 11 | Key? key, 12 | this.text, 13 | this.showRefresh = true, 14 | this.onRefresh, 15 | }) : super(key: key); 16 | 17 | @override 18 | Widget build(BuildContext context) { 19 | return Center( 20 | child: Column( 21 | mainAxisAlignment: MainAxisAlignment.center, 22 | crossAxisAlignment: CrossAxisAlignment.center, 23 | children: [ 24 | Image.asset( 25 | 'assets/status/empty.png', 26 | width: 200, 27 | ), 28 | AppStyle.vGap12, 29 | Text( 30 | text ?? "这里什么都没有", 31 | style: const TextStyle(color: Colors.grey, fontSize: 14), 32 | ), 33 | AppStyle.vGap12, 34 | Visibility( 35 | visible: showRefresh && onRefresh != null, 36 | child: TextButton.icon( 37 | onPressed: onRefresh, 38 | icon: const Icon(Icons.refresh), 39 | label: const Text("刷新"), 40 | ), 41 | ), 42 | ], 43 | ), 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/model/ff_convert.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:developer'; 3 | 4 | void tryCatch(Function? f) { 5 | try { 6 | f?.call(); 7 | } catch (e, stack) { 8 | log('$e'); 9 | log('$stack'); 10 | } 11 | } 12 | 13 | class FFConvert { 14 | FFConvert._(); 15 | // ignore: prefer_function_declarations_over_variables 16 | static T? Function(dynamic value) convert = 17 | (dynamic value) { 18 | if (value == null) { 19 | return null; 20 | } 21 | return json.decode(value.toString()) as T?; 22 | }; 23 | } 24 | 25 | T? asT(dynamic value, [T? defaultValue]) { 26 | if (value is T) { 27 | return value; 28 | } 29 | try { 30 | if (value != null) { 31 | final String valueS = value.toString(); 32 | if ('' is T) { 33 | return valueS as T; 34 | } else if (0 is T) { 35 | return int.parse(valueS) as T; 36 | } else if (0.0 is T) { 37 | return double.parse(valueS) as T; 38 | } else if (false is T) { 39 | if (valueS == '0' || valueS == '1') { 40 | return (valueS == '1') as T; 41 | } 42 | return (valueS == 'true') as T; 43 | } else { 44 | return FFConvert.convert(value); 45 | } 46 | } 47 | } catch (e, stackTrace) { 48 | log('asT<$T>', error: e, stackTrace: stackTrace); 49 | return defaultValue; 50 | } 51 | 52 | return defaultValue; 53 | } 54 | -------------------------------------------------------------------------------- /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"flutter_ithome", 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 | -------------------------------------------------------------------------------- /lib/model/news_banner_model.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'ff_convert.dart'; 4 | 5 | class NewsBannerModel { 6 | NewsBannerModel({ 7 | required this.title, 8 | required this.starttime, 9 | required this.endtime, 10 | required this.link, 11 | required this.opentype, 12 | required this.device, 13 | required this.isad, 14 | required this.image, 15 | }); 16 | 17 | factory NewsBannerModel.fromJson(Map json) => 18 | NewsBannerModel( 19 | title: asT(json['title'])!, 20 | starttime: asT(json['starttime'])!, 21 | endtime: asT(json['endtime'])!, 22 | link: asT(json['link'])!, 23 | opentype: asT(json['opentype'])!, 24 | device: asT(json['device'])!, 25 | isad: asT(json['isad'])!, 26 | image: asT(json['image'])!, 27 | ); 28 | 29 | String title; 30 | String starttime; 31 | String endtime; 32 | String link; 33 | int opentype; 34 | String device; 35 | bool isad; 36 | String image; 37 | 38 | @override 39 | String toString() { 40 | return jsonEncode(this); 41 | } 42 | 43 | Map toJson() => { 44 | 'title': title, 45 | 'starttime': starttime, 46 | 'endtime': endtime, 47 | 'link': link, 48 | 'opentype': opentype, 49 | 'device': device, 50 | 'isad': isad, 51 | 'image': image, 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/app/my_app.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_ithome/app/controller/app_settings_controller.dart'; 5 | import 'package:flutter_ithome/app/route/app_pages.dart'; 6 | import 'package:get/get.dart'; 7 | import 'package:oktoast/oktoast.dart'; 8 | 9 | class MyApp extends StatelessWidget { 10 | MyApp({Key? key}) : super(key: key); 11 | final AppSettingsController controller = Get.put(AppSettingsController()); 12 | @override 13 | Widget build(BuildContext context) { 14 | return OKToast( 15 | child: GetMaterialApp( 16 | title: 'IT之家', 17 | theme: ThemeData( 18 | primarySwatch: Colors.red, 19 | fontFamily: Platform.isWindows ? "微软雅黑" : null, 20 | ), 21 | darkTheme: ThemeData( 22 | colorScheme: ColorScheme.fromSwatch( 23 | primarySwatch: Colors.red, 24 | accentColor: Colors.red, 25 | brightness: Brightness.dark, 26 | ), 27 | toggleableActiveColor: Colors.red, 28 | brightness: Brightness.dark, 29 | fontFamily: Platform.isWindows ? "微软雅黑" : null, 30 | ), 31 | themeMode: controller.darkMode.value ? ThemeMode.dark : ThemeMode.light, 32 | debugShowCheckedModeBanner: false, 33 | builder: (BuildContext context, Widget? widget) { 34 | return OKToast(child: widget!); 35 | }, 36 | initialRoute: AppPages.kIndex, 37 | getPages: AppPages.routes, 38 | ), 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /lib/storage/news_collect.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'news_collect.dart'; 4 | 5 | // ************************************************************************** 6 | // TypeAdapterGenerator 7 | // ************************************************************************** 8 | 9 | class NewsCollectAdapter extends TypeAdapter { 10 | @override 11 | final int typeId = 1; 12 | 13 | @override 14 | NewsCollect read(BinaryReader reader) { 15 | final numOfFields = reader.readByte(); 16 | final fields = { 17 | for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), 18 | }; 19 | return NewsCollect() 20 | ..id = fields[0] as int? 21 | ..image = fields[1] as String? 22 | ..title = fields[2] as String? 23 | ..url = fields[3] as String? 24 | ..addDate = fields[4] as DateTime?; 25 | } 26 | 27 | @override 28 | void write(BinaryWriter writer, NewsCollect obj) { 29 | writer 30 | ..writeByte(5) 31 | ..writeByte(0) 32 | ..write(obj.id) 33 | ..writeByte(1) 34 | ..write(obj.image) 35 | ..writeByte(2) 36 | ..write(obj.title) 37 | ..writeByte(3) 38 | ..write(obj.url) 39 | ..writeByte(4) 40 | ..write(obj.addDate); 41 | } 42 | 43 | @override 44 | int get hashCode => typeId.hashCode; 45 | 46 | @override 47 | bool operator ==(Object other) => 48 | identical(this, other) || 49 | other is NewsCollectAdapter && 50 | runtimeType == other.runtimeType && 51 | typeId == other.typeId; 52 | } 53 | -------------------------------------------------------------------------------- /lib/storage/news_history.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'news_history.dart'; 4 | 5 | // ************************************************************************** 6 | // TypeAdapterGenerator 7 | // ************************************************************************** 8 | 9 | class NewsHistoryAdapter extends TypeAdapter { 10 | @override 11 | final int typeId = 2; 12 | 13 | @override 14 | NewsHistory read(BinaryReader reader) { 15 | final numOfFields = reader.readByte(); 16 | final fields = { 17 | for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), 18 | }; 19 | return NewsHistory() 20 | ..id = fields[0] as int? 21 | ..image = fields[1] as String? 22 | ..title = fields[2] as String? 23 | ..url = fields[3] as String? 24 | ..addDate = fields[4] as DateTime?; 25 | } 26 | 27 | @override 28 | void write(BinaryWriter writer, NewsHistory obj) { 29 | writer 30 | ..writeByte(5) 31 | ..writeByte(0) 32 | ..write(obj.id) 33 | ..writeByte(1) 34 | ..write(obj.image) 35 | ..writeByte(2) 36 | ..write(obj.title) 37 | ..writeByte(3) 38 | ..write(obj.url) 39 | ..writeByte(4) 40 | ..write(obj.addDate); 41 | } 42 | 43 | @override 44 | int get hashCode => typeId.hashCode; 45 | 46 | @override 47 | bool operator ==(Object other) => 48 | identical(this, other) || 49 | other is NewsHistoryAdapter && 50 | runtimeType == other.runtimeType && 51 | typeId == other.typeId; 52 | } 53 | -------------------------------------------------------------------------------- /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/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - FlutterMacOS (1.0.0) 3 | - path_provider_macos (0.0.1): 4 | - FlutterMacOS 5 | - share_plus_macos (0.0.1): 6 | - FlutterMacOS 7 | - url_launcher_macos (0.0.1): 8 | - FlutterMacOS 9 | - wakelock_macos (0.0.1): 10 | - FlutterMacOS 11 | 12 | DEPENDENCIES: 13 | - FlutterMacOS (from `Flutter/ephemeral`) 14 | - path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`) 15 | - share_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos`) 16 | - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) 17 | - wakelock_macos (from `Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macos`) 18 | 19 | EXTERNAL SOURCES: 20 | FlutterMacOS: 21 | :path: Flutter/ephemeral 22 | path_provider_macos: 23 | :path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos 24 | share_plus_macos: 25 | :path: Flutter/ephemeral/.symlinks/plugins/share_plus_macos/macos 26 | url_launcher_macos: 27 | :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos 28 | wakelock_macos: 29 | :path: Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macos 30 | 31 | SPEC CHECKSUMS: 32 | FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 33 | path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19 34 | share_plus_macos: 853ee48e7dce06b633998ca0735d482dd671ade4 35 | url_launcher_macos: 597e05b8e514239626bcf4a850fcf9ef5c856ec3 36 | wakelock_macos: bc3f2a9bd8d2e6c89fee1e1822e7ddac3bd004a9 37 | 38 | PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c 39 | 40 | COCOAPODS: 1.11.2 41 | -------------------------------------------------------------------------------- /lib/widget/net_image.dart: -------------------------------------------------------------------------------- 1 | import 'package:extended_image/extended_image.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class NetImage extends StatelessWidget { 5 | final String picUrl; 6 | final double? width; 7 | final double? height; 8 | final BoxFit? fit; 9 | final double borderRadius; 10 | final double elevation; 11 | const NetImage(this.picUrl, 12 | {this.width, 13 | this.height, 14 | this.fit = BoxFit.cover, 15 | this.borderRadius = 8, 16 | this.elevation = 0, 17 | Key? key}) 18 | : super(key: key); 19 | 20 | @override 21 | Widget build(BuildContext context) { 22 | return Card( 23 | margin: EdgeInsets.zero, 24 | elevation: elevation, 25 | shape: RoundedRectangleBorder( 26 | borderRadius: BorderRadius.circular(borderRadius), 27 | ), 28 | child: ExtendedImage.network( 29 | picUrl, 30 | fit: fit, 31 | height: height, 32 | width: width, 33 | shape: BoxShape.rectangle, 34 | borderRadius: BorderRadius.circular(borderRadius), 35 | loadStateChanged: (e) { 36 | if (e.extendedImageLoadState == LoadState.loading) { 37 | return const Icon( 38 | Icons.image, 39 | color: Colors.grey, 40 | size: 24, 41 | ); 42 | } 43 | if (e.extendedImageLoadState == LoadState.failed) { 44 | return const Icon( 45 | Icons.broken_image, 46 | color: Colors.grey, 47 | size: 24, 48 | ); 49 | } 50 | return null; 51 | }, 52 | ), 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.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: ee4e09cce01d6f2d7f4baebd247fde02e5008851 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: ee4e09cce01d6f2d7f4baebd247fde02e5008851 17 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 18 | - platform: android 19 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 20 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 21 | - platform: ios 22 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 23 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 24 | - platform: linux 25 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 26 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 27 | - platform: macos 28 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 29 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 30 | - platform: web 31 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 32 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 33 | - platform: windows 34 | create_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 35 | base_revision: ee4e09cce01d6f2d7f4baebd247fde02e5008851 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 | -------------------------------------------------------------------------------- /ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CADisableMinimumFrameDurationOnPhone 6 | 7 | CFBundleDevelopmentRegion 8 | $(DEVELOPMENT_LANGUAGE) 9 | CFBundleDisplayName 10 | IT之家 11 | CFBundleExecutable 12 | $(EXECUTABLE_NAME) 13 | CFBundleIdentifier 14 | $(PRODUCT_BUNDLE_IDENTIFIER) 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | flutter_ithome 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | $(FLUTTER_BUILD_NAME) 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | $(FLUTTER_BUILD_NUMBER) 27 | LSRequiresIPhoneOS 28 | 29 | UILaunchStoryboardName 30 | LaunchScreen 31 | UIMainStoryboardFile 32 | Main 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | UIViewControllerBasedStatusBarAppearance 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 17 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | - path_provider_ios (0.0.1): 4 | - Flutter 5 | - share_plus (0.0.1): 6 | - Flutter 7 | - url_launcher_ios (0.0.1): 8 | - Flutter 9 | - video_player_avfoundation (0.0.1): 10 | - Flutter 11 | - wakelock (0.0.1): 12 | - Flutter 13 | - webview_flutter_wkwebview (0.0.1): 14 | - Flutter 15 | 16 | DEPENDENCIES: 17 | - Flutter (from `Flutter`) 18 | - path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`) 19 | - share_plus (from `.symlinks/plugins/share_plus/ios`) 20 | - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) 21 | - video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/ios`) 22 | - wakelock (from `.symlinks/plugins/wakelock/ios`) 23 | - webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`) 24 | 25 | EXTERNAL SOURCES: 26 | Flutter: 27 | :path: Flutter 28 | path_provider_ios: 29 | :path: ".symlinks/plugins/path_provider_ios/ios" 30 | share_plus: 31 | :path: ".symlinks/plugins/share_plus/ios" 32 | url_launcher_ios: 33 | :path: ".symlinks/plugins/url_launcher_ios/ios" 34 | video_player_avfoundation: 35 | :path: ".symlinks/plugins/video_player_avfoundation/ios" 36 | wakelock: 37 | :path: ".symlinks/plugins/wakelock/ios" 38 | webview_flutter_wkwebview: 39 | :path: ".symlinks/plugins/webview_flutter_wkwebview/ios" 40 | 41 | SPEC CHECKSUMS: 42 | Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a 43 | path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02 44 | share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68 45 | url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de 46 | video_player_avfoundation: e489aac24ef5cf7af82702979ed16f2a5ef84cff 47 | wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f 48 | webview_flutter_wkwebview: b7e70ef1ddded7e69c796c7390ee74180182971f 49 | 50 | PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c 51 | 52 | COCOAPODS: 1.11.2 53 | -------------------------------------------------------------------------------- /lib/widget/controller_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/common/log.dart'; 3 | import 'package:flutter_ithome/app/controller/base_controller.dart'; 4 | import 'package:flutter_ithome/widget/empty.dart'; 5 | import 'package:flutter_ithome/widget/error.dart'; 6 | import 'package:flutter_ithome/widget/loadding.dart'; 7 | import 'package:get/get.dart'; 8 | 9 | typedef ControllerWidgetBuilder = Widget Function(T controller); 10 | 11 | class ControllerWidget extends StatelessWidget { 12 | /// 自定义组件 Builder 13 | final ControllerWidgetBuilder builder; 14 | 15 | /// 控制器,该控制器必须继承自BaseController 16 | final BaseController controller; 17 | 18 | /// 请求刷新事件 19 | final Function(T e)? onRefresh; 20 | 21 | final String? tag; 22 | 23 | const ControllerWidget(this.controller, 24 | {required this.builder, this.onRefresh, this.tag, Key? key}) 25 | : super(key: key); 26 | 27 | @override 28 | Widget build(BuildContext context) { 29 | return GetX( 30 | init: controller, 31 | tag: tag, 32 | global: false, 33 | initState: (e) { 34 | (e.controller as BaseController).onShow(); 35 | }, 36 | builder: (e) { 37 | e = e as BaseController; 38 | // 页面错误 39 | if (e.pageError.value) { 40 | return AppErrorWidget( 41 | e.errorMsg.value, 42 | onRefresh: () => onRefresh?.call(e as T), 43 | ); 44 | } 45 | // 页面内容为空 46 | if (!e.pageError.value && e.pageEmpty.value) { 47 | return EmptyWidget( 48 | onRefresh: () => onRefresh?.call(e as T), 49 | ); 50 | } 51 | return Stack( 52 | children: [ 53 | builder(controller as T), 54 | //页面加载中 55 | Visibility( 56 | visible: e.pageLoadding.value, 57 | child: const LoaddingWidget(), 58 | ), 59 | ], 60 | ); 61 | }, 62 | ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | flutter_ithome 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /lib/app/service/app_storage_service.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_ithome/storage/news_collect.dart'; 2 | import 'package:flutter_ithome/storage/news_history.dart'; 3 | import 'package:get/get.dart'; 4 | import 'package:hive/hive.dart'; 5 | 6 | class AppStorageService extends GetxService { 7 | static AppStorageService get instance => Get.find(); 8 | 9 | late Box newsHistoryBox; 10 | late Box newsCollectBox; 11 | 12 | Future init() async { 13 | newsHistoryBox = await Hive.openBox("NewsHistory"); 14 | newsCollectBox = await Hive.openBox("NewsCollect"); 15 | } 16 | 17 | bool existNewsHistory(int newsId) { 18 | return newsHistoryBox.containsKey(newsId); 19 | } 20 | 21 | bool existNewsCollect(int newsId) { 22 | return newsCollectBox.containsKey(newsId); 23 | } 24 | 25 | void insertNewsHistory(int newsId, 26 | {required String url, required String title, required String image}) { 27 | if (existNewsHistory(newsId)) { 28 | //已存在记录,更新日期 29 | var value = newsHistoryBox.get(newsId); 30 | value!.addDate = DateTime.now(); 31 | newsHistoryBox.put(newsId, value); 32 | } else { 33 | var value = NewsHistory(); 34 | value.id = newsId; 35 | value.url = url; 36 | value.title = title; 37 | value.image = image; 38 | value.addDate = DateTime.now(); 39 | newsHistoryBox.put(newsId, value); 40 | } 41 | } 42 | 43 | void insertNewsCollect(int newsId, 44 | {required String url, required String title, required String image}) { 45 | if (existNewsCollect(newsId)) { 46 | //已存在记录,更新日期 47 | var value = newsCollectBox.get(newsId); 48 | value!.addDate = DateTime.now(); 49 | newsCollectBox.put(newsId, value); 50 | } else { 51 | var value = NewsCollect(); 52 | value.id = newsId; 53 | value.url = url; 54 | value.title = title; 55 | value.image = image; 56 | value.addDate = DateTime.now(); 57 | newsCollectBox.put(newsId, value); 58 | } 59 | } 60 | 61 | void deleteNewsHistory(int newsId) { 62 | newsHistoryBox.delete(newsId); 63 | } 64 | 65 | void deleteNewsCollect(int newsId) { 66 | newsCollectBox.delete(newsId); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/app/controller/news/news_new_controller.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter_ithome/app/common/event_bus.dart'; 4 | import 'package:flutter_ithome/app/controller/base_controller.dart'; 5 | import 'package:flutter_ithome/model/news_banner_model.dart'; 6 | import 'package:flutter_ithome/model/news_item_model.dart'; 7 | import 'package:flutter_ithome/request/news_request.dart'; 8 | import 'package:get/get.dart'; 9 | 10 | class NewsNewController extends BasePageController { 11 | final NewsRequest request = NewsRequest(); 12 | 13 | RxList topNews = [].obs; 14 | 15 | RxList banner = [].obs; 16 | 17 | StreamSubscription? streamSubscription; 18 | 19 | StreamSubscription? refreshNewsItemStreamSubscription; 20 | 21 | @override 22 | void onInit() { 23 | streamSubscription = 24 | EventBus.instance.listen(EventBus.kEventRefreshNews, (e) { 25 | refreshData(); 26 | }); 27 | refreshNewsItemStreamSubscription = 28 | EventBus.instance.listen(EventBus.kEventRefreshNewsItem, (e) { 29 | update(); 30 | }); 31 | refreshData(); 32 | super.onInit(); 33 | } 34 | 35 | @override 36 | void dispose() { 37 | streamSubscription?.cancel(); 38 | refreshNewsItemStreamSubscription?.cancel(); 39 | super.dispose(); 40 | } 41 | 42 | @override 43 | Future refreshData() { 44 | loadBannerAndTopNews(); 45 | 46 | return super.refreshData(); 47 | } 48 | 49 | void loadBannerAndTopNews() async { 50 | banner.value = await request.getBanner(); 51 | topNews.value = await request.getTopNews(); 52 | update(); 53 | } 54 | 55 | @override 56 | Future> getData(int page, int pageSize) async { 57 | var ot = ""; 58 | if (page != 1) { 59 | ot = list.last.orderdate.millisecondsSinceEpoch.toString(); 60 | return await request.getNewsMore( 61 | ot: ot, 62 | ); 63 | } else { 64 | return await request.getNews(); 65 | } 66 | } 67 | 68 | //https://api.ithome.com/json/slide/index 69 | //https://api.ithome.com/json/newslist/news 70 | //https://api.ithome.com/json/listpage/news/F128C9CBE944FE0BB09282B01FAC69E3 71 | } 72 | -------------------------------------------------------------------------------- /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 flutter.compileSdkVersion 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "com.example.flutter_ithome" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. 50 | minSdkVersion 19 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /lib/app/views/news/news_category_view.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_easyrefresh/easy_refresh.dart'; 3 | import 'package:flutter_ithome/app/common/app_style.dart'; 4 | import 'package:flutter_ithome/app/controller/news/news_category_controller.dart'; 5 | import 'package:flutter_ithome/widget/adjustable_scroll_controller.dart'; 6 | import 'package:flutter_ithome/widget/empty.dart'; 7 | import 'package:flutter_ithome/widget/error.dart'; 8 | import 'package:flutter_ithome/widget/keep_alive_wrapper.dart'; 9 | import 'package:flutter_ithome/widget/loadding.dart'; 10 | import 'package:flutter_ithome/widget/news_item.dart'; 11 | import 'package:get/get.dart'; 12 | 13 | class NewsCategoryView extends StatelessWidget { 14 | final String categoryId; 15 | const NewsCategoryView(this.categoryId, {Key? key}) : super(key: key); 16 | @override 17 | Widget build(BuildContext context) { 18 | return KeepAliveWrapper( 19 | child: GetX( 20 | init: NewsCategoryController(categoryId), 21 | tag: categoryId, 22 | builder: ((c) { 23 | // 页面错误 24 | if (c.pageError.value) { 25 | return AppErrorWidget( 26 | c.errorMsg.value, 27 | onRefresh: () => c.refreshData(), 28 | ); 29 | } 30 | // 页面内容为空 31 | if (!c.pageError.value && c.pageEmpty.value) { 32 | return EmptyWidget( 33 | onRefresh: () => c.refreshData(), 34 | ); 35 | } 36 | return Stack( 37 | children: [ 38 | EasyRefresh( 39 | onLoad: c.loadData, 40 | onRefresh: c.refreshData, 41 | header: BallPulseHeader(), 42 | footer: BallPulseFooter(), 43 | child: ListView.builder( 44 | padding: AppStyle.edgeInsetsV8, 45 | itemCount: c.list.length, 46 | controller: AdjustableScrollController(), 47 | itemBuilder: (_, i) { 48 | var item = c.list[i]; 49 | return NewsItemWidget(item); 50 | }, 51 | ), 52 | ), 53 | //页面加载中 54 | Visibility( 55 | visible: c.pageLoadding.value, 56 | child: const LoaddingWidget(), 57 | ), 58 | ], 59 | ); 60 | }), 61 | ), 62 | ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /lib/app/controller/base_controller.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_ithome/app/common/log.dart'; 2 | import 'package:get/get.dart'; 3 | import 'package:oktoast/oktoast.dart'; 4 | 5 | class BaseController extends GetxController { 6 | /// 加载中,更新页面 7 | var pageLoadding = false.obs; 8 | 9 | /// 加载中,不会更新页面 10 | var loadding = false; 11 | 12 | /// 空白页面 13 | var pageEmpty = false.obs; 14 | 15 | /// 页面错误 16 | var pageError = false.obs; 17 | 18 | /// 错误信息 19 | var errorMsg = "".obs; 20 | 21 | /// 显示错误 22 | /// * [msg] 错误信息 23 | /// * [showPageError] 显示页面错误 24 | /// * 只在第一页加载错误时showPageError=true,后续页加载错误时使用Toast弹出通知 25 | void showError(String msg, {bool showPageError = false}) { 26 | Log.e(msg, StackTrace.current); 27 | if (showPageError) { 28 | pageError.value = true; 29 | errorMsg.value = msg; 30 | } else { 31 | showToast(msg); 32 | } 33 | } 34 | 35 | /// 当页面显示 36 | void onShow() { 37 | Log.i("显示${toString()}"); 38 | } 39 | 40 | String exceptionToString(Object exception) { 41 | return exception.toString().replaceAll("Exception:", ""); 42 | } 43 | } 44 | 45 | class BasePageController extends BaseController { 46 | int currentPage = 1; 47 | int count = 0; 48 | int maxPage = 0; 49 | int pageSize = 24; 50 | var canLoadMore = false.obs; 51 | var list = [].obs; 52 | 53 | Future refreshData() async { 54 | currentPage = 1; 55 | list.value = []; 56 | await loadData(); 57 | } 58 | 59 | Future loadData() async { 60 | try { 61 | if (loadding) return; 62 | loadding = true; 63 | pageLoadding.value = currentPage == 1; 64 | update(); 65 | var result = await getData(currentPage, pageSize); 66 | //是否可以加载更多 67 | if (result.isNotEmpty) { 68 | currentPage++; 69 | canLoadMore.value = true; 70 | pageEmpty.value = false; 71 | } else { 72 | canLoadMore.value = false; 73 | if (currentPage == 1) { 74 | pageEmpty.value = true; 75 | } 76 | } 77 | // 赋值数据 78 | if (currentPage == 1) { 79 | list.value = result; 80 | } else { 81 | list.addAll(result); 82 | } 83 | } catch (e) { 84 | showError(exceptionToString(e), showPageError: currentPage == 1); 85 | } finally { 86 | loadding = false; 87 | pageLoadding.value = false; 88 | update(); 89 | } 90 | } 91 | 92 | Future> getData(int page, int pageSize) async { 93 | return []; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/request/http_client.dart: -------------------------------------------------------------------------------- 1 | import 'package:dio/dio.dart'; 2 | import 'package:flutter_ithome/app/common/log.dart'; 3 | 4 | class HttpClient { 5 | static HttpClient? _httpUtil; 6 | 7 | static HttpClient get instance { 8 | _httpUtil ??= HttpClient(); 9 | return _httpUtil!; 10 | } 11 | 12 | late Dio dio; 13 | HttpClient() { 14 | dio = Dio( 15 | BaseOptions(), 16 | ); 17 | dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) { 18 | Log.i( 19 | "【发起HTTP请求】\nMethod:${options.method}\nURL:${options.uri}\nQuery:${options.queryParameters}\nData:${options.data}\nHeaders:\n${options.headers}", 20 | ); 21 | options.extra["ts"] = DateTime.now().millisecondsSinceEpoch; 22 | return handler.next(options); 23 | }, onResponse: (response, handler) { 24 | var time = DateTime.now().millisecondsSinceEpoch - 25 | response.requestOptions.extra["ts"]; 26 | Log.i( 27 | '''【HTTP请求响应】 耗时:${time}ms 28 | Request Method:${response.requestOptions.method} 29 | Request Code:${response.statusCode} 30 | Request URL:${response.requestOptions.uri} 31 | Request Query:${response.requestOptions.queryParameters} 32 | Request Data:${response.requestOptions.data} 33 | Request Headers:${response.requestOptions.headers} 34 | Response Headers:${response.headers.map} 35 | Response Data:${response.data}''', 36 | ); 37 | return handler.next(response); 38 | }, onError: (DioError e, handler) { 39 | var time = 40 | DateTime.now().millisecondsSinceEpoch - e.requestOptions.extra["ts"]; 41 | Log.e('''【HTTP请求错误】 耗时:${time}ms 42 | Request Method:${e.requestOptions.method} 43 | Request Code:${e.response?.statusCode} 44 | Request URL:${e.requestOptions.uri} 45 | Request Query:${e.requestOptions.queryParameters} 46 | Request Data:${e.requestOptions.data} 47 | Request Headers:${e.requestOptions.headers} 48 | Response Headers:${e.response?.headers.map} 49 | Response Data:${e.response?.data}''', e.stackTrace ?? StackTrace.current); 50 | 51 | return handler.next(e); 52 | })); 53 | } 54 | 55 | /// Get请求,返回Map 56 | /// * [url] 请求链接 57 | /// * [queryParameters] 请求参数 58 | /// * [cancel] 任务取消Token 59 | Future getJson( 60 | String path, { 61 | Map? queryParameters, 62 | String baseUrl = "", 63 | CancelToken? cancel, 64 | }) async { 65 | Map header = {}; 66 | queryParameters ??= {}; 67 | var result = await dio.get( 68 | baseUrl + path, 69 | queryParameters: queryParameters, 70 | options: Options( 71 | responseType: ResponseType.json, 72 | headers: header, 73 | ), 74 | cancelToken: cancel, 75 | ); 76 | 77 | return result.data; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /lib/app/common/utils.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dart_des/dart_des.dart'; 4 | import 'package:flutter_ithome/app/common/app_navigator.dart'; 5 | import 'package:flutter_ithome/app/route/route_path.dart'; 6 | import 'package:get/get.dart'; 7 | import 'package:intl/intl.dart'; 8 | import 'package:url_launcher/url_launcher.dart'; 9 | 10 | class Utils { 11 | static DateFormat dateFormat = DateFormat("MM-dd HH:mm"); 12 | static DateFormat dateFormatWithYear = DateFormat("yyyy-MM-dd HH:mm"); 13 | 14 | /// 处理时间 15 | static String handleTime(DateTime? dt) { 16 | if (dt == null) { 17 | return ""; 18 | } 19 | 20 | var dtNow = DateTime.now(); 21 | if (dt.year == dtNow.year && 22 | dt.month == dtNow.month && 23 | dt.day == dtNow.day) { 24 | return "${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}"; 25 | } 26 | if (dt.year == dtNow.year && 27 | dt.month == dtNow.month && 28 | dt.day == dtNow.day - 1) { 29 | return "昨日 ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}"; 30 | } 31 | 32 | if (dt.year == dtNow.year) { 33 | return dateFormat.format(dt); 34 | } 35 | 36 | return dateFormatWithYear.format(dt); 37 | } 38 | 39 | /// 处理链接 40 | static void handleUrl(String url) async { 41 | if (url.isEmpty) return; 42 | var uri = Uri.parse(url); 43 | if (uri.host == 'www.ithome.com' && uri.path.contains('/0/')) { 44 | var newsId = int.tryParse( 45 | uri.path 46 | .replaceAll('/0/', '') 47 | .replaceAll('/', '') 48 | .replaceAll('.htm', ''), 49 | ) ?? 50 | 0; 51 | AppNavigator.toContentPage(RoutePath.kNewsDetail, arg: newsId); 52 | 53 | return; 54 | } 55 | 56 | launchUrl(uri, mode: LaunchMode.externalApplication); 57 | } 58 | 59 | // ignore: constant_identifier_names 60 | static const String ENCRYPTION_KEY = '(#i@x*l%'; 61 | static String getCommentSn(String newsId) { 62 | DES desECB = DES(key: ENCRYPTION_KEY.codeUnits, mode: DESMode.ECB); 63 | 64 | var length = newsId.length; 65 | var times = 8 - length; 66 | if (length >= 8) { 67 | length %= 8; 68 | if (length == 0) { 69 | times = 0; 70 | } 71 | } 72 | var sb = StringBuffer(newsId); 73 | for (var i = 0; i < times; i++) { 74 | sb.write(String.fromCharCode(0)); 75 | } 76 | var encrypted = desECB.encrypt(sb.toString().codeUnits); 77 | 78 | var sb2 = StringBuffer(); 79 | for (var element in encrypted) { 80 | var hexString = element.toRadixString(16); 81 | if (hexString.length == 1) { 82 | sb2.write("0"); 83 | } 84 | sb2.write(hexString); 85 | } 86 | 87 | return sb2.toString().substring(0, 16).toUpperCase(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /lib/model/news_item_model.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_ithome/app/service/app_settings_service.dart'; 2 | import 'package:flutter_ithome/app/service/app_storage_service.dart'; 3 | 4 | import 'ff_convert.dart'; 5 | 6 | class NewsItemModel { 7 | final String title; 8 | final int newsid; 9 | final DateTime orderdate; 10 | final DateTime postdate; 11 | final String image; 12 | final List? images; 13 | final bool isAd; 14 | final bool isVideo; 15 | final int cid; 16 | final int commentcount; 17 | NewsItemModel({ 18 | required this.newsid, 19 | required this.cid, 20 | required this.title, 21 | required this.orderdate, 22 | required this.postdate, 23 | required this.image, 24 | this.images, 25 | this.isAd = false, 26 | this.isVideo = false, 27 | this.commentcount = 0, 28 | }); 29 | 30 | /// 处理https://api.ithome.com/json/newslist/news 31 | factory NewsItemModel.fromJson(Map jsonRes) { 32 | final List? imagelist = 33 | jsonRes['imagelist'] is List ? [] : null; 34 | if (imagelist != null) { 35 | for (final dynamic item in jsonRes['imagelist']!) { 36 | if (item != null) { 37 | tryCatch(() { 38 | imagelist.add(asT(item)!); 39 | }); 40 | } 41 | } 42 | } 43 | 44 | return NewsItemModel( 45 | newsid: asT(jsonRes['newsid'])!, 46 | cid: asT(jsonRes['cid']) ?? 0, 47 | image: asT(jsonRes['image'])!, 48 | title: asT(jsonRes['title'])!, 49 | commentcount: asT(jsonRes['commentcount']) ?? 0, 50 | orderdate: DateTime.parse(jsonRes['orderdate']), 51 | postdate: DateTime.parse(jsonRes['postdate']), 52 | images: imagelist, 53 | isAd: jsonRes.containsKey("aid"), 54 | isVideo: jsonRes.containsKey("v"), 55 | ); 56 | } 57 | 58 | /// 处理https://m.ithome.com/api/news/newslistpageget 59 | factory NewsItemModel.fromMJson(Map jsonRes) { 60 | final List? imagelist = 61 | jsonRes['imagelist'] is List ? [] : null; 62 | if (imagelist != null) { 63 | for (final dynamic item in jsonRes['imagelist']!) { 64 | if (item != null) { 65 | tryCatch(() { 66 | imagelist.add(asT(item)!); 67 | }); 68 | } 69 | } 70 | } 71 | 72 | return NewsItemModel( 73 | newsid: asT(jsonRes['newsid'])!, 74 | cid: asT(jsonRes['cid']) ?? 0, 75 | image: asT(jsonRes['image'])!, 76 | title: asT(jsonRes['title'])!, 77 | commentcount: asT(jsonRes['commentcount']) ?? 0, 78 | orderdate: DateTime.parse(jsonRes['orderdate']), 79 | postdate: DateTime.parse(jsonRes['postdate']), 80 | images: imagelist, 81 | isAd: asT(jsonRes['NewsTips'])!.contains("广告"), 82 | isVideo: asT(jsonRes['NewsTips'])!.contains("视频"), 83 | ); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /lib/app/common/app_style.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:get/get.dart'; 3 | 4 | class AppStyle { 5 | static const vGap4 = SizedBox( 6 | height: 4, 7 | ); 8 | static const vGap8 = SizedBox( 9 | height: 8, 10 | ); 11 | static const vGap12 = SizedBox( 12 | height: 12, 13 | ); 14 | static const vGap24 = SizedBox( 15 | height: 24, 16 | ); 17 | static const vGap32 = SizedBox( 18 | height: 32, 19 | ); 20 | 21 | static const hGap4 = SizedBox( 22 | width: 4, 23 | ); 24 | static const hGap8 = SizedBox( 25 | width: 8, 26 | ); 27 | static const hGap12 = SizedBox( 28 | width: 12, 29 | ); 30 | static const hGap16 = SizedBox( 31 | width: 16, 32 | ); 33 | 34 | static const hGap24 = SizedBox( 35 | width: 24, 36 | ); 37 | static const hGap32 = SizedBox( 38 | width: 32, 39 | ); 40 | 41 | static const edgeInsetsH4 = EdgeInsets.symmetric(horizontal: 4); 42 | static const edgeInsetsH8 = EdgeInsets.symmetric(horizontal: 8); 43 | static const edgeInsetsH12 = EdgeInsets.symmetric(horizontal: 12); 44 | static const edgeInsetsH24 = EdgeInsets.symmetric(horizontal: 24); 45 | 46 | static const edgeInsetsV4 = EdgeInsets.symmetric(vertical: 4); 47 | static const edgeInsetsV8 = EdgeInsets.symmetric(vertical: 8); 48 | static const edgeInsetsV12 = EdgeInsets.symmetric(vertical: 12); 49 | static const edgeInsetsV24 = EdgeInsets.symmetric(vertical: 24); 50 | 51 | static const edgeInsetsA4 = EdgeInsets.all(4); 52 | static const edgeInsetsA8 = EdgeInsets.all(8); 53 | static const edgeInsetsA12 = EdgeInsets.all(12); 54 | static const edgeInsetsA24 = EdgeInsets.all(24); 55 | 56 | static const edgeInsetsR4 = EdgeInsets.only(right: 4); 57 | static const edgeInsetsR8 = EdgeInsets.only(right: 8); 58 | static const edgeInsetsR12 = EdgeInsets.only(right: 12); 59 | static const edgeInsetsR24 = EdgeInsets.only(right: 24); 60 | 61 | static const edgeInsetsL4 = EdgeInsets.only(left: 4); 62 | static const edgeInsetsL8 = EdgeInsets.only(left: 8); 63 | static const edgeInsetsL12 = EdgeInsets.only(left: 12); 64 | static const edgeInsetsL24 = EdgeInsets.only(left: 24); 65 | 66 | static const edgeInsetsT4 = EdgeInsets.only(top: 4); 67 | static const edgeInsetsT8 = EdgeInsets.only(top: 8); 68 | static const edgeInsetsT12 = EdgeInsets.only(top: 12); 69 | static const edgeInsetsT24 = EdgeInsets.only(top: 24); 70 | 71 | static const edgeInsetsB4 = EdgeInsets.only(bottom: 4); 72 | static const edgeInsetsB8 = EdgeInsets.only(bottom: 8); 73 | static const edgeInsetsB12 = EdgeInsets.only(bottom: 12); 74 | static const edgeInsetsB24 = EdgeInsets.only(bottom: 24); 75 | 76 | static BorderRadius radius4 = BorderRadius.circular(4); 77 | static BorderRadius radius8 = BorderRadius.circular(8); 78 | static BorderRadius radius12 = BorderRadius.circular(12); 79 | static BorderRadius radius24 = BorderRadius.circular(24); 80 | static BorderRadius radius32 = BorderRadius.circular(32); 81 | static BorderRadius radius48 = BorderRadius.circular(48); 82 | 83 | static double get statusBarHeight => MediaQuery.of(Get.context!).padding.top; 84 | 85 | static double get bottomBarHeight => 86 | MediaQuery.of(Get.context!).padding.bottom; 87 | 88 | static TextStyle titleTextStyle = const TextStyle(fontSize: 15); 89 | static TextStyle introTetxStyle = 90 | const TextStyle(fontSize: 12, color: Colors.grey); 91 | } 92 | -------------------------------------------------------------------------------- /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.example" "\0" 93 | VALUE "FileDescription", "flutter_ithome" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "flutter_ithome" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "flutter_ithome.exe" "\0" 98 | VALUE "ProductName", "flutter_ithome" "\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 | -------------------------------------------------------------------------------- /lib/request/news_request.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/cupertino.dart'; 2 | import 'package:flutter_ithome/app/common/utils.dart'; 3 | import 'package:flutter_ithome/model/news_banner_model.dart'; 4 | import 'package:flutter_ithome/model/news_detail_model.dart'; 5 | import 'package:flutter_ithome/model/news_item_model.dart'; 6 | import 'package:flutter_ithome/request/api.dart'; 7 | import 'package:flutter_ithome/request/http_client.dart'; 8 | 9 | class NewsRequest { 10 | /// 置顶的新闻 11 | Future> getTopNews() async { 12 | var url = "${Api.kApiBaseUrl}/json/newslist/news"; 13 | var result = await HttpClient.instance.getJson( 14 | url, 15 | queryParameters: {"r": 0}, 16 | ); 17 | var ls = []; 18 | for (var item in result?["toplist"] ?? []) { 19 | ls.add(NewsItemModel.fromJson(item)); 20 | } 21 | return ls; 22 | } 23 | 24 | /// Banner 25 | Future> getBanner() async { 26 | var url = "${Api.kApiBaseUrl}/json/slide/index"; 27 | var result = await HttpClient.instance.getJson( 28 | url, 29 | queryParameters: {}, 30 | ); 31 | var ls = []; 32 | for (var item in result) { 33 | ls.add(NewsBannerModel.fromJson(item)); 34 | } 35 | return ls; 36 | } 37 | 38 | /// 新闻 39 | /// * [ot] 分页参数 40 | /// * [tag] 分类ID 41 | Future> getNews({ 42 | String tag = "news", 43 | }) async { 44 | // 处理分类ID 45 | if (tag.endsWith("m")) { 46 | tag = tag.substring(0, tag.length - 1); 47 | } 48 | 49 | var url = "${Api.kApiBaseUrl}/json/newslist/$tag"; 50 | var result = await HttpClient.instance.getJson( 51 | url, 52 | queryParameters: { 53 | 'r': DateTime.now().millisecondsSinceEpoch, 54 | }, 55 | ); 56 | var ls = []; 57 | for (var item in result?["newslist"] ?? []) { 58 | ls.add(NewsItemModel.fromJson(item)); 59 | } 60 | return ls; 61 | } 62 | 63 | /// 加载更多新闻 64 | /// * [ot] 分页参数 65 | /// * [tag] 分类ID 66 | Future> getNewsMore({ 67 | String ot = "", 68 | String tag = "", 69 | int page = 0, 70 | }) async { 71 | var url = "${Api.kWebApiBaseUrl}/api/news/newslistpageget"; 72 | var result = await HttpClient.instance.getJson( 73 | url, 74 | queryParameters: { 75 | "Tag": tag, 76 | "ot": ot, 77 | "page": page, 78 | "hitCountAuthority": false, 79 | }, 80 | ); 81 | var ls = []; 82 | for (var item in result?["Result"] ?? []) { 83 | ls.add(NewsItemModel.fromMJson(item)); 84 | } 85 | return ls; 86 | } 87 | 88 | /// 新闻详情 89 | /// * [newsId] 新闻ID 90 | Future getNewsDetail({ 91 | required int newsId, 92 | }) async { 93 | var url = "${Api.kApiBaseUrl}/json/newscontent/$newsId"; 94 | var result = await HttpClient.instance.getJson( 95 | url, 96 | ); 97 | return NewsDetailModel.fromJson(result); 98 | } 99 | 100 | /// 新闻评论 101 | /// * [newsId] 新闻ID 102 | Future getNewsCommentCount({ 103 | required int newsId, 104 | }) async { 105 | var url = "${Api.kCommentApiBaseUrl}/api/comment/getcount"; 106 | var result = await HttpClient.instance.getJson(url, 107 | queryParameters: {"sn": Utils.getCommentSn(newsId.toString())}); 108 | return result["content"]?["count"] ?? 0; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/app/controller/news_controller.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:io'; 3 | 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_ithome/app/common/event_bus.dart'; 6 | import 'package:flutter_ithome/app/service/app_settings_service.dart'; 7 | import 'package:flutter_ithome/model/category_item.dart'; 8 | import 'package:get/get.dart'; 9 | 10 | class NewsController extends GetxController 11 | with GetSingleTickerProviderStateMixin { 12 | Rx tabController = Rx(null); 13 | final settingsService = Get.find(); 14 | 15 | /// 全部栏目 16 | List allCategores = [ 17 | CategoryItem(name: "最新", id: "news"), 18 | //CategoryItem(name: "排行榜", id: "rank"), 19 | //CategoryItem(name: "热评", id: "comment"), 20 | CategoryItem(name: "精读", id: "jingdum"), 21 | CategoryItem(name: "原创", id: "originalm"), 22 | CategoryItem(name: "评测", id: "labsm"), 23 | CategoryItem(name: "直播", id: "livem"), 24 | CategoryItem(name: "IT号", id: "itaccountm"), 25 | CategoryItem(name: "阳台", id: "balconym"), 26 | CategoryItem(name: "专题", id: "specialm"), 27 | CategoryItem(name: "投票", id: "votenewm"), 28 | CategoryItem(name: "鸿蒙", id: "harmonyos"), 29 | CategoryItem(name: "5G", id: "5gm"), 30 | CategoryItem(name: "京东精选", id: "jdm"), 31 | CategoryItem(name: "电脑", id: "pcm"), 32 | CategoryItem(name: "手机", id: "phonem"), 33 | CategoryItem(name: "数码", id: "digim"), 34 | CategoryItem(name: "学院", id: "geekm"), 35 | CategoryItem(name: "VR", id: "vrm"), 36 | CategoryItem(name: "智能汽车", id: "autom"), 37 | CategoryItem(name: "安卓", id: "androidm"), 38 | CategoryItem(name: "苹果", id: "iosm"), 39 | CategoryItem(name: "网络焦点", id: "internetm"), 40 | CategoryItem(name: "行业前沿", id: "itm"), 41 | CategoryItem(name: "游戏电竞", id: "gamem"), 42 | CategoryItem(name: "Windows", id: "windowsm"), 43 | CategoryItem(name: "Linux", id: "linuxsm"), 44 | CategoryItem(name: "科普", id: "discoverym"), 45 | ]; 46 | 47 | var categores = [].obs; 48 | 49 | StreamSubscription? streamSubscription; 50 | 51 | @override 52 | void onInit() async { 53 | streamSubscription = 54 | EventBus.instance.listen(EventBus.kEventRefreshNews, (e) { 55 | tabController.value 56 | ?.animateTo(categores.indexWhere((x) => x.id == "news")); 57 | }); 58 | Future.delayed(const Duration(milliseconds: 200), initCategores); 59 | 60 | super.onInit(); 61 | } 62 | 63 | @override 64 | void dispose() { 65 | streamSubscription?.cancel(); 66 | super.dispose(); 67 | } 68 | 69 | void initCategores() { 70 | var ls = settingsService.getValue( 71 | AppSettingsService.kNewsCategores, 72 | getDefaultCategores(), 73 | ); 74 | 75 | categores.value = 76 | ls.map((e) => allCategores.firstWhere((x) => x.id == e)).toList(); 77 | tabController.value = TabController(length: categores.length, vsync: this); 78 | } 79 | 80 | /// 读取默认的栏目 81 | List getDefaultCategores() { 82 | var ls = allCategores.take(10).toList(); 83 | if (Platform.isWindows) { 84 | ls.insert( 85 | 3, 86 | CategoryItem(name: "Windows", id: "windowsm"), 87 | ); 88 | } else if (Platform.isMacOS || Platform.isIOS) { 89 | ls.insert( 90 | 3, 91 | CategoryItem(name: "苹果", id: "iosm"), 92 | ); 93 | } else if (Platform.isAndroid || Platform.isFuchsia) { 94 | ls.insert( 95 | 3, 96 | CategoryItem(name: "安卓", id: "androidm"), 97 | ); 98 | } else if (Platform.isLinux) { 99 | ls.insert( 100 | 3, 101 | CategoryItem(name: "Linux", id: "linuxsm"), 102 | ); 103 | } 104 | return ls.map((e) => e.id).toList(); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /lib/widget/bilibili_video_card.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/common/app_style.dart'; 3 | import 'package:flutter_ithome/app/controller/base_controller.dart'; 4 | import 'package:flutter_ithome/request/http_client.dart'; 5 | import 'package:flutter_ithome/widget/net_image.dart'; 6 | import 'package:get/get.dart'; 7 | import 'package:remixicon/remixicon.dart'; 8 | import 'package:url_launcher/url_launcher.dart'; 9 | 10 | class BiliBiliVideoCard extends StatelessWidget { 11 | final String url; 12 | const BiliBiliVideoCard(this.url, {Key? key}) : super(key: key); 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | return GetBuilder( 17 | init: BiliBiliVideoCardController(url), 18 | tag: url, 19 | builder: (controller) { 20 | return InkWell( 21 | onTap: () { 22 | if (!controller.pageLoadding.value && !controller.pageError.value) { 23 | launchUrl(Uri.parse(controller.jumpUrl), 24 | mode: LaunchMode.externalApplication); 25 | } 26 | }, 27 | child: Container( 28 | decoration: BoxDecoration( 29 | color: Colors.grey.shade100, 30 | borderRadius: BorderRadius.circular(8), 31 | ), 32 | height: MediaQuery.of(context).size.width * (9 / 16), 33 | child: Stack( 34 | children: [ 35 | NetImage( 36 | "${controller.pic.value}@400w.jpg", 37 | width: double.infinity, 38 | height: MediaQuery.of(context).size.width * (9 / 16), 39 | fit: BoxFit.cover, 40 | ), 41 | Visibility( 42 | visible: !controller.pageLoadding.value && 43 | !controller.pageError.value, 44 | child: const Center( 45 | child: Icon( 46 | Remix.play_circle_fill, 47 | color: Colors.white70, 48 | size: 56, 49 | ), 50 | ), 51 | ), 52 | Visibility( 53 | visible: controller.pageLoadding.value, 54 | child: const Center( 55 | child: CircularProgressIndicator(), 56 | ), 57 | ), 58 | Visibility( 59 | visible: controller.pageError.value, 60 | child: Center( 61 | child: Text( 62 | "视频加载失败", 63 | style: AppStyle.introTetxStyle, 64 | ), 65 | ), 66 | ), 67 | ], 68 | ), 69 | ), 70 | ); 71 | }, 72 | ); 73 | } 74 | } 75 | 76 | class BiliBiliVideoCardController extends BaseController { 77 | final String url; 78 | BiliBiliVideoCardController(this.url); 79 | var pic = "".obs; 80 | var author = "".obs; 81 | var title = "".obs; 82 | var jumpUrl = ""; 83 | @override 84 | void onInit() { 85 | loadData(); 86 | super.onInit(); 87 | } 88 | 89 | void loadData() async { 90 | pageLoadding.value = true; 91 | update(); 92 | try { 93 | var uri = Uri.parse(url); 94 | var result = await HttpClient.instance.getJson( 95 | "https://api.bilibili.com/x/web-interface/view", 96 | queryParameters: uri.queryParameters, 97 | ); 98 | pic.value = result["data"]["pic"]; 99 | title.value = result["data"]["title"]; 100 | title.value = result["data"]["owner"]["name"]; 101 | jumpUrl = "https://b23.tv/${result["data"]["bvid"]}"; 102 | } catch (e) { 103 | pageError.value = true; 104 | } finally { 105 | pageLoadding.value = false; 106 | update(); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # === Flutter Library === 14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 15 | 16 | # Published to parent scope for install step. 17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 21 | 22 | list(APPEND FLUTTER_LIBRARY_HEADERS 23 | "flutter_export.h" 24 | "flutter_windows.h" 25 | "flutter_messenger.h" 26 | "flutter_plugin_registrar.h" 27 | "flutter_texture_registrar.h" 28 | ) 29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 30 | add_library(flutter INTERFACE) 31 | target_include_directories(flutter INTERFACE 32 | "${EPHEMERAL_DIR}" 33 | ) 34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 35 | add_dependencies(flutter flutter_assemble) 36 | 37 | # === Wrapper === 38 | list(APPEND CPP_WRAPPER_SOURCES_CORE 39 | "core_implementations.cc" 40 | "standard_codec.cc" 41 | ) 42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 44 | "plugin_registrar.cc" 45 | ) 46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 47 | list(APPEND CPP_WRAPPER_SOURCES_APP 48 | "flutter_engine.cc" 49 | "flutter_view_controller.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 52 | 53 | # Wrapper sources needed for a plugin. 54 | add_library(flutter_wrapper_plugin STATIC 55 | ${CPP_WRAPPER_SOURCES_CORE} 56 | ${CPP_WRAPPER_SOURCES_PLUGIN} 57 | ) 58 | apply_standard_settings(flutter_wrapper_plugin) 59 | set_target_properties(flutter_wrapper_plugin PROPERTIES 60 | POSITION_INDEPENDENT_CODE ON) 61 | set_target_properties(flutter_wrapper_plugin PROPERTIES 62 | CXX_VISIBILITY_PRESET hidden) 63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 64 | target_include_directories(flutter_wrapper_plugin PUBLIC 65 | "${WRAPPER_ROOT}/include" 66 | ) 67 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 68 | 69 | # Wrapper sources needed for the runner. 70 | add_library(flutter_wrapper_app STATIC 71 | ${CPP_WRAPPER_SOURCES_CORE} 72 | ${CPP_WRAPPER_SOURCES_APP} 73 | ) 74 | apply_standard_settings(flutter_wrapper_app) 75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 76 | target_include_directories(flutter_wrapper_app PUBLIC 77 | "${WRAPPER_ROOT}/include" 78 | ) 79 | add_dependencies(flutter_wrapper_app flutter_assemble) 80 | 81 | # === Flutter tool backend === 82 | # _phony_ is a non-existent file to force this command to run every time, 83 | # since currently there's no way to get a full input/output list from the 84 | # flutter tool. 85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 87 | add_custom_command( 88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 90 | ${CPP_WRAPPER_SOURCES_APP} 91 | ${PHONY_OUTPUT} 92 | COMMAND ${CMAKE_COMMAND} -E env 93 | ${FLUTTER_TOOL_ENVIRONMENT} 94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 95 | windows-x64 $ 96 | VERBATIM 97 | ) 98 | add_custom_target(flutter_assemble DEPENDS 99 | "${FLUTTER_LIBRARY}" 100 | ${FLUTTER_LIBRARY_HEADERS} 101 | ${CPP_WRAPPER_SOURCES_CORE} 102 | ${CPP_WRAPPER_SOURCES_PLUGIN} 103 | ${CPP_WRAPPER_SOURCES_APP} 104 | ) 105 | -------------------------------------------------------------------------------- /lib/app/views/user_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/common/app_style.dart'; 3 | import 'package:flutter_ithome/app/controller/app_settings_controller.dart'; 4 | import 'package:get/get.dart'; 5 | import 'package:remixicon/remixicon.dart'; 6 | import 'package:url_launcher/url_launcher_string.dart'; 7 | 8 | class UserPage extends StatelessWidget { 9 | UserPage({Key? key}) : super(key: key); 10 | final AppSettingsController controller = Get.find(); 11 | @override 12 | Widget build(BuildContext context) { 13 | return Scaffold( 14 | body: ListView( 15 | padding: AppStyle.edgeInsetsV12, 16 | children: [ 17 | _buildUser(context), 18 | AppStyle.vGap12, 19 | _buildSettings(context), 20 | AppStyle.vGap12, 21 | _buildAbout(context) 22 | ], 23 | ), 24 | ); 25 | } 26 | 27 | Widget _buildUser(BuildContext context) { 28 | return Material( 29 | color: Theme.of(context).cardColor, 30 | child: Column( 31 | children: [ 32 | ListTile( 33 | leading: const Icon(Remix.star_line), 34 | title: const Text("我的收藏"), 35 | trailing: const Icon(Icons.chevron_right), 36 | onTap: () {}, 37 | ), 38 | Divider( 39 | height: 1, 40 | color: Colors.grey.withOpacity(.1), 41 | ), 42 | ListTile( 43 | leading: const Icon(Remix.history_line), 44 | title: const Text("浏览历史"), 45 | trailing: const Icon(Icons.chevron_right), 46 | onTap: () {}, 47 | ), 48 | ], 49 | ), 50 | ); 51 | } 52 | 53 | Widget _buildSettings(BuildContext context) { 54 | return Material( 55 | color: Theme.of(context).cardColor, 56 | child: Column( 57 | children: [ 58 | Obx( 59 | () => SwitchListTile( 60 | secondary: const Icon(Remix.moon_line), 61 | title: const Text("夜间模式"), 62 | value: controller.darkMode.value, 63 | onChanged: controller.changeDarkMode, 64 | ), 65 | ), 66 | ], 67 | ), 68 | ); 69 | } 70 | 71 | Widget _buildAbout(BuildContext context) { 72 | return Material( 73 | color: Theme.of(context).cardColor, 74 | child: Column( 75 | children: [ 76 | ListTile( 77 | leading: const Icon(Remix.information_line), 78 | title: const Text("关于"), 79 | trailing: const Icon(Icons.chevron_right), 80 | onTap: () { 81 | Get.dialog( 82 | AlertDialog( 83 | title: const Text("IT之家 Flutter"), 84 | content: const Text("@xiaoyaocz 开发\n\n个人学习编程使用,不用于任何商业用途"), 85 | actions: [ 86 | TextButton.icon( 87 | onPressed: () { 88 | launchUrlString("https://xiaoyaocz.com"); 89 | Get.back(); 90 | }, 91 | icon: const Icon(Remix.global_line), 92 | label: const Text("个人主页"), 93 | ), 94 | TextButton.icon( 95 | onPressed: () { 96 | launchUrlString( 97 | "https://github.com/xiaoyaocz/flutter_ithome"); 98 | Get.back(); 99 | }, 100 | icon: const Icon(Remix.github_line), 101 | label: const Text("GitHub"), 102 | ), 103 | TextButton( 104 | onPressed: Get.back, 105 | child: const Text("确定"), 106 | ), 107 | ], 108 | ), 109 | ); 110 | }, 111 | ), 112 | ], 113 | ), 114 | ); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /lib/app/views/news/news_new_view.dart: -------------------------------------------------------------------------------- 1 | import 'package:carousel_slider/carousel_slider.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_easyrefresh/easy_refresh.dart'; 4 | import 'package:flutter_ithome/app/common/app_style.dart'; 5 | import 'package:flutter_ithome/app/common/utils.dart'; 6 | import 'package:flutter_ithome/app/controller/news/news_new_controller.dart'; 7 | import 'package:flutter_ithome/widget/adjustable_scroll_controller.dart'; 8 | import 'package:flutter_ithome/widget/empty.dart'; 9 | import 'package:flutter_ithome/widget/error.dart'; 10 | import 'package:flutter_ithome/widget/keep_alive_wrapper.dart'; 11 | import 'package:flutter_ithome/widget/loadding.dart'; 12 | import 'package:flutter_ithome/widget/net_image.dart'; 13 | import 'package:flutter_ithome/widget/news_item.dart'; 14 | import 'package:get/get.dart'; 15 | 16 | class NewsNewView extends StatelessWidget { 17 | const NewsNewView({Key? key}) : super(key: key); 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return KeepAliveWrapper( 22 | child: GetBuilder( 23 | init: NewsNewController(), 24 | builder: ((c) { 25 | // 页面错误 26 | if (c.pageError.value) { 27 | return AppErrorWidget( 28 | c.errorMsg.value, 29 | onRefresh: () => c.refreshData(), 30 | ); 31 | } 32 | // 页面内容为空 33 | if (!c.pageError.value && c.pageEmpty.value) { 34 | return EmptyWidget( 35 | onRefresh: () => c.refreshData(), 36 | ); 37 | } 38 | return Stack( 39 | children: [ 40 | EasyRefresh( 41 | onLoad: c.loadData, 42 | onRefresh: c.refreshData, 43 | header: BallPulseHeader(), 44 | footer: BallPulseFooter(), 45 | child: ListView.builder( 46 | padding: AppStyle.edgeInsetsV8, 47 | itemCount: c.list.length + 1, 48 | controller: AdjustableScrollController(), 49 | itemBuilder: (_, i) { 50 | if (i == 0) { 51 | return _buildHeader(context, c); 52 | } 53 | var item = c.list[i - 1]; 54 | return NewsItemWidget(item); 55 | }, 56 | ), 57 | ), 58 | //页面加载中 59 | Visibility( 60 | visible: c.pageLoadding.value, 61 | child: const LoaddingWidget(), 62 | ), 63 | ], 64 | ); 65 | }), 66 | ), 67 | ); 68 | } 69 | 70 | Widget _buildHeader(BuildContext context, NewsNewController controller) { 71 | return Container( 72 | color: Theme.of(context).cardColor, 73 | margin: AppStyle.edgeInsetsB8, 74 | padding: controller.topNews.isEmpty 75 | ? AppStyle.edgeInsetsV12 76 | : AppStyle.edgeInsetsT12, 77 | child: Column( 78 | children: [ 79 | Padding( 80 | padding: const EdgeInsets.symmetric(horizontal: 16), 81 | child: CarouselSlider( 82 | options: CarouselOptions( 83 | autoPlay: true, 84 | aspectRatio: 120 / 48, 85 | viewportFraction: 1.0, 86 | //height: (MediaQuery.of(context).size.width - 32) * (48 / 120), 87 | ), 88 | items: controller.banner.map((item) { 89 | return GestureDetector( 90 | onTap: () { 91 | Utils.handleUrl(item.link); 92 | }, 93 | child: NetImage( 94 | item.image, 95 | elevation: 0, 96 | ), 97 | ); 98 | }).toList(), 99 | ), 100 | ), 101 | ...controller.topNews.map( 102 | (x) => NewsItemWidget( 103 | x, 104 | isTop: true, 105 | ), 106 | ), 107 | ], 108 | ), 109 | ); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "flutter_ithome"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "flutter_ithome"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(flutter_ithome LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "flutter_ithome") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(SET CMP0063 NEW) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | # Generated plugin build rules, which manage building the plugins and adding 56 | # them to the application. 57 | include(flutter/generated_plugins.cmake) 58 | 59 | 60 | # === Installation === 61 | # Support files are copied into place next to the executable, so that it can 62 | # run in place. This is done instead of making a separate bundle (as on Linux) 63 | # so that building and running from within Visual Studio will work. 64 | set(BUILD_BUNDLE_DIR "$") 65 | # Make the "install" step default, as it's required to run. 66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 69 | endif() 70 | 71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 73 | 74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 75 | COMPONENT Runtime) 76 | 77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 78 | COMPONENT Runtime) 79 | 80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 81 | COMPONENT Runtime) 82 | 83 | if(PLUGIN_BUNDLED_LIBRARIES) 84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 86 | COMPONENT Runtime) 87 | endif() 88 | 89 | # Fully re-copy the assets directory on each build to avoid having stale files 90 | # from a previous install. 91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 92 | install(CODE " 93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 94 | " COMPONENT Runtime) 95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 97 | 98 | # Install the AOT library on non-Debug builds only. 99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 100 | CONFIGURATIONS Profile;Release 101 | COMPONENT Runtime) 102 | -------------------------------------------------------------------------------- /lib/model/news_detail_model.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter_ithome/model/ff_convert.dart'; 4 | 5 | class NewsDetailModel { 6 | NewsDetailModel({ 7 | required this.success, 8 | required this.newsid, 9 | required this.title, 10 | required this.url, 11 | required this.newssource, 12 | required this.newsauthor, 13 | required this.keyword, 14 | required this.image, 15 | this.newstags, 16 | this.newsflag, 17 | this.user, 18 | required this.detail, 19 | this.postdate, 20 | this.hitcount, 21 | this.btheme, 22 | this.forbidcomment, 23 | this.commentcount, 24 | this.z, 25 | }); 26 | 27 | factory NewsDetailModel.fromJson(Map json) { 28 | final List? newstags = 29 | json['newstags'] is List ? [] : null; 30 | if (newstags != null) { 31 | for (final dynamic item in json['newstags']!) { 32 | if (item != null) { 33 | newstags.add( 34 | NewsDetailTagModel.fromJson(asT>(item)!)); 35 | } 36 | } 37 | } 38 | return NewsDetailModel( 39 | success: asT(json['success'])!, 40 | newsid: asT(json['newsid'])!, 41 | title: asT(json['title'])!, 42 | url: asT(json['url'])!, 43 | newssource: asT(json['newssource'])!, 44 | newsauthor: asT(json['newsauthor'])!, 45 | keyword: asT(json['keyword'])!, 46 | image: asT(json['image'])!, 47 | newstags: newstags, 48 | newsflag: asT(json['newsflag']), 49 | user: json['user'] == null 50 | ? null 51 | : NewsDetailUserModel.fromJson( 52 | asT>(json['user'])!), 53 | detail: asT(json['detail'])!, 54 | postdate: DateTime.tryParse(json['postdate'].toString()), 55 | hitcount: asT(json['hitcount']), 56 | btheme: asT(json['btheme']), 57 | forbidcomment: asT(json['forbidcomment']), 58 | commentcount: asT(json['commentcount']), 59 | z: asT(json['z']), 60 | ); 61 | } 62 | 63 | bool success; 64 | int newsid; 65 | String title; 66 | String url; 67 | String newssource; 68 | String newsauthor; 69 | String keyword; 70 | String image; 71 | List? newstags; 72 | int? newsflag; 73 | NewsDetailUserModel? user; 74 | String detail; 75 | DateTime? postdate; 76 | int? hitcount; 77 | bool? btheme; 78 | bool? forbidcomment; 79 | int? commentcount; 80 | String? z; 81 | 82 | @override 83 | String toString() { 84 | return jsonEncode(this); 85 | } 86 | 87 | Map toJson() => { 88 | 'success': success, 89 | 'newsid': newsid, 90 | 'title': title, 91 | 'url': url, 92 | 'newssource': newssource, 93 | 'newsauthor': newsauthor, 94 | 'keyword': keyword, 95 | 'image': image, 96 | 'newstags': newstags, 97 | 'newsflag': newsflag, 98 | 'user': user, 99 | 'detail': detail, 100 | 'postdate': postdate, 101 | 'hitcount': hitcount, 102 | 'btheme': btheme, 103 | 'forbidcomment': forbidcomment, 104 | 'commentcount': commentcount, 105 | 'z': z, 106 | }; 107 | } 108 | 109 | class NewsDetailTagModel { 110 | NewsDetailTagModel({ 111 | this.id, 112 | this.keyword, 113 | this.link, 114 | }); 115 | 116 | factory NewsDetailTagModel.fromJson(Map json) => 117 | NewsDetailTagModel( 118 | id: asT(json['id']), 119 | keyword: asT(json['keyword']), 120 | link: asT(json['link']), 121 | ); 122 | 123 | int? id; 124 | String? keyword; 125 | String? link; 126 | 127 | @override 128 | String toString() { 129 | return jsonEncode(this); 130 | } 131 | 132 | Map toJson() => { 133 | 'id': id, 134 | 'keyword': keyword, 135 | 'link': link, 136 | }; 137 | } 138 | 139 | class NewsDetailUserModel { 140 | NewsDetailUserModel({ 141 | this.userid, 142 | this.usernick, 143 | this.m, 144 | }); 145 | 146 | factory NewsDetailUserModel.fromJson(Map json) => 147 | NewsDetailUserModel( 148 | userid: asT(json['userid']), 149 | usernick: asT(json['usernick']), 150 | m: asT(json['m']), 151 | ); 152 | 153 | int? userid; 154 | String? usernick; 155 | int? m; 156 | 157 | @override 158 | String toString() { 159 | return jsonEncode(this); 160 | } 161 | 162 | Map toJson() => { 163 | 'userid': userid, 164 | 'usernick': usernick, 165 | 'm': m, 166 | }; 167 | } 168 | -------------------------------------------------------------------------------- /lib/app/views/news_page.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:flutter_ithome/app/common/app_style.dart'; 4 | import 'package:flutter_ithome/app/controller/news_controller.dart'; 5 | import 'package:flutter_ithome/app/views/news/news_category_view.dart'; 6 | import 'package:flutter_ithome/app/views/news/news_new_view.dart'; 7 | import 'package:flutter_ithome/app/views/news/news_rank_view.dart'; 8 | import 'package:flutter_ithome/model/category_item.dart'; 9 | import 'package:get/get.dart'; 10 | import 'package:remixicon/remixicon.dart'; 11 | 12 | class NewsPage extends GetView { 13 | const NewsPage({Key? key}) : super(key: key); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | return Obx( 18 | () => controller.tabController.value == null 19 | ? const Scaffold() 20 | : Scaffold( 21 | appBar: NewsAppBar( 22 | tabController: controller.tabController.value!, 23 | categores: controller.categores, 24 | ), 25 | body: TabBarView( 26 | controller: controller.tabController.value!, 27 | children: controller.categores 28 | .map( 29 | (e) => buildTabItem(e), 30 | ) 31 | .toList(), 32 | ), 33 | ), 34 | ); 35 | } 36 | 37 | Widget buildTabItem(CategoryItem categoryItem) { 38 | if (categoryItem.id == "news") { 39 | return const NewsNewView(); 40 | } 41 | if (categoryItem.id == "rank") { 42 | return const NewsRankView(); 43 | } 44 | if (categoryItem.id == "comment") { 45 | return Center( 46 | child: Text(categoryItem.name), 47 | ); 48 | } 49 | return NewsCategoryView(categoryItem.id); 50 | } 51 | } 52 | 53 | class NewsAppBar extends StatelessWidget with PreferredSizeWidget { 54 | final TabController tabController; 55 | final List categores; 56 | const NewsAppBar( 57 | {required this.tabController, required this.categores, Key? key}) 58 | : super(key: key); 59 | @override 60 | Widget build(BuildContext context) { 61 | return AnnotatedRegion( 62 | value: Get.isDarkMode 63 | ? SystemUiOverlayStyle.light 64 | : SystemUiOverlayStyle.dark, 65 | child: Container( 66 | padding: EdgeInsets.only(top: AppStyle.statusBarHeight), 67 | color: Theme.of(context).cardColor, 68 | height: AppStyle.statusBarHeight + 96, 69 | child: Column( 70 | mainAxisAlignment: MainAxisAlignment.center, 71 | children: [ 72 | Container( 73 | padding: AppStyle.edgeInsetsA12.copyWith(bottom: 0), 74 | child: Row( 75 | crossAxisAlignment: CrossAxisAlignment.center, 76 | children: [ 77 | Image.asset( 78 | Get.isDarkMode 79 | ? 'assets/logo/about_logo_night2.png' 80 | : 'assets/logo/about_logo.png', 81 | height: 24, 82 | ), 83 | AppStyle.hGap16, 84 | Expanded( 85 | child: Container( 86 | padding: AppStyle.edgeInsetsH12, 87 | height: 32, 88 | decoration: BoxDecoration( 89 | color: Colors.grey.withOpacity(.2), 90 | borderRadius: BorderRadius.circular(32), 91 | ), 92 | alignment: Alignment.centerLeft, 93 | child: const Text( 94 | "请输入想搜索的内容", 95 | style: TextStyle(color: Colors.grey), 96 | ), 97 | ), 98 | ), 99 | ], 100 | ), 101 | ), 102 | AppStyle.vGap4, 103 | SizedBox( 104 | width: double.infinity, 105 | child: Row( 106 | children: [ 107 | Expanded( 108 | child: TabBar( 109 | controller: tabController, 110 | labelColor: Get.isDarkMode ? Colors.white : Colors.black, 111 | indicatorSize: TabBarIndicatorSize.label, 112 | indicatorColor: Theme.of(context).colorScheme.secondary, 113 | isScrollable: true, 114 | labelStyle: const TextStyle(height: 1.0), 115 | tabs: categores 116 | .map( 117 | (e) => Tab( 118 | text: e.name, 119 | ), 120 | ) 121 | .toList(), 122 | ), 123 | ), 124 | Material( 125 | color: Colors.transparent, 126 | child: IconButton( 127 | onPressed: () {}, 128 | icon: const Icon( 129 | Remix.menu_3_line, 130 | size: 20, 131 | ), 132 | ), 133 | ), 134 | ], 135 | ), 136 | ), 137 | ], 138 | ), 139 | ), 140 | ); 141 | } 142 | 143 | @override 144 | Size get preferredSize => Size.fromHeight(AppStyle.statusBarHeight + 96); 145 | } 146 | -------------------------------------------------------------------------------- /linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "flutter_ithome") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.example.flutter_ithome") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Generated plugin build rules, which manage building the plugins and adding 90 | # them to the application. 91 | include(flutter/generated_plugins.cmake) 92 | 93 | 94 | # === Installation === 95 | # By default, "installing" just makes a relocatable bundle in the build 96 | # directory. 97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 100 | endif() 101 | 102 | # Start with a clean build bundle directory every time. 103 | install(CODE " 104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 105 | " COMPONENT Runtime) 106 | 107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 109 | 110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 111 | COMPONENT Runtime) 112 | 113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 114 | COMPONENT Runtime) 115 | 116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 117 | COMPONENT Runtime) 118 | 119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 120 | install(FILES "${bundled_library}" 121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 122 | COMPONENT Runtime) 123 | endforeach(bundled_library) 124 | 125 | # Fully re-copy the assets directory on each build to avoid having stale files 126 | # from a previous install. 127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 128 | install(CODE " 129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 130 | " COMPONENT Runtime) 131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 133 | 134 | # Install the AOT library on non-Debug builds only. 135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 137 | COMPONENT Runtime) 138 | endif() 139 | -------------------------------------------------------------------------------- /lib/app/controller/news/news_detail_controller.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/common/app_navigator.dart'; 3 | import 'package:flutter_ithome/app/common/app_style.dart'; 4 | import 'package:flutter_ithome/app/common/log.dart'; 5 | import 'package:flutter_ithome/app/common/utils.dart'; 6 | import 'package:flutter_ithome/app/controller/base_controller.dart'; 7 | import 'package:flutter_ithome/app/service/app_settings_service.dart'; 8 | import 'package:flutter_ithome/app/service/app_storage_service.dart'; 9 | import 'package:flutter_ithome/request/news_request.dart'; 10 | import 'package:get/get.dart'; 11 | import 'package:url_launcher/url_launcher_string.dart'; 12 | import 'package:share_plus/share_plus.dart'; 13 | 14 | class NewsDetailControler extends BaseController { 15 | final int newsId; 16 | NewsDetailControler( 17 | this.newsId, 18 | ); 19 | var title = "".obs; 20 | var content = "".obs; 21 | var postTime = "0000-00-00 00-00".obs; 22 | var source = "IT之家".obs; 23 | var author = "--".obs; 24 | var head = "".obs; 25 | var url = ""; 26 | var fontSize = 16.0.obs; 27 | var commentCount = 0.obs; 28 | var image = ""; 29 | var collected = false.obs; 30 | 31 | final NewsRequest request = NewsRequest(); 32 | @override 33 | void onInit() { 34 | fontSize.value = AppSettingsService.instance 35 | .getValue(AppSettingsService.kReadFontSize, 16.0); 36 | loadDetail(); 37 | super.onInit(); 38 | } 39 | 40 | void loadDetail() async { 41 | pageLoadding.value = true; 42 | update(); 43 | try { 44 | var model = await request.getNewsDetail(newsId: newsId); 45 | title.value = model.title; 46 | content.value = model.detail; 47 | postTime.value = 48 | Utils.dateFormatWithYear.format(model.postdate ?? DateTime(1900)); 49 | source.value = model.newssource; 50 | author.value = model.newsauthor; 51 | head.value = model.z ?? ""; 52 | url = model.url; 53 | image = model.image; 54 | collected.value = AppStorageService.instance.existNewsCollect(newsId); 55 | getCommentCount(); 56 | } catch (e) { 57 | pageError.value = true; 58 | } finally { 59 | pageLoadding.value = false; 60 | update(); 61 | } 62 | } 63 | 64 | void getCommentCount() async { 65 | try { 66 | commentCount.value = await request.getNewsCommentCount(newsId: newsId); 67 | } finally {} 68 | //https://cmt.ithome.com/api/comment/getcount?sn=C74D01E9556F2E9B 69 | //https://cmt.ithome.com/api/comment/hot?sn=161EDD81D49C1BD8 70 | //https://cmt.ithome.com/api/comment/hot?sn=B4AEFA0A003D5835 71 | //https://cmt.ithome.com/api/comment/hot?sn=B4AEFA0A003D5835 72 | } 73 | 74 | void toOriginal() { 75 | launchUrlString('https://www.ithome.com$url', 76 | mode: LaunchMode.externalApplication); 77 | } 78 | 79 | void setting() { 80 | AppNavigator.showBottomSheet( 81 | Container( 82 | height: 200, 83 | color: Theme.of(Get.context!).cardColor, 84 | padding: AppStyle.edgeInsetsA12, 85 | child: Column( 86 | crossAxisAlignment: CrossAxisAlignment.start, 87 | children: [ 88 | Row( 89 | children: const [ 90 | Expanded( 91 | child: Text( 92 | "阅读设置", 93 | style: TextStyle(fontSize: 20), 94 | ), 95 | ), 96 | IconButton( 97 | onPressed: AppNavigator.closePage, 98 | icon: Icon(Icons.close), 99 | ), 100 | ], 101 | ), 102 | AppStyle.vGap12, 103 | Row( 104 | crossAxisAlignment: CrossAxisAlignment.center, 105 | children: [ 106 | const Expanded( 107 | child: Text( 108 | "字体大小", 109 | style: TextStyle(fontSize: 16), 110 | ), 111 | ), 112 | IconButton( 113 | onPressed: () { 114 | if (fontSize.value <= 8) { 115 | return; 116 | } 117 | fontSize.value -= 2; 118 | AppSettingsService.instance.setValue( 119 | AppSettingsService.kReadFontSize, fontSize.value); 120 | update(); 121 | }, 122 | icon: const Icon(Icons.remove), 123 | ), 124 | Obx( 125 | () => Padding( 126 | padding: AppStyle.edgeInsetsA8, 127 | child: Text( 128 | fontSize.value.toStringAsFixed(0), 129 | style: const TextStyle(fontSize: 16), 130 | ), 131 | ), 132 | ), 133 | IconButton( 134 | onPressed: () { 135 | if (fontSize.value >= 48) { 136 | return; 137 | } 138 | fontSize.value += 2; 139 | AppSettingsService.instance.setValue( 140 | AppSettingsService.kReadFontSize, fontSize.value); 141 | update(); 142 | }, 143 | icon: const Icon(Icons.add), 144 | ), 145 | ], 146 | ) 147 | ], 148 | ), 149 | ), 150 | ); 151 | } 152 | 153 | void share() { 154 | if (url.isEmpty) return; 155 | Share.share('https://www.ithome.com$url'); 156 | } 157 | 158 | void collect() { 159 | if (AppStorageService.instance.existNewsCollect(newsId)) { 160 | AppStorageService.instance.deleteNewsCollect(newsId); 161 | collected.value = false; 162 | } else { 163 | AppStorageService.instance.insertNewsCollect( 164 | newsId, 165 | url: url, 166 | title: title.value, 167 | image: image, 168 | ); 169 | collected.value = true; 170 | } 171 | update(); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /lib/widget/news_item.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_ithome/app/common/app_navigator.dart'; 3 | import 'package:flutter_ithome/app/common/app_style.dart'; 4 | import 'package:flutter_ithome/app/common/event_bus.dart'; 5 | import 'package:flutter_ithome/app/common/utils.dart'; 6 | import 'package:flutter_ithome/app/route/route_path.dart'; 7 | import 'package:flutter_ithome/app/service/app_storage_service.dart'; 8 | import 'package:flutter_ithome/model/news_item_model.dart'; 9 | import 'package:flutter_ithome/widget/net_image.dart'; 10 | import 'package:get/get.dart'; 11 | 12 | class NewsItemWidget extends StatelessWidget { 13 | final NewsItemModel item; 14 | 15 | /// 是否置顶 16 | final bool isTop; 17 | 18 | const NewsItemWidget(this.item, {this.isTop = false, Key? key}) 19 | : super(key: key); 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | Widget widget = Container(); 24 | if (item.images?.isEmpty ?? true) { 25 | widget = _buildLeftImage(context); 26 | } else { 27 | widget = _buildThreeImage(context); 28 | } 29 | 30 | return Material( 31 | color: Theme.of(context).cardColor, 32 | child: InkWell( 33 | onTap: () { 34 | AppStorageService.instance.insertNewsHistory( 35 | item.newsid, 36 | url: '', 37 | title: item.title, 38 | image: item.image, 39 | ); 40 | EventBus.instance.emit(EventBus.kEventRefreshNewsItem, item.newsid); 41 | AppNavigator.toContentPage( 42 | RoutePath.kNewsDetail, 43 | arg: item.newsid, 44 | ); 45 | }, 46 | child: widget, 47 | ), 48 | ); 49 | } 50 | 51 | Widget _buildLeftImage(BuildContext context) { 52 | return Container( 53 | padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), 54 | child: Row( 55 | crossAxisAlignment: CrossAxisAlignment.start, 56 | mainAxisAlignment: MainAxisAlignment.start, 57 | children: [ 58 | NetImage( 59 | item.image, 60 | height: 80, 61 | width: 106, 62 | elevation: 0, 63 | borderRadius: 8, 64 | ), 65 | AppStyle.hGap16, 66 | Expanded( 67 | child: SizedBox( 68 | height: 80, 69 | child: Column( 70 | crossAxisAlignment: CrossAxisAlignment.start, 71 | mainAxisAlignment: MainAxisAlignment.start, 72 | children: [ 73 | Expanded( 74 | child: _buildTitle(), 75 | ), 76 | _buildBottom(), 77 | ], 78 | ), 79 | ), 80 | ), 81 | ], 82 | ), 83 | ); 84 | } 85 | 86 | Widget _buildThreeImage(BuildContext context) { 87 | return Container( 88 | padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8), 89 | child: Column( 90 | crossAxisAlignment: CrossAxisAlignment.start, 91 | mainAxisAlignment: MainAxisAlignment.start, 92 | children: [ 93 | Padding( 94 | padding: AppStyle.edgeInsetsH4, 95 | child: _buildTitle(), 96 | ), 97 | AppStyle.vGap8, 98 | item.images!.length >= 3 99 | ? Row( 100 | children: item.images! 101 | .take(3) 102 | .map( 103 | (e) => Expanded( 104 | child: Padding( 105 | padding: const EdgeInsets.all(4.0), 106 | child: NetImage( 107 | e, 108 | height: 80, 109 | elevation: 0, 110 | borderRadius: 4, 111 | ), 112 | ), 113 | ), 114 | ) 115 | .toList(), 116 | ) 117 | : Padding( 118 | padding: const EdgeInsets.all(4.0), 119 | child: NetImage( 120 | item.images!.first, 121 | width: double.infinity, 122 | elevation: 0, 123 | borderRadius: 8, 124 | ), 125 | ), 126 | AppStyle.vGap12, 127 | Padding( 128 | padding: AppStyle.edgeInsetsH4, 129 | child: _buildBottom(), 130 | ), 131 | ], 132 | ), 133 | ); 134 | } 135 | 136 | Widget _buildTitle() { 137 | return Text( 138 | item.title, 139 | maxLines: 2, 140 | overflow: TextOverflow.ellipsis, 141 | style: AppStorageService.instance.existNewsHistory(item.newsid) 142 | ? AppStyle.titleTextStyle.copyWith(color: Colors.grey) 143 | : AppStyle.titleTextStyle, 144 | ); 145 | } 146 | 147 | /// 时间+评论数 148 | Widget _buildBottom() { 149 | return Row( 150 | mainAxisAlignment: MainAxisAlignment.start, 151 | children: [ 152 | Expanded( 153 | child: Row( 154 | crossAxisAlignment: CrossAxisAlignment.center, 155 | children: [ 156 | Visibility( 157 | visible: !isTop, 158 | child: Padding( 159 | padding: AppStyle.edgeInsetsR8, 160 | child: Text( 161 | Utils.handleTime(item.postdate), 162 | style: AppStyle.introTetxStyle, 163 | ), 164 | ), 165 | ), 166 | _buildTag( 167 | "置顶", 168 | visible: isTop, 169 | color: Colors.red, 170 | ), 171 | _buildTag( 172 | "广告", 173 | visible: item.isAd, 174 | ), 175 | _buildTag( 176 | "视频", 177 | visible: item.isVideo, 178 | color: Colors.orange, 179 | ), 180 | ], 181 | ), 182 | ), 183 | Text( 184 | "${item.commentcount}评", 185 | style: AppStyle.introTetxStyle, 186 | ), 187 | ], 188 | ); 189 | } 190 | 191 | Widget _buildTag(String tag, 192 | {bool visible = false, Color color = Colors.grey}) { 193 | return Visibility( 194 | visible: visible, 195 | child: Container( 196 | decoration: BoxDecoration( 197 | borderRadius: BorderRadius.circular(4), 198 | border: Border.all(color: color), 199 | ), 200 | margin: AppStyle.edgeInsetsR8, 201 | padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), 202 | child: Text( 203 | tag, 204 | style: TextStyle(fontSize: 10, color: color, height: 1), 205 | ), 206 | ), 207 | ); 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /windows/runner/win32_window.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | namespace { 8 | 9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 10 | 11 | // The number of Win32Window objects that currently exist. 12 | static int g_active_window_count = 0; 13 | 14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 15 | 16 | // Scale helper to convert logical scaler values to physical using passed in 17 | // scale factor 18 | int Scale(int source, double scale_factor) { 19 | return static_cast(source * scale_factor); 20 | } 21 | 22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 23 | // This API is only needed for PerMonitor V1 awareness mode. 24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 25 | HMODULE user32_module = LoadLibraryA("User32.dll"); 26 | if (!user32_module) { 27 | return; 28 | } 29 | auto enable_non_client_dpi_scaling = 30 | reinterpret_cast( 31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 32 | if (enable_non_client_dpi_scaling != nullptr) { 33 | enable_non_client_dpi_scaling(hwnd); 34 | FreeLibrary(user32_module); 35 | } 36 | } 37 | 38 | } // namespace 39 | 40 | // Manages the Win32Window's window class registration. 41 | class WindowClassRegistrar { 42 | public: 43 | ~WindowClassRegistrar() = default; 44 | 45 | // Returns the singleton registar instance. 46 | static WindowClassRegistrar* GetInstance() { 47 | if (!instance_) { 48 | instance_ = new WindowClassRegistrar(); 49 | } 50 | return instance_; 51 | } 52 | 53 | // Returns the name of the window class, registering the class if it hasn't 54 | // previously been registered. 55 | const wchar_t* GetWindowClass(); 56 | 57 | // Unregisters the window class. Should only be called if there are no 58 | // instances of the window. 59 | void UnregisterWindowClass(); 60 | 61 | private: 62 | WindowClassRegistrar() = default; 63 | 64 | static WindowClassRegistrar* instance_; 65 | 66 | bool class_registered_ = false; 67 | }; 68 | 69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 70 | 71 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 72 | if (!class_registered_) { 73 | WNDCLASS window_class{}; 74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 75 | window_class.lpszClassName = kWindowClassName; 76 | window_class.style = CS_HREDRAW | CS_VREDRAW; 77 | window_class.cbClsExtra = 0; 78 | window_class.cbWndExtra = 0; 79 | window_class.hInstance = GetModuleHandle(nullptr); 80 | window_class.hIcon = 81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 82 | window_class.hbrBackground = 0; 83 | window_class.lpszMenuName = nullptr; 84 | window_class.lpfnWndProc = Win32Window::WndProc; 85 | RegisterClass(&window_class); 86 | class_registered_ = true; 87 | } 88 | return kWindowClassName; 89 | } 90 | 91 | void WindowClassRegistrar::UnregisterWindowClass() { 92 | UnregisterClass(kWindowClassName, nullptr); 93 | class_registered_ = false; 94 | } 95 | 96 | Win32Window::Win32Window() { 97 | ++g_active_window_count; 98 | } 99 | 100 | Win32Window::~Win32Window() { 101 | --g_active_window_count; 102 | Destroy(); 103 | } 104 | 105 | bool Win32Window::CreateAndShow(const std::wstring& title, 106 | const Point& origin, 107 | const Size& size) { 108 | Destroy(); 109 | 110 | const wchar_t* window_class = 111 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 112 | 113 | const POINT target_point = {static_cast(origin.x), 114 | static_cast(origin.y)}; 115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 117 | double scale_factor = dpi / 96.0; 118 | 119 | HWND window = CreateWindow( 120 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 121 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 122 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 123 | nullptr, nullptr, GetModuleHandle(nullptr), this); 124 | 125 | if (!window) { 126 | return false; 127 | } 128 | 129 | return OnCreate(); 130 | } 131 | 132 | // static 133 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 134 | UINT const message, 135 | WPARAM const wparam, 136 | LPARAM const lparam) noexcept { 137 | if (message == WM_NCCREATE) { 138 | auto window_struct = reinterpret_cast(lparam); 139 | SetWindowLongPtr(window, GWLP_USERDATA, 140 | reinterpret_cast(window_struct->lpCreateParams)); 141 | 142 | auto that = static_cast(window_struct->lpCreateParams); 143 | EnableFullDpiSupportIfAvailable(window); 144 | that->window_handle_ = window; 145 | } else if (Win32Window* that = GetThisFromHandle(window)) { 146 | return that->MessageHandler(window, message, wparam, lparam); 147 | } 148 | 149 | return DefWindowProc(window, message, wparam, lparam); 150 | } 151 | 152 | LRESULT 153 | Win32Window::MessageHandler(HWND hwnd, 154 | UINT const message, 155 | WPARAM const wparam, 156 | LPARAM const lparam) noexcept { 157 | switch (message) { 158 | case WM_DESTROY: 159 | window_handle_ = nullptr; 160 | Destroy(); 161 | if (quit_on_close_) { 162 | PostQuitMessage(0); 163 | } 164 | return 0; 165 | 166 | case WM_DPICHANGED: { 167 | auto newRectSize = reinterpret_cast(lparam); 168 | LONG newWidth = newRectSize->right - newRectSize->left; 169 | LONG newHeight = newRectSize->bottom - newRectSize->top; 170 | 171 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 172 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 173 | 174 | return 0; 175 | } 176 | case WM_SIZE: { 177 | RECT rect = GetClientArea(); 178 | if (child_content_ != nullptr) { 179 | // Size and position the child window. 180 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 181 | rect.bottom - rect.top, TRUE); 182 | } 183 | return 0; 184 | } 185 | 186 | case WM_ACTIVATE: 187 | if (child_content_ != nullptr) { 188 | SetFocus(child_content_); 189 | } 190 | return 0; 191 | } 192 | 193 | return DefWindowProc(window_handle_, message, wparam, lparam); 194 | } 195 | 196 | void Win32Window::Destroy() { 197 | OnDestroy(); 198 | 199 | if (window_handle_) { 200 | DestroyWindow(window_handle_); 201 | window_handle_ = nullptr; 202 | } 203 | if (g_active_window_count == 0) { 204 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 205 | } 206 | } 207 | 208 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 209 | return reinterpret_cast( 210 | GetWindowLongPtr(window, GWLP_USERDATA)); 211 | } 212 | 213 | void Win32Window::SetChildContent(HWND content) { 214 | child_content_ = content; 215 | SetParent(content, window_handle_); 216 | RECT frame = GetClientArea(); 217 | 218 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 219 | frame.bottom - frame.top, true); 220 | 221 | SetFocus(child_content_); 222 | } 223 | 224 | RECT Win32Window::GetClientArea() { 225 | RECT frame; 226 | GetClientRect(window_handle_, &frame); 227 | return frame; 228 | } 229 | 230 | HWND Win32Window::GetHandle() { 231 | return window_handle_; 232 | } 233 | 234 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 235 | quit_on_close_ = quit_on_close; 236 | } 237 | 238 | bool Win32Window::OnCreate() { 239 | // No-op; provided for subclasses. 240 | return true; 241 | } 242 | 243 | void Win32Window::OnDestroy() { 244 | // No-op; provided for subclasses. 245 | } 246 | --------------------------------------------------------------------------------