├── ios ├── Flutter │ ├── Debug.xcconfig │ ├── Release.xcconfig │ └── AppFrameworkInfo.plist ├── 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 ├── Runner.xcworkspace │ └── contents.xcworkspacedata ├── Runner.xcodeproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ └── project.pbxproj └── .gitignore ├── lib ├── about.dart ├── model.dart ├── appbutton.dart ├── manager.dart ├── load.dart ├── main.dart ├── CupertinoReorderableList.dart └── CupertinoAcitionCard.dart ├── images └── background.png ├── android ├── gradle.properties ├── .gitignore ├── 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 │ │ │ │ ├── values │ │ │ │ │ └── styles.xml │ │ │ │ └── drawable │ │ │ │ │ └── launch_background.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── oboard │ │ │ │ │ └── dashboard │ │ │ │ │ └── MainActivity.kt │ │ │ └── AndroidManifest.xml │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ └── profile │ │ │ └── AndroidManifest.xml │ └── build.gradle ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties ├── settings.gradle └── build.gradle ├── windows └── flutter │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── ephemeral │ └── Generated.props ├── .metadata ├── README.md ├── .gitignore ├── pubspec.yaml └── pubspec.lock /ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" -------------------------------------------------------------------------------- /lib/about.dart: -------------------------------------------------------------------------------- 1 | //https://hitokoto.cn 一言 2 | //https://www.dailypics.cn 图鉴 -------------------------------------------------------------------------------- /images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/images/background.png -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.enableR8=true 3 | android.useAndroidX=true 4 | android.enableJetifier=true 5 | -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/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/oboard/dashboard/master/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oboard/dashboard/master/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/oboard/dashboard/master/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #include "generated_plugin_registrant.h" 6 | 7 | 8 | void RegisterPlugins(flutter::PluginRegistry* registry) { 9 | } 10 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lib/model.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/cupertino.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class Model { 5 | const Model(this.title, this.children, this.id); 6 | 7 | final String title; 8 | final List children; 9 | final String id; 10 | } 11 | -------------------------------------------------------------------------------- /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-5.6.2-all.zip 7 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 2de1e4f4a1e1cd3fb538fbb686705be7c0bade17 8 | channel: master 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void RegisterPlugins(flutter::PluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /android/app/src/main/kotlin/com/oboard/dashboard/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.oboard.dashboard 2 | 3 | import android.os.Bundle 4 | 5 | import io.flutter.app.FlutterActivity 6 | import io.flutter.plugins.GeneratedPluginRegistrant 7 | 8 | class MainActivity: FlutterActivity() { 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | super.onCreate(savedInstanceState) 11 | GeneratedPluginRegistrant.registerWith(this) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 4 | 5 | def plugins = new Properties() 6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') 7 | if (pluginsFile.exists()) { 8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } 9 | } 10 | 11 | plugins.each { name, path -> 12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() 13 | include ":$name" 14 | project(":$name").projectDir = pluginDirectory 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dashboard 2 | 3 | A interesting dashboard for flutter 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Generated.xcconfig 20 | Flutter/app.flx 21 | Flutter/app.zip 22 | Flutter/flutter_assets/ 23 | Flutter/flutter_export_environment.sh 24 | ServiceDefinitions.json 25 | Runner/GeneratedPluginRegistrant.* 26 | 27 | # Exceptions to above rules. 28 | !default.mode1v3 29 | !default.mode2v3 30 | !default.pbxuser 31 | !default.perspectivev3 32 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.5.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .packages 28 | .pub-cache/ 29 | .pub/ 30 | /build/ 31 | 32 | # Web related 33 | lib/generated_plugin_registrant.dart 34 | 35 | # Exceptions to above rules. 36 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 37 | -------------------------------------------------------------------------------- /lib/appbutton.dart: -------------------------------------------------------------------------------- 1 | import 'package:dashboard/load.dart'; 2 | import 'package:flutter/cupertino.dart'; 3 | import 'manager.dart'; 4 | 5 | class AppButton extends StatelessWidget { 6 | final Widget image; 7 | final Widget title; 8 | final String id; 9 | 10 | const AppButton({Key key, this.image, this.title, this.id}) : super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return CupertinoButton( 15 | child: Column( 16 | children: [ 17 | image, 18 | title, 19 | ], 20 | ), 21 | onPressed: () async { 22 | loadId(id); 23 | Manager() 24 | .writeShared('list', await Manager().readShared('list') + ';' + id); 25 | eventBus.fire('closeMenu'); 26 | }, 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/manager.dart: -------------------------------------------------------------------------------- 1 | import 'package:event_bus/event_bus.dart'; 2 | import 'package:shared_preferences/shared_preferences.dart'; 3 | 4 | /// 创建EventBus 5 | EventBus eventBus = EventBus(); 6 | 7 | class Manager{ 8 | Future writeShared(String key,String value) async { 9 | SharedPreferences preferences = await SharedPreferences.getInstance(); 10 | preferences.setString(key, value); 11 | } 12 | 13 | /* 14 | * 读取数据 15 | */ 16 | Future readShared(String key) async { 17 | SharedPreferences preferences = await SharedPreferences.getInstance(); 18 | return preferences.get(key); 19 | } 20 | 21 | /* 22 | * 删除数据 23 | */ 24 | Future removeShared(String key) async { 25 | SharedPreferences preferences = await SharedPreferences.getInstance(); 26 | preferences.remove(key); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /windows/flutter/ephemeral/Generated.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | D:\flutter 6 | C:\Users\admin\StudioProjects\dashboard\windows\flutter\ephemeral 7 | C:\Users\admin\StudioProjects\dashboard 8 | true 9 | C:\Users\admin\StudioProjects\dashboard\lib\main.dart 10 | 11 | 12 | 13 | 14 | 15 | $(FLUTTER_ROOT) 16 | true 17 | 18 | 19 | $(FLUTTER_EPHEMERAL_DIR) 20 | true 21 | 22 | 23 | $(PROJECT_DIR) 24 | true 25 | 26 | 27 | $(TRACK_WIDGET_CREATION) 28 | true 29 | 30 | 31 | $(FLUTTER_TARGET) 32 | true 33 | 34 | 35 | -------------------------------------------------------------------------------- /ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | dashboard 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 13 | 20 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /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 28 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | 35 | lintOptions { 36 | disable 'InvalidPackage' 37 | } 38 | 39 | defaultConfig { 40 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 41 | applicationId "com.oboard.dashboard" 42 | minSdkVersion 16 43 | targetSdkVersion 28 44 | versionCode flutterVersionCode.toInteger() 45 | versionName flutterVersionName 46 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 47 | } 48 | 49 | buildTypes { 50 | release { 51 | // TODO: Add your own signing config for the release build. 52 | // Signing with the debug keys for now, so `flutter run --release` works. 53 | signingConfig signingConfigs.debug 54 | } 55 | } 56 | } 57 | 58 | flutter { 59 | source '../..' 60 | } 61 | 62 | dependencies { 63 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 64 | testImplementation 'junit:junit:4.12' 65 | androidTestImplementation 'androidx.test:runner:1.1.1' 66 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 67 | } 68 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: dashboard 2 | description: A interesting dashboard for flutter 3 | 4 | # The following defines the version and build number for your application. 5 | # A version number is three numbers separated by dots, like 1.2.43 6 | # followed by an optional build number separated by a +. 7 | # Both the version and the builder number may be overridden in flutter 8 | # build by specifying --build-name and --build-number, respectively. 9 | # In Android, build-name is used as versionName while build-number used as versionCode. 10 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 11 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 12 | # Read more about iOS versioning at 13 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 14 | version: 1.0.0+1 15 | 16 | environment: 17 | sdk: ">=2.1.0 <3.0.0" 18 | 19 | dependencies: 20 | flutter: 21 | sdk: flutter 22 | share: ^0.6.1+1 23 | 24 | # The following adds the Cupertino Icons font to your application. 25 | # Use with the CupertinoIcons class for iOS style icons. 26 | cupertino_icons: ^0.1.2 27 | shared_preferences: ^0.4.2 28 | event_bus: ^1.1.0 29 | 30 | dev_dependencies: 31 | flutter_test: 32 | sdk: flutter 33 | 34 | 35 | # For information on the generic Dart part of this file, see the 36 | # following page: https://dart.dev/tools/pub/pubspec 37 | 38 | # The following section is specific to Flutter. 39 | flutter: 40 | 41 | # The following line ensures that the Material Icons font is 42 | # included with your application, so that you can use the icons in 43 | # the material Icons class. 44 | uses-material-design: true 45 | assets: 46 | - images/background.png 47 | # To add assets to your application, add an assets section, like this: 48 | # assets: 49 | # - images/a_dot_burr.jpeg 50 | # - images/a_dot_ham.jpeg 51 | 52 | # An image asset can refer to one or more resolution-specific "variants", see 53 | # https://flutter.dev/assets-and-images/#resolution-aware. 54 | 55 | # For details regarding adding assets from package dependencies, see 56 | # https://flutter.dev/assets-and-images/#from-packages 57 | 58 | # To add custom fonts to your application, add a fonts section here, 59 | # in this "flutter" section. Each entry in this list should have a 60 | # "family" key with the font family name, and a "fonts" key with a 61 | # list giving the asset and other descriptors for the font. For 62 | # example: 63 | # fonts: 64 | # - family: Schyler 65 | # fonts: 66 | # - asset: fonts/Schyler-Regular.ttf 67 | # - asset: fonts/Schyler-Italic.ttf 68 | # style: italic 69 | # - family: Trajan Pro 70 | # fonts: 71 | # - asset: fonts/TrajanPro.ttf 72 | # - asset: fonts/TrajanPro_Bold.ttf 73 | # weight: 700 74 | # 75 | # For details regarding fonts from package dependencies, 76 | # see https://flutter.dev/custom-fonts/#from-packages 77 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | archive: 5 | dependency: transitive 6 | description: 7 | name: archive 8 | url: "https://pub.flutter-io.cn" 9 | source: hosted 10 | version: "2.0.10" 11 | args: 12 | dependency: transitive 13 | description: 14 | name: args 15 | url: "https://pub.flutter-io.cn" 16 | source: hosted 17 | version: "1.5.2" 18 | async: 19 | dependency: transitive 20 | description: 21 | name: async 22 | url: "https://pub.flutter-io.cn" 23 | source: hosted 24 | version: "2.3.0" 25 | boolean_selector: 26 | dependency: transitive 27 | description: 28 | name: boolean_selector 29 | url: "https://pub.flutter-io.cn" 30 | source: hosted 31 | version: "1.0.5" 32 | charcode: 33 | dependency: transitive 34 | description: 35 | name: charcode 36 | url: "https://pub.flutter-io.cn" 37 | source: hosted 38 | version: "1.1.2" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.flutter-io.cn" 44 | source: hosted 45 | version: "1.14.11" 46 | convert: 47 | dependency: transitive 48 | description: 49 | name: convert 50 | url: "https://pub.flutter-io.cn" 51 | source: hosted 52 | version: "2.1.1" 53 | crypto: 54 | dependency: transitive 55 | description: 56 | name: crypto 57 | url: "https://pub.flutter-io.cn" 58 | source: hosted 59 | version: "2.1.3" 60 | cupertino_icons: 61 | dependency: "direct main" 62 | description: 63 | name: cupertino_icons 64 | url: "https://pub.flutter-io.cn" 65 | source: hosted 66 | version: "0.1.2" 67 | event_bus: 68 | dependency: "direct main" 69 | description: 70 | name: event_bus 71 | url: "https://pub.flutter-io.cn" 72 | source: hosted 73 | version: "1.1.0" 74 | flutter: 75 | dependency: "direct main" 76 | description: flutter 77 | source: sdk 78 | version: "0.0.0" 79 | flutter_test: 80 | dependency: "direct dev" 81 | description: flutter 82 | source: sdk 83 | version: "0.0.0" 84 | image: 85 | dependency: transitive 86 | description: 87 | name: image 88 | url: "https://pub.flutter-io.cn" 89 | source: hosted 90 | version: "2.1.4" 91 | matcher: 92 | dependency: transitive 93 | description: 94 | name: matcher 95 | url: "https://pub.flutter-io.cn" 96 | source: hosted 97 | version: "0.12.5" 98 | meta: 99 | dependency: transitive 100 | description: 101 | name: meta 102 | url: "https://pub.flutter-io.cn" 103 | source: hosted 104 | version: "1.1.7" 105 | path: 106 | dependency: transitive 107 | description: 108 | name: path 109 | url: "https://pub.flutter-io.cn" 110 | source: hosted 111 | version: "1.6.4" 112 | pedantic: 113 | dependency: transitive 114 | description: 115 | name: pedantic 116 | url: "https://pub.flutter-io.cn" 117 | source: hosted 118 | version: "1.8.0+1" 119 | petitparser: 120 | dependency: transitive 121 | description: 122 | name: petitparser 123 | url: "https://pub.flutter-io.cn" 124 | source: hosted 125 | version: "2.4.0" 126 | quiver: 127 | dependency: transitive 128 | description: 129 | name: quiver 130 | url: "https://pub.flutter-io.cn" 131 | source: hosted 132 | version: "2.0.5" 133 | share: 134 | dependency: "direct main" 135 | description: 136 | name: share 137 | url: "https://pub.flutter-io.cn" 138 | source: hosted 139 | version: "0.6.2+1" 140 | shared_preferences: 141 | dependency: "direct main" 142 | description: 143 | name: shared_preferences 144 | url: "https://pub.flutter-io.cn" 145 | source: hosted 146 | version: "0.4.3" 147 | sky_engine: 148 | dependency: transitive 149 | description: flutter 150 | source: sdk 151 | version: "0.0.99" 152 | source_span: 153 | dependency: transitive 154 | description: 155 | name: source_span 156 | url: "https://pub.flutter-io.cn" 157 | source: hosted 158 | version: "1.5.5" 159 | stack_trace: 160 | dependency: transitive 161 | description: 162 | name: stack_trace 163 | url: "https://pub.flutter-io.cn" 164 | source: hosted 165 | version: "1.9.3" 166 | stream_channel: 167 | dependency: transitive 168 | description: 169 | name: stream_channel 170 | url: "https://pub.flutter-io.cn" 171 | source: hosted 172 | version: "2.0.0" 173 | string_scanner: 174 | dependency: transitive 175 | description: 176 | name: string_scanner 177 | url: "https://pub.flutter-io.cn" 178 | source: hosted 179 | version: "1.0.5" 180 | term_glyph: 181 | dependency: transitive 182 | description: 183 | name: term_glyph 184 | url: "https://pub.flutter-io.cn" 185 | source: hosted 186 | version: "1.1.0" 187 | test_api: 188 | dependency: transitive 189 | description: 190 | name: test_api 191 | url: "https://pub.flutter-io.cn" 192 | source: hosted 193 | version: "0.2.5" 194 | typed_data: 195 | dependency: transitive 196 | description: 197 | name: typed_data 198 | url: "https://pub.flutter-io.cn" 199 | source: hosted 200 | version: "1.1.6" 201 | vector_math: 202 | dependency: transitive 203 | description: 204 | name: vector_math 205 | url: "https://pub.flutter-io.cn" 206 | source: hosted 207 | version: "2.0.8" 208 | xml: 209 | dependency: transitive 210 | description: 211 | name: xml 212 | url: "https://pub.flutter-io.cn" 213 | source: hosted 214 | version: "3.5.0" 215 | sdks: 216 | dart: ">=2.4.0 <3.0.0" 217 | flutter: ">=1.6.0 <2.0.0" 218 | -------------------------------------------------------------------------------- /lib/load.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | import 'dart:math'; 4 | 5 | import 'package:flutter/cupertino.dart'; 6 | import 'package:flutter/material.dart'; 7 | import 'package:flutter/services.dart'; 8 | import 'package:flutter/widgets.dart'; 9 | import 'package:share/share.dart'; 10 | 11 | import 'CupertinoAcitionCard.dart'; 12 | import 'main.dart'; 13 | import 'manager.dart'; 14 | import 'model.dart'; 15 | 16 | Future loadList() async { 17 | what = await Manager().readShared("list"); 18 | print(what); 19 | if (what == null || what.indexOf(';') == -1) { 20 | what = 'yiyan;tujian;'; 21 | Manager().writeShared('list', what); 22 | } 23 | List whats = what.split(';'); 24 | for (String w in whats) { 25 | loadId(w); 26 | } 27 | } 28 | 29 | loadId(String w) async { 30 | Model m; 31 | switch (w) { 32 | case 'tujian': 33 | m = await loadTujian(); 34 | break; 35 | case 'yiyan': 36 | m = await loadAsentence(); 37 | break; 38 | case 'bingpic': 39 | m = await loadBingPic(); 40 | break; 41 | } 42 | int i = items.length; 43 | Dismissible d = Dismissible( 44 | key: ObjectKey(Random().nextInt(10000)), 45 | child: CupertinoActionCard( 46 | title: new Text(m.title), 47 | actions: m.children, 48 | ), 49 | onDismissed: (DismissDirection direction) async { 50 | items.removeAt(i); 51 | String list = await Manager().readShared('list'); 52 | int index = list.indexOf(m.id); 53 | list = list.substring(0, index) + list.substring(index + m.id.length + 1); 54 | Manager().writeShared('list', list); 55 | }, 56 | ); 57 | items.add(d); 58 | eventBus.fire('setState'); 59 | } 60 | 61 | Future loadUrl(String url) async { 62 | String a = url; 63 | HttpClient httpClient = new HttpClient(); 64 | HttpClientRequest request = await httpClient.getUrl(Uri.parse(a)); 65 | HttpClientResponse response = await request.close(); 66 | a = await response.transform(utf8.decoder).join(); 67 | httpClient.close(); 68 | return a; 69 | } 70 | 71 | Future loadTujian() async { 72 | String tujian = await loadUrl("https://v2.api.dailypics.cn/today"); 73 | tujian = tujian.replaceAll("\"", ""); 74 | tujian = tujian.replaceAll(",", ""); 75 | tujian = tujian.replaceAll(":", ""); 76 | tujian = tujian.replaceAll("\\r\\n", "\n"); 77 | tujian = tujian.replaceAll("\\/\\/", ""); 78 | String picTitle = tujian.split("p_title")[1].split("p_content")[0]; 79 | String picLink = tujian 80 | .split("local_url")[1] 81 | .split("TID")[0] 82 | .replaceAll("https", "https://") 83 | .replaceAll("\\/", "/"); 84 | String picContent = tujian.split("p_content")[1].split("width")[0]; 85 | Model m = Model( 86 | "图鉴日图", 87 | [ 88 | Stack( 89 | children: [ 90 | Image.network(picLink), 91 | Column( 92 | children: [ 93 | Padding( 94 | padding: const EdgeInsets.fromLTRB(16.0, 32.0, 16.0, 16.0), 95 | child: Column( 96 | crossAxisAlignment: CrossAxisAlignment.start, 97 | children: [ 98 | Text( 99 | picTitle, 100 | style: TextStyle( 101 | color: Colors.white, 102 | fontSize: 40, 103 | shadows: [ 104 | Shadow( 105 | color: Colors.black, 106 | blurRadius: 30, 107 | ), 108 | ], 109 | ), 110 | ), 111 | Align( 112 | alignment: Alignment.bottomLeft, 113 | child: Text( 114 | picContent, 115 | style: TextStyle( 116 | color: Color.fromARGB(200, 255, 255, 255), 117 | fontSize: 15, 118 | shadows: [ 119 | Shadow( 120 | color: Colors.black, 121 | blurRadius: 30, 122 | ), 123 | ], 124 | ), 125 | ), 126 | ), 127 | ], 128 | ), 129 | ), 130 | ], 131 | ), 132 | ], 133 | ), 134 | Row( 135 | children: [ 136 | Expanded( 137 | child: CupertinoButton( 138 | child: Text("复制图片链接"), 139 | onPressed: () { 140 | Clipboard.setData(new ClipboardData(text: picLink)); 141 | }, 142 | ), 143 | ), 144 | ], 145 | ), 146 | ], 147 | 'tujian'); 148 | return m; 149 | } 150 | 151 | Future loadBingPic() async { 152 | String bingpic = await loadUrl("https://bing.biturl.top/"); 153 | bingpic = bingpic.replaceAll("\":\"", ""); 154 | bingpic = bingpic.replaceAll("\",\"", ""); 155 | bingpic = bingpic.replaceAll("\\r\\n", "\n"); 156 | bingpic = bingpic.replaceAll(",", ""); 157 | String picLink = bingpic.split("url")[1].split("copyright")[0]; 158 | String picContent = bingpic.split("copyright")[1].split("copyright_link")[0]; 159 | Model m = Model( 160 | "必应日图", 161 | [ 162 | Stack( 163 | children: [ 164 | Image.network(picLink), 165 | Column( 166 | children: [ 167 | Padding( 168 | padding: const EdgeInsets.fromLTRB(16.0, 32.0, 16.0, 16.0), 169 | child: Column( 170 | crossAxisAlignment: CrossAxisAlignment.start, 171 | children: [ 172 | Align( 173 | alignment: Alignment.bottomLeft, 174 | child: Text( 175 | picContent, 176 | style: TextStyle( 177 | color: Color.fromARGB(200, 255, 255, 255), 178 | fontSize: 15, 179 | shadows: [ 180 | Shadow( 181 | color: Colors.black, 182 | blurRadius: 30, 183 | ), 184 | ], 185 | ), 186 | ), 187 | ), 188 | ], 189 | ), 190 | ), 191 | ], 192 | ), 193 | ], 194 | ), 195 | Row( 196 | children: [ 197 | Expanded( 198 | child: CupertinoButton( 199 | child: Text("复制图片链接"), 200 | onPressed: () { 201 | Clipboard.setData(new ClipboardData(text: picLink)); 202 | }, 203 | ), 204 | ), 205 | ], 206 | ), 207 | ], 208 | 'bingpic'); 209 | return m; 210 | } 211 | 212 | Future loadAsentence() async { 213 | String asentence = await loadUrl( 214 | "https://api.lwl12.com/hitokoto/v1?encode=text&charset=utf-8"); 215 | 216 | Model m = Model( 217 | "一言", 218 | [ 219 | Padding( 220 | padding: const EdgeInsets.all(16.0), 221 | child: Stack( 222 | children: [ 223 | Text(asentence), 224 | ], 225 | ), 226 | ), 227 | Row( 228 | children: [ 229 | Expanded( 230 | flex: 1, 231 | child: Center( 232 | child: CupertinoButton( 233 | child: Text("复制"), 234 | onPressed: () { 235 | Clipboard.setData(new ClipboardData(text: asentence)); 236 | }, 237 | ), 238 | )), 239 | Expanded( 240 | flex: 1, 241 | child: CupertinoButton( 242 | child: Text("分享"), 243 | onPressed: () async { 244 | Share.share(asentence); 245 | }, 246 | ), 247 | ), 248 | ], 249 | ), 250 | ], 251 | 'yiyan'); 252 | return m; 253 | } 254 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'dart:math'; 3 | import 'dart:ui'; 4 | 5 | import 'package:dashboard/manager.dart'; 6 | import 'package:dashboard/model.dart'; 7 | import 'package:flutter/cupertino.dart'; 8 | import 'package:flutter/material.dart' show Colors, Icons; 9 | import 'package:flutter/services.dart'; 10 | import 'CupertinoAcitionCard.dart'; 11 | import 'CupertinoReorderableList.dart'; 12 | import 'appbutton.dart'; 13 | import 'load.dart'; 14 | import 'manager.dart'; 15 | 16 | List items = new List(); 17 | Brightness brightnessValue = Brightness.light; 18 | 19 | String what; 20 | 21 | void main() { 22 | if (Platform.isAndroid) { 23 | // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后,是为了在渲染后进行set赋值,覆盖状态栏,写在渲染之前MaterialApp组件会覆盖掉这个值。 24 | SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle( 25 | statusBarColor: Colors.transparent, 26 | systemNavigationBarColor: Colors.grey); 27 | SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle); 28 | } 29 | SystemChrome.setPreferredOrientations( 30 | [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); 31 | 32 | runApp(App()); 33 | } 34 | 35 | class App extends StatelessWidget { 36 | @override 37 | Widget build(BuildContext context) { 38 | return CupertinoApp( 39 | title: 'Dashboard', 40 | theme: CupertinoThemeData( 41 | primaryColor: Colors.blue, 42 | primaryContrastingColor: Colors.blueGrey, 43 | brightness: brightnessValue, 44 | ), 45 | home: HomePage(), 46 | ); 47 | } 48 | } 49 | 50 | class HomePage extends StatefulWidget { 51 | HomePage({Key key, this.title}) : super(key: key); 52 | 53 | final String title; 54 | 55 | @override 56 | _HomePageState createState() => _HomePageState(); 57 | } 58 | 59 | class _HomePageState extends State with TickerProviderStateMixin { 60 | AnimationController controller; 61 | Animation animation; 62 | Animation alpha; 63 | bool isMenu = false; 64 | 65 | @override 66 | void initState() { 67 | super.initState(); 68 | controller = new AnimationController( 69 | duration: const Duration(milliseconds: 3000), vsync: this); 70 | animation = new CurvedAnimation(parent: controller, curve: Curves.easeOut); 71 | alpha = new Tween(begin: 255.0, end: 0.0).animate(animation); // 动画 72 | controller.forward(); 73 | alpha.addListener(() { 74 | setState(() {}); 75 | }); 76 | 77 | //关闭菜单的EventBus 78 | //订阅eventbus 79 | eventBus.on().listen((event) { 80 | setState(() { 81 | switch (event.toString()) { 82 | case 'setState': 83 | setState(() { 84 | controller.reverse(); 85 | controller.forward(); 86 | }); 87 | break; 88 | case 'closeMenu': 89 | closeMenu(); 90 | break; 91 | } 92 | }); 93 | }); 94 | 95 | loadList(); 96 | } 97 | 98 | closeMenu() { 99 | isMenu = false; 100 | controller.forward(); 101 | setState(() {}); 102 | alpha.addListener(() { 103 | setState(() {}); 104 | }); 105 | } 106 | 107 | @override 108 | Widget build(BuildContext context) { 109 | setState(() { 110 | brightnessValue = MediaQuery.of(context).platformBrightness; 111 | }); 112 | 113 | ; 114 | return Container( 115 | color: Colors.grey, 116 | child: Stack( 117 | children: [ 118 | ConstrainedBox( 119 | constraints: const BoxConstraints.expand(), 120 | child: Image.network( 121 | "https://api.neweb.top/bing.php?type=rand", 122 | fit: BoxFit.cover, 123 | ), 124 | ), 125 | CupertinoReorderableListView( 126 | children: items.toList(), 127 | onReorder: (int oldIndex, int newIndex) { 128 | setState(() { 129 | if (newIndex == items.length) { 130 | newIndex = items.length - 1; 131 | } 132 | 133 | var temp = items.removeAt(oldIndex); 134 | items.insert(newIndex, temp); 135 | }); 136 | }, 137 | ), 138 | new Align( 139 | alignment: Alignment.bottomCenter, 140 | child: Padding( 141 | padding: const EdgeInsets.all(32.0), 142 | child: ClipOval( 143 | child: BackdropFilter( 144 | filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), 145 | child: Container( 146 | color: CupertinoTheme.of(context) 147 | .barBackgroundColor 148 | .withOpacity(0.3), 149 | child: Row( 150 | mainAxisSize: MainAxisSize.min, 151 | children: [ 152 | CupertinoButton( 153 | child: Icon( 154 | Icons.add, 155 | size: 30, 156 | ), 157 | onPressed: () { 158 | isMenu = true; 159 | controller.duration = Duration(milliseconds: 300); 160 | controller.reverse(); 161 | setState(() {}); 162 | alpha.addListener(() { 163 | setState(() {}); 164 | }); 165 | }, 166 | ), 167 | ], 168 | ), 169 | ), 170 | ), 171 | ), 172 | ), 173 | ), 174 | Visibility( 175 | visible: alpha.value >= 0.1, 176 | child: BackdropFilter( 177 | filter: ImageFilter.blur( 178 | sigmaX: alpha.value / 255 * 50, 179 | sigmaY: alpha.value / 255 * 50), 180 | child: Container( 181 | color: CupertinoTheme.of(context) 182 | .barBackgroundColor 183 | .withAlpha(100), 184 | )), 185 | ), 186 | Visibility( 187 | visible: isMenu, 188 | child: Opacity( 189 | opacity: alpha.value / 255, 190 | child: Transform.scale( 191 | scale: 1.5 - alpha.value / 255 / 2, 192 | child: Stack( 193 | children: [ 194 | Center( 195 | child: GridView.count( 196 | //水平子Widget之间间距 197 | crossAxisSpacing: 10.0, 198 | //垂直子Widget之间间距 199 | mainAxisSpacing: 10.0, 200 | //一行的Widget数量 201 | crossAxisCount: 1, 202 | childAspectRatio: 3, 203 | children: [ 204 | AppButton( 205 | image: Image.network( 206 | "https://www.dailypics.cn/static/assets/images/favicon.ico", 207 | height: 64, 208 | ), 209 | title: Text("图鉴日图"), 210 | id: 'tujian', 211 | ), 212 | AppButton( 213 | image: Image.network( 214 | "https://hitokoto.cn/favicon.ico", 215 | height: 64, 216 | ), 217 | title: Text("一言"), 218 | id: 'yiyan', 219 | ), 220 | AppButton( 221 | image: Image.network( 222 | "https://vignette.wikia.nocookie.net/logopedia/images/0/09/Bing-2.png/revision/latest/scale-to-width-down/220?cb=20160504230420", 223 | height: 64, 224 | ), 225 | title: Text("必应日图"), 226 | id: 'bingpic', 227 | ), 228 | ], 229 | ), 230 | ), 231 | new Align( 232 | alignment: Alignment.bottomCenter, 233 | child: Padding( 234 | padding: const EdgeInsets.all(32.0), 235 | child: ClipOval( 236 | child: BackdropFilter( 237 | filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), 238 | child: Container( 239 | color: CupertinoTheme.of(context) 240 | .barBackgroundColor 241 | .withOpacity(0.3), 242 | child: Row( 243 | mainAxisSize: MainAxisSize.min, 244 | children: [ 245 | CupertinoButton( 246 | child: Icon( 247 | Icons.close, 248 | size: 30, 249 | ), 250 | onPressed: () => closeMenu(), 251 | ), 252 | ], 253 | ), 254 | ), 255 | ), 256 | ), 257 | ), 258 | ), 259 | ], 260 | ), 261 | ), 262 | ), 263 | ), 264 | ], 265 | ), 266 | ); 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /lib/CupertinoReorderableList.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'dart:math'; 6 | 7 | import 'package:flutter/foundation.dart'; 8 | import 'package:flutter/rendering.dart'; 9 | import 'package:flutter/widgets.dart'; 10 | 11 | import 'package:flutter/cupertino.dart'; 12 | 13 | // Examples can assume: 14 | // class MyDataObject { } 15 | 16 | /// The callback used by [CupertinoReorderableListView] to move an item to a new 17 | /// position in a list. 18 | /// 19 | /// Implementations should remove the corresponding list item at [oldIndex] 20 | /// and reinsert it at [newIndex]. 21 | /// 22 | /// If [oldIndex] is before [newIndex], removing the item at [oldIndex] from the 23 | /// list will reduce the list's length by one. Implementations used by 24 | /// [CupertinoReorderableListView] will need to account for this when inserting before 25 | /// [newIndex]. 26 | /// 27 | /// {@youtube 560 315 https://www.youtube.com/watch?v=3fB1mxOsqJE} 28 | /// 29 | /// {@tool sample} 30 | /// 31 | /// ```dart 32 | /// final List backingList = [/* ... */]; 33 | /// 34 | /// void handleReorder(int oldIndex, int newIndex) { 35 | /// if (oldIndex < newIndex) { 36 | /// // removing the item at oldIndex will shorten the list by 1. 37 | /// newIndex -= 1; 38 | /// } 39 | /// final MyDataObject element = backingList.removeAt(oldIndex); 40 | /// backingList.insert(newIndex, element); 41 | /// } 42 | /// ``` 43 | /// {@end-tool} 44 | typedef ReorderCallback = void Function(int oldIndex, int newIndex); 45 | 46 | /// A list whose items the user can interactively reorder by dragging. 47 | /// 48 | /// This class is appropriate for views with a small number of 49 | /// children because constructing the [List] requires doing work for every 50 | /// child that could possibly be displayed in the list view instead of just 51 | /// those children that are actually visible. 52 | /// 53 | /// All [children] must have a key. 54 | class CupertinoReorderableListView extends StatefulWidget { 55 | /// Creates a reorderable list. 56 | CupertinoReorderableListView({ 57 | this.header, 58 | @required this.children, 59 | @required this.onReorder, 60 | this.scrollDirection = Axis.vertical, 61 | this.padding, 62 | this.reverse = false, 63 | }) : assert(scrollDirection != null), 64 | assert(onReorder != null), 65 | assert(children != null), 66 | assert( 67 | children.every((Widget w) => w.key != null), 68 | 'All children of this widget must have a key.', 69 | ); 70 | 71 | /// A non-reorderable header widget to show before the list. 72 | /// 73 | /// If null, no header will appear before the list. 74 | final Widget header; 75 | 76 | /// The widgets to display. 77 | final List children; 78 | 79 | /// The [Axis] along which the list scrolls. 80 | /// 81 | /// List [children] can only drag along this [Axis]. 82 | final Axis scrollDirection; 83 | 84 | /// The amount of space by which to inset the [children]. 85 | final EdgeInsets padding; 86 | 87 | /// Whether the scroll view scrolls in the reading direction. 88 | /// 89 | /// For example, if the reading direction is left-to-right and 90 | /// [scrollDirection] is [Axis.horizontal], then the scroll view scrolls from 91 | /// left to right when [reverse] is false and from right to left when 92 | /// [reverse] is true. 93 | /// 94 | /// Similarly, if [scrollDirection] is [Axis.vertical], then the scroll view 95 | /// scrolls from top to bottom when [reverse] is false and from bottom to top 96 | /// when [reverse] is true. 97 | /// 98 | /// Defaults to false. 99 | final bool reverse; 100 | 101 | /// Called when a list child is dropped into a new position to shuffle the 102 | /// underlying list. 103 | /// 104 | /// This [CupertinoReorderableListView] calls [onReorder] after a list child is dropped 105 | /// into a new position. 106 | final ReorderCallback onReorder; 107 | 108 | @override 109 | _CupertinoReorderableListViewState createState() => 110 | _CupertinoReorderableListViewState(); 111 | } 112 | 113 | // This top-level state manages an Overlay that contains the list and 114 | // also any Draggables it creates. 115 | // 116 | // _CupertinoReorderableListContent manages the list itself and reorder operations. 117 | // 118 | // The Overlay doesn't properly keep state by building new overlay entries, 119 | // and so we cache a single OverlayEntry for use as the list layer. 120 | // That overlay entry then builds a _CupertinoReorderableListContent which may 121 | // insert Draggables into the Overlay above itself. 122 | class _CupertinoReorderableListViewState 123 | extends State { 124 | // We use an inner overlay so that the dragging list item doesn't draw outside of the list itself. 125 | final GlobalKey _overlayKey = 126 | GlobalKey(debugLabel: '$CupertinoReorderableListView overlay key'); 127 | 128 | // This entry contains the scrolling list itself. 129 | OverlayEntry _listOverlayEntry; 130 | 131 | @override 132 | void initState() { 133 | super.initState(); 134 | _listOverlayEntry = OverlayEntry( 135 | opaque: true, 136 | builder: (BuildContext context) { 137 | return _CupertinoReorderableListContent( 138 | header: widget.header, 139 | children: widget.children, 140 | scrollDirection: widget.scrollDirection, 141 | onReorder: widget.onReorder, 142 | padding: widget.padding, 143 | reverse: widget.reverse, 144 | ); 145 | }, 146 | ); 147 | } 148 | 149 | @override 150 | Widget build(BuildContext context) { 151 | return Overlay(key: _overlayKey, initialEntries: [ 152 | _listOverlayEntry, 153 | ]); 154 | } 155 | } 156 | 157 | // This widget is responsible for the inside of the Overlay in the 158 | // CupertinoReorderableListView. 159 | class _CupertinoReorderableListContent extends StatefulWidget { 160 | const _CupertinoReorderableListContent({ 161 | @required this.header, 162 | @required this.children, 163 | @required this.scrollDirection, 164 | @required this.padding, 165 | @required this.onReorder, 166 | @required this.reverse, 167 | }); 168 | 169 | final Widget header; 170 | final List children; 171 | final Axis scrollDirection; 172 | final EdgeInsets padding; 173 | final ReorderCallback onReorder; 174 | final bool reverse; 175 | 176 | @override 177 | _CupertinoReorderableListContentState createState() => 178 | _CupertinoReorderableListContentState(); 179 | } 180 | 181 | class _CupertinoReorderableListContentState 182 | extends State<_CupertinoReorderableListContent> 183 | with TickerProviderStateMixin<_CupertinoReorderableListContent> { 184 | // The extent along the [widget.scrollDirection] axis to allow a child to 185 | // drop into when the user reorders list children. 186 | // 187 | // This value is used when the extents haven't yet been calculated from 188 | // the currently dragging widget, such as when it first builds. 189 | static const double _defaultDropAreaExtent = 100.0; 190 | 191 | // The additional margin to place around a computed drop area. 192 | static const double _dropAreaMargin = 8.0; 193 | 194 | // How long an animation to reorder an element in the list takes. 195 | static const Duration _reorderAnimationDuration = Duration(milliseconds: 200); 196 | 197 | // How long an animation to scroll to an off-screen element in the 198 | // list takes. 199 | static const Duration _scrollAnimationDuration = Duration(milliseconds: 200); 200 | 201 | // Controls scrolls and measures scroll progress. 202 | ScrollController _scrollController; 203 | 204 | // This controls the entrance of the dragging widget into a new place. 205 | AnimationController _entranceController; 206 | 207 | // This controls the 'ghost' of the dragging widget, which is left behind 208 | // where the widget used to be. 209 | AnimationController _ghostController; 210 | 211 | // The member of widget.children currently being dragged. 212 | // 213 | // Null if no drag is underway. 214 | Key _dragging; 215 | 216 | // The last computed size of the feedback widget being dragged. 217 | Size _draggingFeedbackSize; 218 | 219 | // The location that the dragging widget occupied before it started to drag. 220 | int _dragStartIndex = 0; 221 | 222 | // The index that the dragging widget most recently left. 223 | // This is used to show an animation of the widget's position. 224 | int _ghostIndex = 0; 225 | 226 | // The index that the dragging widget currently occupies. 227 | int _currentIndex = 0; 228 | 229 | // The widget to move the dragging widget too after the current index. 230 | int _nextIndex = 0; 231 | 232 | // Whether or not we are currently scrolling this view to show a widget. 233 | bool _scrolling = false; 234 | 235 | double get _dropAreaExtent { 236 | if (_draggingFeedbackSize == null) { 237 | return _defaultDropAreaExtent; 238 | } 239 | double dropAreaWithoutMargin; 240 | switch (widget.scrollDirection) { 241 | case Axis.horizontal: 242 | dropAreaWithoutMargin = _draggingFeedbackSize.width; 243 | break; 244 | case Axis.vertical: 245 | default: 246 | dropAreaWithoutMargin = _draggingFeedbackSize.height; 247 | break; 248 | } 249 | return dropAreaWithoutMargin + _dropAreaMargin; 250 | } 251 | 252 | @override 253 | void initState() { 254 | super.initState(); 255 | _entranceController = 256 | AnimationController(vsync: this, duration: _reorderAnimationDuration); 257 | _ghostController = 258 | AnimationController(vsync: this, duration: _reorderAnimationDuration); 259 | _entranceController.addStatusListener(_onEntranceStatusChanged); 260 | } 261 | 262 | @override 263 | void didChangeDependencies() { 264 | _scrollController = 265 | PrimaryScrollController.of(context) ?? ScrollController(); 266 | super.didChangeDependencies(); 267 | } 268 | 269 | @override 270 | void dispose() { 271 | _entranceController.dispose(); 272 | _ghostController.dispose(); 273 | super.dispose(); 274 | } 275 | 276 | // Animates the droppable space from _currentIndex to _nextIndex. 277 | void _requestAnimationToNextIndex() { 278 | if (_entranceController.isCompleted) { 279 | _ghostIndex = _currentIndex; 280 | if (_nextIndex == _currentIndex) { 281 | return; 282 | } 283 | _currentIndex = _nextIndex; 284 | _ghostController.reverse(from: 1.0); 285 | _entranceController.forward(from: 0.0); 286 | } 287 | } 288 | 289 | // Requests animation to the latest next index if it changes during an animation. 290 | void _onEntranceStatusChanged(AnimationStatus status) { 291 | if (status == AnimationStatus.completed) { 292 | setState(() { 293 | _requestAnimationToNextIndex(); 294 | }); 295 | } 296 | } 297 | 298 | // Scrolls to a target context if that context is not on the screen. 299 | void _scrollTo(BuildContext context) { 300 | if (_scrolling) return; 301 | final RenderObject contextObject = context.findRenderObject(); 302 | final RenderAbstractViewport viewport = 303 | RenderAbstractViewport.of(contextObject); 304 | assert(viewport != null); 305 | // If and only if the current scroll offset falls in-between the offsets 306 | // necessary to reveal the selected context at the top or bottom of the 307 | // screen, then it is already on-screen. 308 | final double margin = _dropAreaExtent; 309 | final double scrollOffset = _scrollController.offset; 310 | final double topOffset = max( 311 | _scrollController.position.minScrollExtent, 312 | viewport.getOffsetToReveal(contextObject, 0.0).offset - margin, 313 | ); 314 | final double bottomOffset = min( 315 | _scrollController.position.maxScrollExtent, 316 | viewport.getOffsetToReveal(contextObject, 1.0).offset + margin, 317 | ); 318 | final bool onScreen = 319 | scrollOffset <= topOffset && scrollOffset >= bottomOffset; 320 | 321 | // If the context is off screen, then we request a scroll to make it visible. 322 | if (!onScreen) { 323 | _scrolling = true; 324 | _scrollController.position 325 | .animateTo( 326 | scrollOffset < bottomOffset ? bottomOffset : topOffset, 327 | duration: _scrollAnimationDuration, 328 | curve: Curves.easeInOut, 329 | ) 330 | .then((void value) { 331 | setState(() { 332 | _scrolling = false; 333 | }); 334 | }); 335 | } 336 | } 337 | 338 | // Wraps children in Row or Column, so that the children flow in 339 | // the widget's scrollDirection. 340 | Widget _buildContainerForScrollDirection({List children}) { 341 | switch (widget.scrollDirection) { 342 | case Axis.horizontal: 343 | return Row(children: children); 344 | case Axis.vertical: 345 | default: 346 | return Column(children: children); 347 | } 348 | } 349 | 350 | // Wraps one of the widget's children in a DragTarget and Draggable. 351 | // Handles up the logic for dragging and reordering items in the list. 352 | Widget _wrap(Widget toWrap, int index, BoxConstraints constraints) { 353 | assert(toWrap.key != null); 354 | final _ScopedValueGlobalKey<_CupertinoReorderableListContentState> 355 | keyIndexGlobalKey = 356 | _ScopedValueGlobalKey<_CupertinoReorderableListContentState>( 357 | scope: this, 358 | value: toWrap.key, 359 | ); 360 | // We pass the toWrapWithGlobalKey into the Draggable so that when a list 361 | // item gets dragged, the accessibility framework can preserve the selected 362 | // state of the dragging item. 363 | 364 | // Starts dragging toWrap. 365 | void onDragStarted() { 366 | setState(() { 367 | _dragging = toWrap.key; 368 | _dragStartIndex = index; 369 | _ghostIndex = index; 370 | _currentIndex = index; 371 | _entranceController.value = 1.0; 372 | _draggingFeedbackSize = keyIndexGlobalKey.currentContext.size; 373 | }); 374 | } 375 | 376 | // Places the value from startIndex one space before the element at endIndex. 377 | void reorder(int startIndex, int endIndex) { 378 | setState(() { 379 | if (startIndex != endIndex) widget.onReorder(startIndex, endIndex); 380 | // Animates leftover space in the drop area closed. 381 | // TODO(djshuckerow): bring the animation in line with the Material 382 | // specifications. 383 | _ghostController.reverse(from: 0.1); 384 | _entranceController.reverse(from: 0.1); 385 | _dragging = null; 386 | }); 387 | } 388 | 389 | // Drops toWrap into the last position it was hovering over. 390 | void onDragEnded() { 391 | reorder(_dragStartIndex, _currentIndex); 392 | } 393 | 394 | Widget wrapWithSemantics() { 395 | // First, determine which semantics actions apply. 396 | final Map semanticsActions = 397 | {}; 398 | // We pass toWrap with a GlobalKey into the Draggable so that when a list 399 | // item gets dragged, the accessibility framework can preserve the selected 400 | // state of the dragging item. 401 | // 402 | // We also apply the relevant custom accessibility actions for moving the item 403 | // up, down, to the start, and to the end of the list. 404 | return KeyedSubtree( 405 | key: keyIndexGlobalKey, 406 | child: MergeSemantics( 407 | child: Semantics( 408 | customSemanticsActions: semanticsActions, 409 | child: toWrap, 410 | ), 411 | ), 412 | ); 413 | } 414 | 415 | Widget buildDragTarget(BuildContext context, List acceptedCandidates, 416 | List rejectedCandidates) { 417 | final Widget toWrapWithSemantics = wrapWithSemantics(); 418 | 419 | // We build the draggable inside of a layout builder so that we can 420 | // constrain the size of the feedback dragging widget. 421 | Widget child = LongPressDraggable( 422 | maxSimultaneousDrags: 1, 423 | axis: widget.scrollDirection, 424 | data: toWrap.key, 425 | ignoringFeedbackSemantics: false, 426 | feedback: Container( 427 | alignment: Alignment.topLeft, 428 | // These constraints will limit the cross axis of the drawn widget. 429 | constraints: constraints, 430 | child: Transform.scale(scale: 1.01, child: toWrapWithSemantics), 431 | ), 432 | child: _dragging == toWrap.key ? const SizedBox() : toWrapWithSemantics, 433 | childWhenDragging: const SizedBox(), 434 | dragAnchor: DragAnchor.child, 435 | onDragStarted: onDragStarted, 436 | // When the drag ends inside a DragTarget widget, the drag 437 | // succeeds, and we reorder the widget into position appropriately. 438 | onDragCompleted: onDragEnded, 439 | // When the drag does not end inside a DragTarget widget, the 440 | // drag fails, but we still reorder the widget to the last position it 441 | // had been dragged to. 442 | onDraggableCanceled: (Velocity velocity, Offset offset) { 443 | onDragEnded(); 444 | }, 445 | ); 446 | 447 | // The target for dropping at the end of the list doesn't need to be 448 | // draggable. 449 | if (index >= widget.children.length) { 450 | child = toWrap; 451 | } 452 | 453 | // Determine the size of the drop area to show under the dragging widget. 454 | Widget spacing; 455 | switch (widget.scrollDirection) { 456 | case Axis.horizontal: 457 | spacing = SizedBox(width: _dropAreaExtent); 458 | break; 459 | case Axis.vertical: 460 | default: 461 | spacing = SizedBox(height: _dropAreaExtent); 462 | break; 463 | } 464 | 465 | // We open up a space under where the dragging widget currently is to 466 | // show it can be dropped. 467 | if (_currentIndex == index) { 468 | return _buildContainerForScrollDirection(children: [ 469 | SizeTransition( 470 | sizeFactor: _entranceController, 471 | axis: widget.scrollDirection, 472 | child: spacing, 473 | ), 474 | child, 475 | ]); 476 | } 477 | // We close up the space under where the dragging widget previously was 478 | // with the ghostController animation. 479 | if (_ghostIndex == index) { 480 | return _buildContainerForScrollDirection(children: [ 481 | SizeTransition( 482 | sizeFactor: _ghostController, 483 | axis: widget.scrollDirection, 484 | child: spacing, 485 | ), 486 | child, 487 | ]); 488 | } 489 | return child; 490 | } 491 | 492 | // We wrap the drag target in a Builder so that we can scroll to its specific context. 493 | return Builder(builder: (BuildContext context) { 494 | return DragTarget( 495 | builder: buildDragTarget, 496 | onWillAccept: (Key toAccept) { 497 | setState(() { 498 | _nextIndex = index; 499 | _requestAnimationToNextIndex(); 500 | }); 501 | _scrollTo(context); 502 | // If the target is not the original starting point, then we will accept the drop. 503 | return _dragging == toAccept && toAccept != toWrap.key; 504 | }, 505 | onAccept: (Key accepted) {}, 506 | onLeave: (Key leaving) {}, 507 | ); 508 | }); 509 | } 510 | 511 | @override 512 | Widget build(BuildContext context) { 513 | // We use the layout builder to constrain the cross-axis size of dragging child widgets. 514 | return LayoutBuilder( 515 | builder: (BuildContext context, BoxConstraints constraints) { 516 | const Key endWidgetKey = Key('DraggableList - End Widget'); 517 | Widget finalDropArea; 518 | switch (widget.scrollDirection) { 519 | case Axis.horizontal: 520 | finalDropArea = SizedBox( 521 | key: endWidgetKey, 522 | width: _defaultDropAreaExtent, 523 | height: constraints.maxHeight, 524 | ); 525 | break; 526 | case Axis.vertical: 527 | default: 528 | finalDropArea = SizedBox( 529 | key: endWidgetKey, 530 | height: _defaultDropAreaExtent, 531 | width: constraints.maxWidth, 532 | ); 533 | break; 534 | } 535 | return SingleChildScrollView( 536 | scrollDirection: widget.scrollDirection, 537 | padding: widget.padding, 538 | controller: _scrollController, 539 | reverse: widget.reverse, 540 | child: _buildContainerForScrollDirection( 541 | children: [ 542 | if (widget.reverse) 543 | _wrap(finalDropArea, widget.children.length, constraints), 544 | if (widget.header != null) widget.header, 545 | for (int i = 0; i < widget.children.length; i += 1) 546 | _wrap(widget.children[i], i, constraints), 547 | if (!widget.reverse) 548 | _wrap(finalDropArea, widget.children.length, constraints), 549 | ], 550 | ), 551 | ); 552 | }); 553 | } 554 | } 555 | 556 | /// A [GlobalKey] that uses a scope and a value to determine equality. 557 | /// 558 | /// The scope is compared using [identical], while the value is compared 559 | /// using [operator ==]. This allows a locally scoped value to be turned 560 | /// into a globally unique key. 561 | class _ScopedValueGlobalKey> 562 | extends GlobalKey { 563 | const _ScopedValueGlobalKey({this.scope, this.value}) : super.constructor(); 564 | 565 | final Object scope; 566 | final Object value; 567 | 568 | @override 569 | int get hashCode => hashValues(identityHashCode(scope), value.hashCode); 570 | 571 | @override 572 | bool operator ==(dynamic other) { 573 | if (other.runtimeType != runtimeType) { 574 | return false; 575 | } 576 | final _ScopedValueGlobalKey typedOther = other; 577 | return identical(scope, typedOther.scope) && value == typedOther.value; 578 | } 579 | 580 | @override 581 | String toString() { 582 | return '[$runtimeType ${describeIdentity(scope)} ${describeIdentity(value)}]'; 583 | } 584 | } 585 | -------------------------------------------------------------------------------- /ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 13 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 15 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 16 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 17 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 18 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 19 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXCopyFilesBuildPhase section */ 23 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 24 | isa = PBXCopyFilesBuildPhase; 25 | buildActionMask = 2147483647; 26 | dstPath = ""; 27 | dstSubfolderSpec = 10; 28 | files = ( 29 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, 30 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, 31 | ); 32 | name = "Embed Frameworks"; 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXCopyFilesBuildPhase section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 39 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 40 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 41 | 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 42 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 43 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 44 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 45 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 46 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 47 | 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 48 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 50 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 51 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 52 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | /* End PBXFileReference section */ 54 | 55 | /* Begin PBXFrameworksBuildPhase section */ 56 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 61 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | 9740EEB11CF90186004384FC /* Flutter */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 3B80C3931E831B6300D905FE /* App.framework */, 72 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 73 | 9740EEBA1CF902C7004384FC /* Flutter.framework */, 74 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 75 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 76 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 77 | ); 78 | name = Flutter; 79 | sourceTree = ""; 80 | }; 81 | 97C146E51CF9000F007C117D = { 82 | isa = PBXGroup; 83 | children = ( 84 | 9740EEB11CF90186004384FC /* Flutter */, 85 | 97C146F01CF9000F007C117D /* Runner */, 86 | 97C146EF1CF9000F007C117D /* Products */, 87 | ); 88 | sourceTree = ""; 89 | }; 90 | 97C146EF1CF9000F007C117D /* Products */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 97C146EE1CF9000F007C117D /* Runner.app */, 94 | ); 95 | name = Products; 96 | sourceTree = ""; 97 | }; 98 | 97C146F01CF9000F007C117D /* Runner */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 102 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 103 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 104 | 97C147021CF9000F007C117D /* Info.plist */, 105 | 97C146F11CF9000F007C117D /* Supporting Files */, 106 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 107 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 108 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 109 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, 110 | ); 111 | path = Runner; 112 | sourceTree = ""; 113 | }; 114 | 97C146F11CF9000F007C117D /* Supporting Files */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | ); 118 | name = "Supporting Files"; 119 | sourceTree = ""; 120 | }; 121 | /* End PBXGroup section */ 122 | 123 | /* Begin PBXNativeTarget section */ 124 | 97C146ED1CF9000F007C117D /* Runner */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 127 | buildPhases = ( 128 | 9740EEB61CF901F6004384FC /* Run Script */, 129 | 97C146EA1CF9000F007C117D /* Sources */, 130 | 97C146EB1CF9000F007C117D /* Frameworks */, 131 | 97C146EC1CF9000F007C117D /* Resources */, 132 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 133 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 134 | ); 135 | buildRules = ( 136 | ); 137 | dependencies = ( 138 | ); 139 | name = Runner; 140 | productName = Runner; 141 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 142 | productType = "com.apple.product-type.application"; 143 | }; 144 | /* End PBXNativeTarget section */ 145 | 146 | /* Begin PBXProject section */ 147 | 97C146E61CF9000F007C117D /* Project object */ = { 148 | isa = PBXProject; 149 | attributes = { 150 | LastUpgradeCheck = 1020; 151 | ORGANIZATIONNAME = "The Chromium Authors"; 152 | TargetAttributes = { 153 | 97C146ED1CF9000F007C117D = { 154 | CreatedOnToolsVersion = 7.3.1; 155 | LastSwiftMigration = 0910; 156 | }; 157 | }; 158 | }; 159 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 160 | compatibilityVersion = "Xcode 3.2"; 161 | developmentRegion = en; 162 | hasScannedForEncodings = 0; 163 | knownRegions = ( 164 | en, 165 | Base, 166 | ); 167 | mainGroup = 97C146E51CF9000F007C117D; 168 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 169 | projectDirPath = ""; 170 | projectRoot = ""; 171 | targets = ( 172 | 97C146ED1CF9000F007C117D /* Runner */, 173 | ); 174 | }; 175 | /* End PBXProject section */ 176 | 177 | /* Begin PBXResourcesBuildPhase section */ 178 | 97C146EC1CF9000F007C117D /* Resources */ = { 179 | isa = PBXResourcesBuildPhase; 180 | buildActionMask = 2147483647; 181 | files = ( 182 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 183 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 184 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 185 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 186 | ); 187 | runOnlyForDeploymentPostprocessing = 0; 188 | }; 189 | /* End PBXResourcesBuildPhase section */ 190 | 191 | /* Begin PBXShellScriptBuildPhase section */ 192 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 193 | isa = PBXShellScriptBuildPhase; 194 | buildActionMask = 2147483647; 195 | files = ( 196 | ); 197 | inputPaths = ( 198 | ); 199 | name = "Thin Binary"; 200 | outputPaths = ( 201 | ); 202 | runOnlyForDeploymentPostprocessing = 0; 203 | shellPath = /bin/sh; 204 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; 205 | }; 206 | 9740EEB61CF901F6004384FC /* Run Script */ = { 207 | isa = PBXShellScriptBuildPhase; 208 | buildActionMask = 2147483647; 209 | files = ( 210 | ); 211 | inputPaths = ( 212 | ); 213 | name = "Run Script"; 214 | outputPaths = ( 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | shellPath = /bin/sh; 218 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 219 | }; 220 | /* End PBXShellScriptBuildPhase section */ 221 | 222 | /* Begin PBXSourcesBuildPhase section */ 223 | 97C146EA1CF9000F007C117D /* Sources */ = { 224 | isa = PBXSourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 228 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 229 | ); 230 | runOnlyForDeploymentPostprocessing = 0; 231 | }; 232 | /* End PBXSourcesBuildPhase section */ 233 | 234 | /* Begin PBXVariantGroup section */ 235 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 236 | isa = PBXVariantGroup; 237 | children = ( 238 | 97C146FB1CF9000F007C117D /* Base */, 239 | ); 240 | name = Main.storyboard; 241 | sourceTree = ""; 242 | }; 243 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 244 | isa = PBXVariantGroup; 245 | children = ( 246 | 97C147001CF9000F007C117D /* Base */, 247 | ); 248 | name = LaunchScreen.storyboard; 249 | sourceTree = ""; 250 | }; 251 | /* End PBXVariantGroup section */ 252 | 253 | /* Begin XCBuildConfiguration section */ 254 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 255 | isa = XCBuildConfiguration; 256 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 257 | buildSettings = { 258 | ALWAYS_SEARCH_USER_PATHS = NO; 259 | CLANG_ANALYZER_NONNULL = YES; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_MODULES = YES; 263 | CLANG_ENABLE_OBJC_ARC = YES; 264 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 265 | CLANG_WARN_BOOL_CONVERSION = YES; 266 | CLANG_WARN_COMMA = YES; 267 | CLANG_WARN_CONSTANT_CONVERSION = YES; 268 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_EMPTY_BODY = YES; 271 | CLANG_WARN_ENUM_CONVERSION = YES; 272 | CLANG_WARN_INFINITE_RECURSION = YES; 273 | CLANG_WARN_INT_CONVERSION = YES; 274 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 275 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 276 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 277 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 278 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 279 | CLANG_WARN_STRICT_PROTOTYPES = YES; 280 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 281 | CLANG_WARN_UNREACHABLE_CODE = YES; 282 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 283 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 284 | COPY_PHASE_STRIP = NO; 285 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 286 | ENABLE_NS_ASSERTIONS = NO; 287 | ENABLE_STRICT_OBJC_MSGSEND = YES; 288 | GCC_C_LANGUAGE_STANDARD = gnu99; 289 | GCC_NO_COMMON_BLOCKS = YES; 290 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 291 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 292 | GCC_WARN_UNDECLARED_SELECTOR = YES; 293 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 294 | GCC_WARN_UNUSED_FUNCTION = YES; 295 | GCC_WARN_UNUSED_VARIABLE = YES; 296 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 297 | MTL_ENABLE_DEBUG_INFO = NO; 298 | SDKROOT = iphoneos; 299 | SUPPORTED_PLATFORMS = iphoneos; 300 | TARGETED_DEVICE_FAMILY = "1,2"; 301 | VALIDATE_PRODUCT = YES; 302 | }; 303 | name = Profile; 304 | }; 305 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 306 | isa = XCBuildConfiguration; 307 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 308 | buildSettings = { 309 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 310 | CLANG_ENABLE_MODULES = YES; 311 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 312 | ENABLE_BITCODE = NO; 313 | FRAMEWORK_SEARCH_PATHS = ( 314 | "$(inherited)", 315 | "$(PROJECT_DIR)/Flutter", 316 | ); 317 | INFOPLIST_FILE = Runner/Info.plist; 318 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 319 | LIBRARY_SEARCH_PATHS = ( 320 | "$(inherited)", 321 | "$(PROJECT_DIR)/Flutter", 322 | ); 323 | PRODUCT_BUNDLE_IDENTIFIER = com.oboard.dashboard; 324 | PRODUCT_NAME = "$(TARGET_NAME)"; 325 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 326 | SWIFT_VERSION = 4.0; 327 | VERSIONING_SYSTEM = "apple-generic"; 328 | }; 329 | name = Profile; 330 | }; 331 | 97C147031CF9000F007C117D /* Debug */ = { 332 | isa = XCBuildConfiguration; 333 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 334 | buildSettings = { 335 | ALWAYS_SEARCH_USER_PATHS = NO; 336 | CLANG_ANALYZER_NONNULL = YES; 337 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 338 | CLANG_CXX_LIBRARY = "libc++"; 339 | CLANG_ENABLE_MODULES = YES; 340 | CLANG_ENABLE_OBJC_ARC = YES; 341 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 342 | CLANG_WARN_BOOL_CONVERSION = YES; 343 | CLANG_WARN_COMMA = YES; 344 | CLANG_WARN_CONSTANT_CONVERSION = YES; 345 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 346 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 347 | CLANG_WARN_EMPTY_BODY = YES; 348 | CLANG_WARN_ENUM_CONVERSION = YES; 349 | CLANG_WARN_INFINITE_RECURSION = YES; 350 | CLANG_WARN_INT_CONVERSION = YES; 351 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 352 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 353 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 354 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 355 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 356 | CLANG_WARN_STRICT_PROTOTYPES = YES; 357 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 358 | CLANG_WARN_UNREACHABLE_CODE = YES; 359 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 360 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 361 | COPY_PHASE_STRIP = NO; 362 | DEBUG_INFORMATION_FORMAT = dwarf; 363 | ENABLE_STRICT_OBJC_MSGSEND = YES; 364 | ENABLE_TESTABILITY = YES; 365 | GCC_C_LANGUAGE_STANDARD = gnu99; 366 | GCC_DYNAMIC_NO_PIC = NO; 367 | GCC_NO_COMMON_BLOCKS = YES; 368 | GCC_OPTIMIZATION_LEVEL = 0; 369 | GCC_PREPROCESSOR_DEFINITIONS = ( 370 | "DEBUG=1", 371 | "$(inherited)", 372 | ); 373 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 374 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 375 | GCC_WARN_UNDECLARED_SELECTOR = YES; 376 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 377 | GCC_WARN_UNUSED_FUNCTION = YES; 378 | GCC_WARN_UNUSED_VARIABLE = YES; 379 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 380 | MTL_ENABLE_DEBUG_INFO = YES; 381 | ONLY_ACTIVE_ARCH = YES; 382 | SDKROOT = iphoneos; 383 | TARGETED_DEVICE_FAMILY = "1,2"; 384 | }; 385 | name = Debug; 386 | }; 387 | 97C147041CF9000F007C117D /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 390 | buildSettings = { 391 | ALWAYS_SEARCH_USER_PATHS = NO; 392 | CLANG_ANALYZER_NONNULL = YES; 393 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 394 | CLANG_CXX_LIBRARY = "libc++"; 395 | CLANG_ENABLE_MODULES = YES; 396 | CLANG_ENABLE_OBJC_ARC = YES; 397 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 398 | CLANG_WARN_BOOL_CONVERSION = YES; 399 | CLANG_WARN_COMMA = YES; 400 | CLANG_WARN_CONSTANT_CONVERSION = YES; 401 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 402 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 403 | CLANG_WARN_EMPTY_BODY = YES; 404 | CLANG_WARN_ENUM_CONVERSION = YES; 405 | CLANG_WARN_INFINITE_RECURSION = YES; 406 | CLANG_WARN_INT_CONVERSION = YES; 407 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 408 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 409 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 410 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 411 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 412 | CLANG_WARN_STRICT_PROTOTYPES = YES; 413 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 414 | CLANG_WARN_UNREACHABLE_CODE = YES; 415 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 416 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 417 | COPY_PHASE_STRIP = NO; 418 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 419 | ENABLE_NS_ASSERTIONS = NO; 420 | ENABLE_STRICT_OBJC_MSGSEND = YES; 421 | GCC_C_LANGUAGE_STANDARD = gnu99; 422 | GCC_NO_COMMON_BLOCKS = YES; 423 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 424 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 425 | GCC_WARN_UNDECLARED_SELECTOR = YES; 426 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 427 | GCC_WARN_UNUSED_FUNCTION = YES; 428 | GCC_WARN_UNUSED_VARIABLE = YES; 429 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 430 | MTL_ENABLE_DEBUG_INFO = NO; 431 | SDKROOT = iphoneos; 432 | SUPPORTED_PLATFORMS = iphoneos; 433 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 434 | TARGETED_DEVICE_FAMILY = "1,2"; 435 | VALIDATE_PRODUCT = YES; 436 | }; 437 | name = Release; 438 | }; 439 | 97C147061CF9000F007C117D /* Debug */ = { 440 | isa = XCBuildConfiguration; 441 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 442 | buildSettings = { 443 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 444 | CLANG_ENABLE_MODULES = YES; 445 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 446 | ENABLE_BITCODE = NO; 447 | FRAMEWORK_SEARCH_PATHS = ( 448 | "$(inherited)", 449 | "$(PROJECT_DIR)/Flutter", 450 | ); 451 | INFOPLIST_FILE = Runner/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 453 | LIBRARY_SEARCH_PATHS = ( 454 | "$(inherited)", 455 | "$(PROJECT_DIR)/Flutter", 456 | ); 457 | PRODUCT_BUNDLE_IDENTIFIER = com.oboard.dashboard; 458 | PRODUCT_NAME = "$(TARGET_NAME)"; 459 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 460 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 461 | SWIFT_VERSION = 4.0; 462 | VERSIONING_SYSTEM = "apple-generic"; 463 | }; 464 | name = Debug; 465 | }; 466 | 97C147071CF9000F007C117D /* Release */ = { 467 | isa = XCBuildConfiguration; 468 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 469 | buildSettings = { 470 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 471 | CLANG_ENABLE_MODULES = YES; 472 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 473 | ENABLE_BITCODE = NO; 474 | FRAMEWORK_SEARCH_PATHS = ( 475 | "$(inherited)", 476 | "$(PROJECT_DIR)/Flutter", 477 | ); 478 | INFOPLIST_FILE = Runner/Info.plist; 479 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 480 | LIBRARY_SEARCH_PATHS = ( 481 | "$(inherited)", 482 | "$(PROJECT_DIR)/Flutter", 483 | ); 484 | PRODUCT_BUNDLE_IDENTIFIER = com.oboard.dashboard; 485 | PRODUCT_NAME = "$(TARGET_NAME)"; 486 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 487 | SWIFT_VERSION = 4.0; 488 | VERSIONING_SYSTEM = "apple-generic"; 489 | }; 490 | name = Release; 491 | }; 492 | /* End XCBuildConfiguration section */ 493 | 494 | /* Begin XCConfigurationList section */ 495 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 496 | isa = XCConfigurationList; 497 | buildConfigurations = ( 498 | 97C147031CF9000F007C117D /* Debug */, 499 | 97C147041CF9000F007C117D /* Release */, 500 | 249021D3217E4FDB00AE95B9 /* Profile */, 501 | ); 502 | defaultConfigurationIsVisible = 0; 503 | defaultConfigurationName = Release; 504 | }; 505 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 506 | isa = XCConfigurationList; 507 | buildConfigurations = ( 508 | 97C147061CF9000F007C117D /* Debug */, 509 | 97C147071CF9000F007C117D /* Release */, 510 | 249021D4217E4FDB00AE95B9 /* Profile */, 511 | ); 512 | defaultConfigurationIsVisible = 0; 513 | defaultConfigurationName = Release; 514 | }; 515 | /* End XCConfigurationList section */ 516 | 517 | }; 518 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 519 | } 520 | -------------------------------------------------------------------------------- /lib/CupertinoAcitionCard.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | import 'dart:ui' show ImageFilter; 6 | 7 | import 'package:flutter/foundation.dart'; 8 | import 'package:flutter/rendering.dart'; 9 | import 'package:flutter/widgets.dart'; 10 | import "package:flutter/cupertino.dart"; 11 | 12 | const TextStyle _kActionSheetActionStyle = TextStyle( 13 | fontFamily: '.SF UI Text', 14 | inherit: false, 15 | fontSize: 20.0, 16 | fontWeight: FontWeight.w400, 17 | textBaseline: TextBaseline.alphabetic, 18 | ); 19 | 20 | const TextStyle _kActionSheetContentStyle = TextStyle( 21 | fontFamily: '.SF UI Text', 22 | inherit: false, 23 | fontSize: 13.0, 24 | fontWeight: FontWeight.w400, 25 | color: _kContentTextColor, 26 | textBaseline: TextBaseline.alphabetic, 27 | ); 28 | 29 | // Translucent, very light gray that is painted on top of the blurred backdrop 30 | // as the action sheet's background color. 31 | // TODO(LongCatIsLooong): https://github.com/flutter/flutter/issues/39272. Use 32 | // System Materials once we have them. 33 | // Extracted from https://developer.apple.com/design/resources/. 34 | const Color _kBackgroundColor = CupertinoDynamicColor.withBrightness( 35 | color: Color(0xC7F9F9F9), 36 | darkColor: Color(0xC7252525), 37 | ); 38 | 39 | // Translucent, light gray that is painted on top of the blurred backdrop as 40 | // the background color of a pressed button. 41 | // Eye-balled from iOS 13 beta simulator. 42 | const Color _kPressedColor = CupertinoDynamicColor.withBrightness( 43 | color: Color(0xFFE1E1E1), 44 | darkColor: Color(0xFF2E2E2E), 45 | ); 46 | 47 | const Color _kCancelPressedColor = CupertinoDynamicColor.withBrightness( 48 | color: Color(0xFFECECEC), 49 | darkColor: Color(0xFF49494B), 50 | ); 51 | 52 | // The gray color used for text that appears in the title area. 53 | // Extracted from https://developer.apple.com/design/resources/. 54 | const Color _kContentTextColor = Color(0xFF8F8F8F); 55 | 56 | // Translucent gray that is painted on top of the blurred backdrop in the gap 57 | // areas between the content section and actions section, as well as between 58 | // buttons. 59 | // Eye-balled from iOS 13 beta simulator. 60 | const Color _kButtonDividerColor = _kContentTextColor; 61 | 62 | const double _kBlurAmount = 20.0; 63 | const double _kEdgeHorizontalPadding = 8.0; 64 | const double _kCancelButtonPadding = 8.0; 65 | const double _kEdgeVerticalPadding = 10.0; 66 | const double _kContentHorizontalPadding = 40.0; 67 | const double _kContentVerticalPadding = 14.0; 68 | const double _kButtonHeight = 56.0; 69 | const double _kCornerRadius = 14.0; 70 | const double _kDividerThickness = 1.0; 71 | 72 | /// An iOS-style action sheet. 73 | /// 74 | /// An action sheet is a specific style of alert that presents the user 75 | /// with a set of two or more choices related to the current context. 76 | /// An action sheet can have a title, an additional message, and a list 77 | /// of actions. The title is displayed above the message and the actions 78 | /// are displayed below this content. 79 | /// 80 | /// This action sheet styles its title and message to match standard iOS action 81 | /// sheet title and message text style. 82 | /// 83 | /// To display action buttons that look like standard iOS action sheet buttons, 84 | /// provide [CupertinoActionCardAction]s for the [actions] given to this action sheet. 85 | /// 86 | /// To include a iOS-style cancel button separate from the other buttons, 87 | /// provide an [CupertinoActionCardAction] for the [cancelButton] given to this 88 | /// action sheet. 89 | /// 90 | /// An action sheet is typically passed as the child widget to 91 | /// [showCupertinoModalPopup], which displays the action sheet by sliding it up 92 | /// from the bottom of the screen. 93 | /// 94 | /// See also: 95 | /// 96 | /// * [CupertinoActionCardAction], which is an iOS-style action sheet button. 97 | /// * 98 | class CupertinoActionCard extends StatelessWidget { 99 | /// Creates an iOS-style action sheet. 100 | /// 101 | /// An action sheet must have a non-null value for at least one of the 102 | /// following arguments: [actions], [title], [message], or [cancelButton]. 103 | /// 104 | /// Generally, action sheets are used to give the user a choice between 105 | /// two or more choices for the current context. 106 | const CupertinoActionCard({ 107 | Key key, 108 | this.title, 109 | this.message, 110 | this.actions, 111 | this.messageScrollController, 112 | this.actionScrollController, 113 | this.cancelButton, 114 | }) : assert( 115 | actions != null || 116 | title != null || 117 | message != null || 118 | cancelButton != null, 119 | 'An action sheet must have a non-null value for at least one of the following arguments: ' 120 | 'actions, title, message, or cancelButton'), 121 | super(key: key); 122 | 123 | /// An optional title of the action sheet. When the [message] is non-null, 124 | /// the font of the [title] is bold. 125 | /// 126 | /// Typically a [Text] widget. 127 | final Widget title; 128 | 129 | /// An optional descriptive message that provides more details about the 130 | /// reason for the alert. 131 | /// 132 | /// Typically a [Text] widget. 133 | final Widget message; 134 | 135 | /// The set of actions that are displayed for the user to select. 136 | /// 137 | /// Typically this is a list of [CupertinoActionCardAction] widgets. 138 | final List actions; 139 | 140 | /// A scroll controller that can be used to control the scrolling of the 141 | /// [message] in the action sheet. 142 | /// 143 | /// This attribute is typically not needed, as alert messages should be 144 | /// short. 145 | final ScrollController messageScrollController; 146 | 147 | /// A scroll controller that can be used to control the scrolling of the 148 | /// [actions] in the action sheet. 149 | /// 150 | /// This attribute is typically not needed. 151 | final ScrollController actionScrollController; 152 | 153 | /// The optional cancel button that is grouped separately from the other 154 | /// actions. 155 | /// 156 | /// Typically this is an [CupertinoActionCardAction] widget. 157 | final Widget cancelButton; 158 | 159 | Widget _buildContent(BuildContext context) { 160 | final List content = []; 161 | if (title != null || message != null) { 162 | final Widget titleSection = _CupertinoAlertContentSection( 163 | title: title, 164 | message: message, 165 | scrollController: messageScrollController, 166 | ); 167 | content.add(Flexible(child: titleSection)); 168 | } 169 | 170 | return Container( 171 | color: CupertinoDynamicColor.resolve(_kBackgroundColor, context), 172 | child: Column( 173 | mainAxisSize: MainAxisSize.min, 174 | crossAxisAlignment: CrossAxisAlignment.stretch, 175 | children: content, 176 | ), 177 | ); 178 | } 179 | 180 | Widget _buildActions() { 181 | if (actions == null || actions.isEmpty) { 182 | return Container( 183 | height: 0.0, 184 | ); 185 | } 186 | return Container( 187 | child: _CupertinoAlertActionSection( 188 | children: actions, 189 | scrollController: actionScrollController, 190 | hasCancelButton: cancelButton != null, 191 | ), 192 | ); 193 | } 194 | 195 | @override 196 | Widget build(BuildContext context) { 197 | final List children = [ 198 | Flexible( 199 | child: ClipRRect( 200 | borderRadius: BorderRadius.circular(12.0), 201 | child: BackdropFilter( 202 | filter: 203 | ImageFilter.blur(sigmaX: _kBlurAmount, sigmaY: _kBlurAmount), 204 | child: _CupertinoAlertRenderWidget( 205 | contentSection: Builder(builder: _buildContent), 206 | actionsSection: _buildActions(), 207 | ), 208 | ), 209 | ), 210 | ), 211 | ]; 212 | 213 | final Orientation orientation = MediaQuery.of(context).orientation; 214 | double actionSheetWidth; 215 | if (orientation == Orientation.portrait) { 216 | actionSheetWidth = 217 | MediaQuery.of(context).size.width - (_kEdgeHorizontalPadding * 2); 218 | } else { 219 | actionSheetWidth = 220 | MediaQuery.of(context).size.height - (_kEdgeHorizontalPadding * 2); 221 | } 222 | 223 | return SafeArea( 224 | child: Semantics( 225 | namesRoute: true, 226 | scopesRoute: true, 227 | explicitChildNodes: true, 228 | label: 'Alert', 229 | child: CupertinoUserInterfaceLevel( 230 | data: CupertinoUserInterfaceLevelData.elevated, 231 | child: Container( 232 | width: actionSheetWidth, 233 | margin: const EdgeInsets.symmetric( 234 | horizontal: _kEdgeHorizontalPadding, 235 | vertical: _kEdgeVerticalPadding, 236 | ), 237 | child: Column( 238 | children: children, 239 | mainAxisSize: MainAxisSize.min, 240 | crossAxisAlignment: CrossAxisAlignment.stretch, 241 | ), 242 | ), 243 | ), 244 | ), 245 | ); 246 | } 247 | } 248 | 249 | /// A button typically used in a [CupertinoActionCard]. 250 | /// 251 | /// See also: 252 | /// 253 | /// * [CupertinoActionCard], an alert that presents the user with a set of two or 254 | /// more choices related to the current context. 255 | class CupertinoActionCardAction extends StatelessWidget { 256 | /// Creates an action for an iOS-style action sheet. 257 | /// 258 | /// The [child] and [onPressed] arguments must not be null. 259 | const CupertinoActionCardAction({ 260 | @required this.onPressed, 261 | this.isDefaultAction = false, 262 | this.isDestructiveAction = false, 263 | @required this.child, 264 | }) : assert(child != null), 265 | assert(onPressed != null); 266 | 267 | /// The callback that is called when the button is tapped. 268 | /// 269 | /// This attribute must not be null. 270 | final VoidCallback onPressed; 271 | 272 | /// Whether this action is the default choice in the action sheet. 273 | /// 274 | /// Default buttons have bold text. 275 | final bool isDefaultAction; 276 | 277 | /// Whether this action might change or delete data. 278 | /// 279 | /// Destructive buttons have red text. 280 | final bool isDestructiveAction; 281 | 282 | /// The widget below this widget in the tree. 283 | /// 284 | /// Typically a [Text] widget. 285 | final Widget child; 286 | 287 | @override 288 | Widget build(BuildContext context) { 289 | TextStyle style = _kActionSheetActionStyle.copyWith( 290 | color: isDestructiveAction 291 | ? CupertinoDynamicColor.resolve(CupertinoColors.systemRed, context) 292 | : CupertinoTheme.of(context).primaryColor, 293 | ); 294 | 295 | if (isDefaultAction) { 296 | style = style.copyWith(fontWeight: FontWeight.w600); 297 | } 298 | 299 | return GestureDetector( 300 | onTap: onPressed, 301 | behavior: HitTestBehavior.opaque, 302 | child: ConstrainedBox( 303 | constraints: const BoxConstraints( 304 | minHeight: _kButtonHeight, 305 | ), 306 | child: Semantics( 307 | button: true, 308 | child: Container( 309 | alignment: Alignment.center, 310 | padding: const EdgeInsets.symmetric( 311 | vertical: 16.0, 312 | horizontal: 10.0, 313 | ), 314 | child: DefaultTextStyle( 315 | style: style, 316 | child: child, 317 | textAlign: TextAlign.center, 318 | ), 319 | ), 320 | ), 321 | ), 322 | ); 323 | } 324 | } 325 | 326 | class _CupertinoAlertRenderWidget extends RenderObjectWidget { 327 | const _CupertinoAlertRenderWidget({ 328 | Key key, 329 | @required this.contentSection, 330 | @required this.actionsSection, 331 | }) : super(key: key); 332 | 333 | final Widget contentSection; 334 | final Widget actionsSection; 335 | 336 | @override 337 | RenderObject createRenderObject(BuildContext context) { 338 | return _RenderCupertinoAlert( 339 | dividerThickness: 340 | _kDividerThickness / MediaQuery.of(context).devicePixelRatio, 341 | dividerColor: 342 | CupertinoDynamicColor.resolve(_kButtonDividerColor, context), 343 | ); 344 | } 345 | 346 | @override 347 | void updateRenderObject( 348 | BuildContext context, _RenderCupertinoAlert renderObject) { 349 | super.updateRenderObject(context, renderObject); 350 | renderObject.dividerColor = 351 | CupertinoDynamicColor.resolve(_kButtonDividerColor, context); 352 | } 353 | 354 | @override 355 | RenderObjectElement createElement() { 356 | return _CupertinoAlertRenderElement(this); 357 | } 358 | } 359 | 360 | class _CupertinoAlertRenderElement extends RenderObjectElement { 361 | _CupertinoAlertRenderElement(_CupertinoAlertRenderWidget widget) 362 | : super(widget); 363 | 364 | Element _contentElement; 365 | Element _actionsElement; 366 | 367 | @override 368 | _CupertinoAlertRenderWidget get widget => super.widget; 369 | 370 | @override 371 | _RenderCupertinoAlert get renderObject => super.renderObject; 372 | 373 | @override 374 | void visitChildren(ElementVisitor visitor) { 375 | if (_contentElement != null) { 376 | visitor(_contentElement); 377 | } 378 | if (_actionsElement != null) { 379 | visitor(_actionsElement); 380 | } 381 | } 382 | 383 | @override 384 | void mount(Element parent, dynamic newSlot) { 385 | super.mount(parent, newSlot); 386 | _contentElement = updateChild( 387 | _contentElement, widget.contentSection, _AlertSections.contentSection); 388 | _actionsElement = updateChild( 389 | _actionsElement, widget.actionsSection, _AlertSections.actionsSection); 390 | } 391 | 392 | @override 393 | void insertChildRenderObject(RenderObject child, _AlertSections slot) { 394 | _placeChildInSlot(child, slot); 395 | } 396 | 397 | @override 398 | void moveChildRenderObject(RenderObject child, _AlertSections slot) { 399 | _placeChildInSlot(child, slot); 400 | } 401 | 402 | @override 403 | void update(RenderObjectWidget newWidget) { 404 | super.update(newWidget); 405 | _contentElement = updateChild( 406 | _contentElement, widget.contentSection, _AlertSections.contentSection); 407 | _actionsElement = updateChild( 408 | _actionsElement, widget.actionsSection, _AlertSections.actionsSection); 409 | } 410 | 411 | @override 412 | void forgetChild(Element child) { 413 | assert(child == _contentElement || child == _actionsElement); 414 | if (_contentElement == child) { 415 | _contentElement = null; 416 | } else if (_actionsElement == child) { 417 | _actionsElement = null; 418 | } 419 | } 420 | 421 | @override 422 | void removeChildRenderObject(RenderObject child) { 423 | assert(child == renderObject.contentSection || 424 | child == renderObject.actionsSection); 425 | if (renderObject.contentSection == child) { 426 | renderObject.contentSection = null; 427 | } else if (renderObject.actionsSection == child) { 428 | renderObject.actionsSection = null; 429 | } 430 | } 431 | 432 | void _placeChildInSlot(RenderObject child, _AlertSections slot) { 433 | assert(slot != null); 434 | switch (slot) { 435 | case _AlertSections.contentSection: 436 | renderObject.contentSection = child; 437 | break; 438 | case _AlertSections.actionsSection: 439 | renderObject.actionsSection = child; 440 | break; 441 | } 442 | } 443 | } 444 | 445 | // An iOS-style layout policy for sizing an alert's content section and action 446 | // button section. 447 | // 448 | // The policy is as follows: 449 | // 450 | // If all content and buttons fit on the screen: 451 | // The content section and action button section are sized intrinsically. 452 | // 453 | // If all content and buttons do not fit on the screen: 454 | // A minimum height for the action button section is calculated. The action 455 | // button section will not be rendered shorter than this minimum. See 456 | // _RenderCupertinoAlertActions for the minimum height calculation. 457 | // 458 | // With the minimum action button section calculated, the content section can 459 | // take up as much of the remaining space as it needs. 460 | // 461 | // After the content section is laid out, the action button section is allowed 462 | // to take up any remaining space that was not consumed by the content section. 463 | class _RenderCupertinoAlert extends RenderBox { 464 | _RenderCupertinoAlert({ 465 | RenderBox contentSection, 466 | RenderBox actionsSection, 467 | double dividerThickness = 0.0, 468 | @required Color dividerColor, 469 | }) : assert(dividerColor != null), 470 | _contentSection = contentSection, 471 | _actionsSection = actionsSection, 472 | _dividerThickness = dividerThickness, 473 | _dividerPaint = Paint() 474 | ..color = dividerColor 475 | ..style = PaintingStyle.fill; 476 | 477 | RenderBox get contentSection => _contentSection; 478 | RenderBox _contentSection; 479 | 480 | set contentSection(RenderBox newContentSection) { 481 | if (newContentSection != _contentSection) { 482 | if (null != _contentSection) { 483 | dropChild(_contentSection); 484 | } 485 | _contentSection = newContentSection; 486 | if (null != _contentSection) { 487 | adoptChild(_contentSection); 488 | } 489 | } 490 | } 491 | 492 | RenderBox get actionsSection => _actionsSection; 493 | RenderBox _actionsSection; 494 | 495 | set actionsSection(RenderBox newActionsSection) { 496 | if (newActionsSection != _actionsSection) { 497 | if (null != _actionsSection) { 498 | dropChild(_actionsSection); 499 | } 500 | _actionsSection = newActionsSection; 501 | if (null != _actionsSection) { 502 | adoptChild(_actionsSection); 503 | } 504 | } 505 | } 506 | 507 | Color get dividerColor => _dividerPaint.color; 508 | 509 | set dividerColor(Color value) { 510 | if (value == _dividerPaint.color) return; 511 | _dividerPaint.color = value; 512 | markNeedsPaint(); 513 | } 514 | 515 | final double _dividerThickness; 516 | 517 | final Paint _dividerPaint; 518 | 519 | @override 520 | void attach(PipelineOwner owner) { 521 | super.attach(owner); 522 | if (null != contentSection) { 523 | contentSection.attach(owner); 524 | } 525 | if (null != actionsSection) { 526 | actionsSection.attach(owner); 527 | } 528 | } 529 | 530 | @override 531 | void detach() { 532 | super.detach(); 533 | if (null != contentSection) { 534 | contentSection.detach(); 535 | } 536 | if (null != actionsSection) { 537 | actionsSection.detach(); 538 | } 539 | } 540 | 541 | @override 542 | void redepthChildren() { 543 | if (null != contentSection) { 544 | redepthChild(contentSection); 545 | } 546 | if (null != actionsSection) { 547 | redepthChild(actionsSection); 548 | } 549 | } 550 | 551 | @override 552 | void setupParentData(RenderBox child) { 553 | if (child.parentData is! MultiChildLayoutParentData) { 554 | child.parentData = MultiChildLayoutParentData(); 555 | } 556 | } 557 | 558 | @override 559 | void visitChildren(RenderObjectVisitor visitor) { 560 | if (contentSection != null) { 561 | visitor(contentSection); 562 | } 563 | if (actionsSection != null) { 564 | visitor(actionsSection); 565 | } 566 | } 567 | 568 | @override 569 | List debugDescribeChildren() { 570 | final List value = []; 571 | if (contentSection != null) { 572 | value.add(contentSection.toDiagnosticsNode(name: 'content')); 573 | } 574 | if (actionsSection != null) { 575 | value.add(actionsSection.toDiagnosticsNode(name: 'actions')); 576 | } 577 | return value; 578 | } 579 | 580 | @override 581 | double computeMinIntrinsicWidth(double height) { 582 | return constraints.minWidth; 583 | } 584 | 585 | @override 586 | double computeMaxIntrinsicWidth(double height) { 587 | return constraints.maxWidth; 588 | } 589 | 590 | @override 591 | double computeMinIntrinsicHeight(double width) { 592 | final double contentHeight = contentSection.getMinIntrinsicHeight(width); 593 | final double actionsHeight = actionsSection.getMinIntrinsicHeight(width); 594 | final bool hasDivider = contentHeight > 0.0 && actionsHeight > 0.0; 595 | double height = 596 | contentHeight + (hasDivider ? _dividerThickness : 0.0) + actionsHeight; 597 | 598 | if (actionsHeight > 0 || contentHeight > 0) 599 | height -= 2 * _kEdgeVerticalPadding; 600 | if (height.isFinite) return height; 601 | return 0.0; 602 | } 603 | 604 | @override 605 | double computeMaxIntrinsicHeight(double width) { 606 | final double contentHeight = contentSection.getMaxIntrinsicHeight(width); 607 | final double actionsHeight = actionsSection.getMaxIntrinsicHeight(width); 608 | final bool hasDivider = contentHeight > 0.0 && actionsHeight > 0.0; 609 | double height = 610 | contentHeight + (hasDivider ? _dividerThickness : 0.0) + actionsHeight; 611 | 612 | if (actionsHeight > 0 || contentHeight > 0) 613 | height -= 2 * _kEdgeVerticalPadding; 614 | if (height.isFinite) return height; 615 | return 0.0; 616 | } 617 | 618 | @override 619 | void performLayout() { 620 | final bool hasDivider = 621 | contentSection.getMaxIntrinsicHeight(constraints.maxWidth) > 0.0 && 622 | actionsSection.getMaxIntrinsicHeight(constraints.maxWidth) > 0.0; 623 | final double dividerThickness = hasDivider ? _dividerThickness : 0.0; 624 | 625 | final double minActionsHeight = 626 | actionsSection.getMinIntrinsicHeight(constraints.maxWidth); 627 | 628 | // Size alert content. 629 | contentSection.layout( 630 | constraints.deflate( 631 | EdgeInsets.only(bottom: minActionsHeight + dividerThickness)), 632 | parentUsesSize: true, 633 | ); 634 | final Size contentSize = contentSection.size; 635 | 636 | // Size alert actions. 637 | actionsSection.layout( 638 | constraints 639 | .deflate(EdgeInsets.only(top: contentSize.height + dividerThickness)), 640 | parentUsesSize: true, 641 | ); 642 | final Size actionsSize = actionsSection.size; 643 | 644 | // Calculate overall alert height. 645 | final double actionSheetHeight = 646 | contentSize.height + dividerThickness + actionsSize.height; 647 | 648 | // Set our size now that layout calculations are complete. 649 | size = Size(constraints.maxWidth, actionSheetHeight); 650 | 651 | // Set the position of the actions box to sit at the bottom of the alert. 652 | // The content box defaults to the top left, which is where we want it. 653 | assert(actionsSection.parentData is MultiChildLayoutParentData); 654 | final MultiChildLayoutParentData actionParentData = 655 | actionsSection.parentData; 656 | actionParentData.offset = 657 | Offset(0.0, contentSize.height + dividerThickness); 658 | } 659 | 660 | @override 661 | void paint(PaintingContext context, Offset offset) { 662 | final MultiChildLayoutParentData contentParentData = 663 | contentSection.parentData; 664 | contentSection.paint(context, offset + contentParentData.offset); 665 | 666 | final bool hasDivider = 667 | contentSection.size.height > 0.0 && actionsSection.size.height > 0.0; 668 | if (hasDivider) { 669 | _paintDividerBetweenContentAndActions(context.canvas, offset); 670 | } 671 | 672 | final MultiChildLayoutParentData actionsParentData = 673 | actionsSection.parentData; 674 | actionsSection.paint(context, offset + actionsParentData.offset); 675 | } 676 | 677 | void _paintDividerBetweenContentAndActions(Canvas canvas, Offset offset) { 678 | canvas.drawRect( 679 | Rect.fromLTWH( 680 | offset.dx, 681 | offset.dy + contentSection.size.height, 682 | size.width, 683 | _dividerThickness, 684 | ), 685 | _dividerPaint, 686 | ); 687 | } 688 | 689 | @override 690 | bool hitTestChildren(BoxHitTestResult result, {Offset position}) { 691 | final MultiChildLayoutParentData contentSectionParentData = 692 | contentSection.parentData; 693 | final MultiChildLayoutParentData actionsSectionParentData = 694 | actionsSection.parentData; 695 | return result.addWithPaintOffset( 696 | offset: contentSectionParentData.offset, 697 | position: position, 698 | hitTest: (BoxHitTestResult result, Offset transformed) { 699 | assert(transformed == position - contentSectionParentData.offset); 700 | return contentSection.hitTest(result, position: transformed); 701 | }, 702 | ) || 703 | result.addWithPaintOffset( 704 | offset: actionsSectionParentData.offset, 705 | position: position, 706 | hitTest: (BoxHitTestResult result, Offset transformed) { 707 | assert(transformed == position - actionsSectionParentData.offset); 708 | return actionsSection.hitTest(result, position: transformed); 709 | }, 710 | ); 711 | } 712 | } 713 | 714 | // Visual components of an alert that need to be explicitly sized and 715 | // laid out at runtime. 716 | enum _AlertSections { 717 | contentSection, 718 | actionsSection, 719 | } 720 | 721 | // The "content section" of a CupertinoActionCard. 722 | // 723 | // If title is missing, then only content is added. If content is 724 | // missing, then only a title is added. If both are missing, then it returns 725 | // a SingleChildScrollView with a zero-sized Container. 726 | class _CupertinoAlertContentSection extends StatelessWidget { 727 | const _CupertinoAlertContentSection({ 728 | Key key, 729 | this.title, 730 | this.message, 731 | this.scrollController, 732 | }) : super(key: key); 733 | 734 | // An optional title of the action sheet. When the message is non-null, 735 | // the font of the title is bold. 736 | // 737 | // Typically a Text widget. 738 | final Widget title; 739 | 740 | // An optional descriptive message that provides more details about the 741 | // reason for the alert. 742 | // 743 | // Typically a Text widget. 744 | final Widget message; 745 | 746 | // A scroll controller that can be used to control the scrolling of the 747 | // content in the action sheet. 748 | // 749 | // Defaults to null, and is typically not needed, since most alert contents 750 | // are short. 751 | final ScrollController scrollController; 752 | 753 | @override 754 | Widget build(BuildContext context) { 755 | final List titleContentGroup = []; 756 | 757 | if (title != null) { 758 | titleContentGroup.add(Padding( 759 | padding: const EdgeInsets.only( 760 | left: _kContentHorizontalPadding, 761 | right: _kContentHorizontalPadding, 762 | bottom: _kContentVerticalPadding, 763 | top: _kContentVerticalPadding, 764 | ), 765 | child: DefaultTextStyle( 766 | style: message == null 767 | ? _kActionSheetContentStyle 768 | : _kActionSheetContentStyle.copyWith(fontWeight: FontWeight.w600), 769 | textAlign: TextAlign.center, 770 | child: title, 771 | ), 772 | )); 773 | } 774 | 775 | if (message != null) { 776 | titleContentGroup.add( 777 | Padding( 778 | padding: EdgeInsets.only( 779 | left: _kContentHorizontalPadding, 780 | right: _kContentHorizontalPadding, 781 | bottom: title == null ? _kContentVerticalPadding : 22.0, 782 | top: title == null ? _kContentVerticalPadding : 0.0, 783 | ), 784 | child: DefaultTextStyle( 785 | style: title == null 786 | ? _kActionSheetContentStyle.copyWith( 787 | fontWeight: FontWeight.w600) 788 | : _kActionSheetContentStyle, 789 | textAlign: TextAlign.center, 790 | child: message, 791 | ), 792 | ), 793 | ); 794 | } 795 | 796 | if (titleContentGroup.isEmpty) { 797 | return SingleChildScrollView( 798 | controller: scrollController, 799 | child: Container( 800 | width: 0.0, 801 | height: 0.0, 802 | ), 803 | ); 804 | } 805 | 806 | // Add padding between the widgets if necessary. 807 | if (titleContentGroup.length > 1) { 808 | titleContentGroup.insert( 809 | 1, const Padding(padding: EdgeInsets.only(top: 8.0))); 810 | } 811 | 812 | return CupertinoScrollbar( 813 | child: SingleChildScrollView( 814 | controller: scrollController, 815 | child: Column( 816 | mainAxisSize: MainAxisSize.max, 817 | crossAxisAlignment: CrossAxisAlignment.stretch, 818 | children: titleContentGroup, 819 | ), 820 | ), 821 | ); 822 | } 823 | } 824 | 825 | // The "actions section" of a CupertinoActionCard. 826 | // 827 | // See _RenderCupertinoAlertActions for details about action button sizing 828 | // and layout. 829 | class _CupertinoAlertActionSection extends StatefulWidget { 830 | const _CupertinoAlertActionSection({ 831 | Key key, 832 | @required this.children, 833 | this.scrollController, 834 | this.hasCancelButton, 835 | }) : assert(children != null), 836 | super(key: key); 837 | 838 | final List children; 839 | 840 | // A scroll controller that can be used to control the scrolling of the 841 | // actions in the action sheet. 842 | // 843 | // Defaults to null, and is typically not needed, since most alerts 844 | // don't have many actions. 845 | final ScrollController scrollController; 846 | 847 | final bool hasCancelButton; 848 | 849 | @override 850 | _CupertinoAlertActionSectionState createState() => 851 | _CupertinoAlertActionSectionState(); 852 | } 853 | 854 | class _CupertinoAlertActionSectionState 855 | extends State<_CupertinoAlertActionSection> { 856 | @override 857 | Widget build(BuildContext context) { 858 | final double devicePixelRatio = MediaQuery.of(context).devicePixelRatio; 859 | 860 | final List interactiveButtons = []; 861 | for (int i = 0; i < widget.children.length; i += 1) { 862 | interactiveButtons.add( 863 | widget.children[i], 864 | // _PressableActionButton( 865 | // child: widget.children[i], 866 | // ), 867 | ); 868 | } 869 | 870 | return CupertinoScrollbar( 871 | child: SingleChildScrollView( 872 | controller: widget.scrollController, 873 | child: _CupertinoAlertActionsRenderWidget( 874 | actionButtons: interactiveButtons, 875 | dividerThickness: _kDividerThickness / devicePixelRatio, 876 | hasCancelButton: widget.hasCancelButton, 877 | ), 878 | ), 879 | ); 880 | } 881 | } 882 | 883 | // A button that updates its render state when pressed. 884 | // 885 | // The pressed state is forwarded to an _ActionButtonParentDataWidget. The 886 | // corresponding _ActionButtonParentData is then interpreted and rendered 887 | // appropriately by _RenderCupertinoAlertActions. 888 | class _PressableActionButton extends StatefulWidget { 889 | const _PressableActionButton({ 890 | @required this.child, 891 | }); 892 | 893 | final Widget child; 894 | 895 | @override 896 | _PressableActionButtonState createState() => _PressableActionButtonState(); 897 | } 898 | 899 | class _PressableActionButtonState extends State<_PressableActionButton> { 900 | bool _isPressed = false; 901 | 902 | @override 903 | Widget build(BuildContext context) { 904 | return _ActionButtonParentDataWidget( 905 | isPressed: _isPressed, 906 | // TODO(mattcarroll): Button press dynamics need overhaul for iOS: https://github.com/flutter/flutter/issues/19786 907 | child: GestureDetector( 908 | excludeFromSemantics: true, 909 | behavior: HitTestBehavior.opaque, 910 | onTapDown: (TapDownDetails details) => 911 | setState(() => _isPressed = true), 912 | onTapUp: (TapUpDetails details) => setState(() => _isPressed = false), 913 | // TODO(mattcarroll): Cancel is currently triggered when user moves past slop instead of off button: https://github.com/flutter/flutter/issues/19783 914 | onTapCancel: () => setState(() => _isPressed = false), 915 | child: widget.child, 916 | ), 917 | ); 918 | } 919 | } 920 | 921 | // ParentDataWidget that updates _ActionButtonParentData for an action button. 922 | // 923 | // Each action button requires knowledge of whether or not it is pressed so that 924 | // the alert can correctly render the button. The pressed state is held within 925 | // _ActionButtonParentData. _ActionButtonParentDataWidget is responsible for 926 | // updating the pressed state of an _ActionButtonParentData based on the 927 | // incoming isPressed property. 928 | class _ActionButtonParentDataWidget 929 | extends ParentDataWidget<_CupertinoAlertActionsRenderWidget> { 930 | const _ActionButtonParentDataWidget({ 931 | Key key, 932 | this.isPressed, 933 | @required Widget child, 934 | }) : super(key: key, child: child); 935 | 936 | final bool isPressed; 937 | 938 | @override 939 | void applyParentData(RenderObject renderObject) { 940 | assert(renderObject.parentData is _ActionButtonParentData); 941 | final _ActionButtonParentData parentData = renderObject.parentData; 942 | if (parentData.isPressed != isPressed) { 943 | parentData.isPressed = isPressed; 944 | 945 | // Force a repaint. 946 | final AbstractNode targetParent = renderObject.parent; 947 | if (targetParent is RenderObject) targetParent.markNeedsPaint(); 948 | } 949 | } 950 | } 951 | 952 | // ParentData applied to individual action buttons that report whether or not 953 | // that button is currently pressed by the user. 954 | class _ActionButtonParentData extends MultiChildLayoutParentData { 955 | _ActionButtonParentData({ 956 | this.isPressed = false, 957 | }); 958 | 959 | bool isPressed; 960 | } 961 | 962 | // An iOS-style alert action button layout. 963 | // 964 | // See _RenderCupertinoAlertActions for specific layout policy details. 965 | class _CupertinoAlertActionsRenderWidget extends MultiChildRenderObjectWidget { 966 | _CupertinoAlertActionsRenderWidget({ 967 | Key key, 968 | @required List actionButtons, 969 | double dividerThickness = 0.0, 970 | bool hasCancelButton = false, 971 | }) : _dividerThickness = dividerThickness, 972 | _hasCancelButton = hasCancelButton, 973 | super(key: key, children: actionButtons); 974 | 975 | final double _dividerThickness; 976 | final bool _hasCancelButton; 977 | 978 | @override 979 | RenderObject createRenderObject(BuildContext context) { 980 | return _RenderCupertinoAlertActions( 981 | dividerThickness: _dividerThickness, 982 | dividerColor: 983 | CupertinoDynamicColor.resolve(_kButtonDividerColor, context), 984 | hasCancelButton: _hasCancelButton, 985 | backgroundColor: 986 | CupertinoDynamicColor.resolve(_kBackgroundColor, context), 987 | pressedColor: CupertinoDynamicColor.resolve(_kPressedColor, context), 988 | ); 989 | } 990 | 991 | @override 992 | void updateRenderObject( 993 | BuildContext context, _RenderCupertinoAlertActions renderObject) { 994 | renderObject 995 | ..dividerThickness = _dividerThickness 996 | ..dividerColor = 997 | CupertinoDynamicColor.resolve(_kButtonDividerColor, context) 998 | ..hasCancelButton = _hasCancelButton 999 | ..backgroundColor = 1000 | CupertinoDynamicColor.resolve(_kBackgroundColor, context) 1001 | ..pressedColor = CupertinoDynamicColor.resolve(_kPressedColor, context); 1002 | } 1003 | } 1004 | 1005 | // An iOS-style layout policy for sizing and positioning an action sheet's 1006 | // buttons. 1007 | // 1008 | // The policy is as follows: 1009 | // 1010 | // Action sheet buttons are always stacked vertically. In the case where the 1011 | // content section and the action section combined can not fit on the screen 1012 | // without scrolling, the height of the action section is determined as 1013 | // follows. 1014 | // 1015 | // If the user has included a separate cancel button, the height of the action 1016 | // section can be up to the height of 3 action buttons (i.e., the user can 1017 | // include 1, 2, or 3 action buttons and they will appear without needing to 1018 | // be scrolled). If 4+ action buttons are provided, the height of the action 1019 | // section shrinks to 1.5 buttons tall, and is scrollable. 1020 | // 1021 | // If the user has not included a separate cancel button, the height of the 1022 | // action section is at most 1.5 buttons tall. 1023 | class _RenderCupertinoAlertActions extends RenderBox 1024 | with 1025 | ContainerRenderObjectMixin, 1026 | RenderBoxContainerDefaultsMixin { 1027 | _RenderCupertinoAlertActions({ 1028 | List children, 1029 | double dividerThickness = 0.0, 1030 | @required Color dividerColor, 1031 | bool hasCancelButton = false, 1032 | Color backgroundColor, 1033 | Color pressedColor, 1034 | }) : _dividerThickness = dividerThickness, 1035 | _hasCancelButton = hasCancelButton, 1036 | _buttonBackgroundPaint = Paint() 1037 | ..style = PaintingStyle.fill 1038 | ..color = backgroundColor, 1039 | _pressedButtonBackgroundPaint = Paint() 1040 | ..style = PaintingStyle.fill 1041 | ..color = pressedColor, 1042 | _dividerPaint = Paint() 1043 | ..color = dividerColor 1044 | ..style = PaintingStyle.fill { 1045 | addAll(children); 1046 | } 1047 | 1048 | // The thickness of the divider between buttons. 1049 | double get dividerThickness => _dividerThickness; 1050 | double _dividerThickness; 1051 | 1052 | set dividerThickness(double newValue) { 1053 | if (newValue == _dividerThickness) { 1054 | return; 1055 | } 1056 | 1057 | _dividerThickness = newValue; 1058 | markNeedsLayout(); 1059 | } 1060 | 1061 | Color get backgroundColor => _buttonBackgroundPaint.color; 1062 | 1063 | set backgroundColor(Color newValue) { 1064 | if (newValue == _buttonBackgroundPaint.color) { 1065 | return; 1066 | } 1067 | 1068 | _buttonBackgroundPaint.color = newValue; 1069 | markNeedsPaint(); 1070 | } 1071 | 1072 | Color get pressedColor => _pressedButtonBackgroundPaint.color; 1073 | 1074 | set pressedColor(Color newValue) { 1075 | if (newValue == _pressedButtonBackgroundPaint.color) { 1076 | return; 1077 | } 1078 | 1079 | _pressedButtonBackgroundPaint.color = newValue; 1080 | markNeedsPaint(); 1081 | } 1082 | 1083 | Color get dividerColor => _dividerPaint.color; 1084 | 1085 | set dividerColor(Color value) { 1086 | if (value == _dividerPaint.color) { 1087 | return; 1088 | } 1089 | _dividerPaint.color = value; 1090 | markNeedsPaint(); 1091 | } 1092 | 1093 | bool _hasCancelButton; 1094 | 1095 | bool get hasCancelButton => _hasCancelButton; 1096 | 1097 | set hasCancelButton(bool newValue) { 1098 | if (newValue == _hasCancelButton) { 1099 | return; 1100 | } 1101 | 1102 | _hasCancelButton = newValue; 1103 | markNeedsLayout(); 1104 | } 1105 | 1106 | final Paint _buttonBackgroundPaint; 1107 | final Paint _pressedButtonBackgroundPaint; 1108 | 1109 | final Paint _dividerPaint; 1110 | 1111 | @override 1112 | void setupParentData(RenderBox child) { 1113 | if (child.parentData is! _ActionButtonParentData) 1114 | child.parentData = _ActionButtonParentData(); 1115 | } 1116 | 1117 | @override 1118 | double computeMinIntrinsicWidth(double height) { 1119 | return constraints.minWidth; 1120 | } 1121 | 1122 | @override 1123 | double computeMaxIntrinsicWidth(double height) { 1124 | return constraints.maxWidth; 1125 | } 1126 | 1127 | @override 1128 | double computeMinIntrinsicHeight(double width) { 1129 | if (childCount == 0) return 0.0; 1130 | if (childCount == 1) 1131 | return firstChild.computeMaxIntrinsicHeight(width) + dividerThickness; 1132 | if (hasCancelButton && childCount < 4) 1133 | return _computeMinIntrinsicHeightWithCancel(width); 1134 | return _computeMinIntrinsicHeightWithoutCancel(width); 1135 | } 1136 | 1137 | // The minimum height for more than 2-3 buttons when a cancel button is 1138 | // included is the full height of button stack. 1139 | double _computeMinIntrinsicHeightWithCancel(double width) { 1140 | assert(childCount == 2 || childCount == 3); 1141 | if (childCount == 2) { 1142 | return firstChild.getMinIntrinsicHeight(width) + 1143 | childAfter(firstChild).getMinIntrinsicHeight(width) + 1144 | dividerThickness; 1145 | } 1146 | return firstChild.getMinIntrinsicHeight(width) + 1147 | childAfter(firstChild).getMinIntrinsicHeight(width) + 1148 | childAfter(childAfter(firstChild)).getMinIntrinsicHeight(width) + 1149 | (dividerThickness * 2); 1150 | } 1151 | 1152 | // The minimum height for more than 2 buttons when no cancel button or 4+ 1153 | // buttons when a cancel button is included is the height of the 1st button 1154 | // + 50% the height of the 2nd button + 2 dividers. 1155 | double _computeMinIntrinsicHeightWithoutCancel(double width) { 1156 | assert(childCount >= 2); 1157 | return firstChild.getMinIntrinsicHeight(width) + 1158 | dividerThickness + 1159 | (0.5 * childAfter(firstChild).getMinIntrinsicHeight(width)); 1160 | } 1161 | 1162 | @override 1163 | double computeMaxIntrinsicHeight(double width) { 1164 | if (childCount == 0) return 0.0; 1165 | if (childCount == 1) 1166 | return firstChild.computeMaxIntrinsicHeight(width) + dividerThickness; 1167 | return _computeMaxIntrinsicHeightStacked(width); 1168 | } 1169 | 1170 | // Max height of a stack of buttons is the sum of all button heights + a 1171 | // divider for each button. 1172 | double _computeMaxIntrinsicHeightStacked(double width) { 1173 | assert(childCount >= 2); 1174 | 1175 | final double allDividersHeight = (childCount - 1) * dividerThickness; 1176 | double heightAccumulation = allDividersHeight; 1177 | RenderBox button = firstChild; 1178 | while (button != null) { 1179 | heightAccumulation += button.getMaxIntrinsicHeight(width); 1180 | button = childAfter(button); 1181 | } 1182 | return heightAccumulation; 1183 | } 1184 | 1185 | @override 1186 | void performLayout() { 1187 | final BoxConstraints perButtonConstraints = constraints.copyWith( 1188 | minHeight: 0.0, 1189 | maxHeight: double.infinity, 1190 | ); 1191 | 1192 | RenderBox child = firstChild; 1193 | int index = 0; 1194 | double verticalOffset = 0.0; 1195 | while (child != null) { 1196 | child.layout( 1197 | perButtonConstraints, 1198 | parentUsesSize: true, 1199 | ); 1200 | 1201 | assert(child.parentData is MultiChildLayoutParentData); 1202 | final MultiChildLayoutParentData parentData = child.parentData; 1203 | parentData.offset = Offset(0.0, verticalOffset); 1204 | 1205 | verticalOffset += child.size.height; 1206 | if (index < childCount - 1) { 1207 | // Add a gap for the next divider. 1208 | verticalOffset += dividerThickness; 1209 | } 1210 | 1211 | index += 1; 1212 | child = childAfter(child); 1213 | } 1214 | 1215 | size = constraints.constrain(Size(constraints.maxWidth, verticalOffset)); 1216 | } 1217 | 1218 | @override 1219 | void paint(PaintingContext context, Offset offset) { 1220 | final Canvas canvas = context.canvas; 1221 | _drawButtonBackgroundsAndDividersStacked(canvas, offset); 1222 | _drawButtons(context, offset); 1223 | } 1224 | 1225 | void _drawButtonBackgroundsAndDividersStacked(Canvas canvas, Offset offset) { 1226 | final Offset dividerOffset = Offset(0.0, dividerThickness); 1227 | 1228 | final Path backgroundFillPath = Path() 1229 | ..fillType = PathFillType.evenOdd 1230 | ..addRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height)); 1231 | 1232 | final Path pressedBackgroundFillPath = Path(); 1233 | 1234 | final Path dividersPath = Path(); 1235 | 1236 | Offset accumulatingOffset = offset; 1237 | 1238 | RenderBox child = firstChild; 1239 | RenderBox prevChild; 1240 | while (child != null) { 1241 | assert(child.parentData is _ActionButtonParentData); 1242 | final _ActionButtonParentData currentButtonParentData = child.parentData; 1243 | final bool isButtonPressed = currentButtonParentData.isPressed; 1244 | 1245 | bool isPrevButtonPressed = false; 1246 | if (prevChild != null) { 1247 | assert(prevChild.parentData is _ActionButtonParentData); 1248 | final _ActionButtonParentData previousButtonParentData = 1249 | prevChild.parentData; 1250 | isPrevButtonPressed = previousButtonParentData.isPressed; 1251 | } 1252 | 1253 | final bool isDividerPresent = child != firstChild; 1254 | final bool isDividerPainted = 1255 | isDividerPresent && !(isButtonPressed || isPrevButtonPressed); 1256 | final Rect dividerRect = Rect.fromLTWH( 1257 | accumulatingOffset.dx, 1258 | accumulatingOffset.dy, 1259 | size.width, 1260 | _dividerThickness, 1261 | ); 1262 | 1263 | final Rect buttonBackgroundRect = Rect.fromLTWH( 1264 | accumulatingOffset.dx, 1265 | accumulatingOffset.dy + (isDividerPresent ? dividerThickness : 0.0), 1266 | size.width, 1267 | child.size.height, 1268 | ); 1269 | 1270 | // If this button is pressed, then we don't want a white background to be 1271 | // painted, so we erase this button from the background path. 1272 | if (isButtonPressed) { 1273 | backgroundFillPath.addRect(buttonBackgroundRect); 1274 | pressedBackgroundFillPath.addRect(buttonBackgroundRect); 1275 | } 1276 | 1277 | // If this divider is needed, then we erase the divider area from the 1278 | // background path, and on top of that we paint a translucent gray to 1279 | // darken the divider area. 1280 | if (isDividerPainted) { 1281 | backgroundFillPath.addRect(dividerRect); 1282 | dividersPath.addRect(dividerRect); 1283 | } 1284 | 1285 | accumulatingOffset += (isDividerPresent ? dividerOffset : Offset.zero) + 1286 | Offset(0.0, child.size.height); 1287 | 1288 | prevChild = child; 1289 | child = childAfter(child); 1290 | } 1291 | 1292 | canvas.drawPath(backgroundFillPath, _buttonBackgroundPaint); 1293 | canvas.drawPath(pressedBackgroundFillPath, _pressedButtonBackgroundPaint); 1294 | canvas.drawPath(dividersPath, _dividerPaint); 1295 | } 1296 | 1297 | void _drawButtons(PaintingContext context, Offset offset) { 1298 | RenderBox child = firstChild; 1299 | while (child != null) { 1300 | final MultiChildLayoutParentData childParentData = child.parentData; 1301 | context.paintChild(child, childParentData.offset + offset); 1302 | child = childAfter(child); 1303 | } 1304 | } 1305 | 1306 | @override 1307 | bool hitTestChildren(BoxHitTestResult result, {Offset position}) { 1308 | return defaultHitTestChildren(result, position: position); 1309 | } 1310 | } 1311 | --------------------------------------------------------------------------------