diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 554c4340c5..9f21a2d397 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -408,15 +408,17 @@ Future runForbiddenFromReleaseTests() async { ); } -/// Verifies that APK, and IPA (if on macOS) builds the examples apps -/// without crashing. It does not actually launch the apps. That happens later -/// in the devicelab. This is just a smoke-test. In particular, this will verify -/// we can build when there are spaces in the path name for the Flutter SDK and -/// target app. +/// Verifies that APK, and IPA (if on macOS), and native desktop builds the +/// examples apps without crashing. It does not actually launch the apps. That +/// happens later in the devicelab. This is just a smoke-test. In particular, +/// this will verify we can build when there are spaces in the path name for the +/// Flutter SDK and target app. /// /// Also does some checking about types included in hello_world. Future _runBuildTests() async { - final List exampleDirectories = Directory(path.join(flutterRoot, 'examples')).listSync() + final List exampleDirectories = Directory(path.join(flutterRoot, 'examples')).listSync() + // API example builds will be tested in a separate shard. + .where((FileSystemEntity entity) => entity is Directory && path.basename(entity.path) != 'api').cast().toList() ..add(Directory(path.join(flutterRoot, 'packages', 'integration_test', 'example'))) ..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'android_semantics_testing'))) ..add(Directory(path.join(flutterRoot, 'dev', 'integration_tests', 'android_views'))) @@ -430,7 +432,7 @@ Future _runBuildTests() async { // The tests are randomly distributed into subshards so as to get a uniform // distribution of costs, but the seed is fixed so that issues are reproducible. final List tests = [ - for (final FileSystemEntity exampleDirectory in exampleDirectories) + for (final Directory exampleDirectory in exampleDirectories) () => _runExampleProjectBuildTests(exampleDirectory), ...[ // Web compilation tests. @@ -450,7 +452,7 @@ Future _runBuildTests() async { await _runShardRunnerIndexOfTotalSubshard(tests); } -Future _runExampleProjectBuildTests(FileSystemEntity exampleDirectory) async { +Future _runExampleProjectBuildTests(Directory exampleDirectory, [File? mainFile]) async { // Only verify caching with flutter gallery. final bool verifyCaching = exampleDirectory.path.contains('flutter_gallery'); if (exampleDirectory is! Directory) { @@ -458,9 +460,10 @@ Future _runExampleProjectBuildTests(FileSystemEntity exampleDirectory) asy } final String examplePath = exampleDirectory.path; final bool hasNullSafety = File(path.join(examplePath, 'null_safety')).existsSync(); - final List additionalArgs = hasNullSafety - ? ['--no-sound-null-safety'] - : []; + final List additionalArgs = [ + if (hasNullSafety) '--no-sound-null-safety', + if (mainFile != null) path.relative(mainFile.path, from: exampleDirectory.absolute.path), + ]; if (Directory(path.join(examplePath, 'android')).existsSync()) { await _flutterBuildApk(examplePath, release: false, additionalArgs: additionalArgs, verifyCaching: verifyCaching); await _flutterBuildApk(examplePath, release: true, additionalArgs: additionalArgs, verifyCaching: verifyCaching); diff --git a/examples/api/.metadata b/examples/api/.metadata new file mode 100644 index 0000000000..e88138a540 --- /dev/null +++ b/examples/api/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: e91847fe7cadcc293e6b75ec614dfad5097d9de8 + channel: extract_samples + +project_type: app diff --git a/examples/api/README.md b/examples/api/README.md new file mode 100644 index 0000000000..b0e6ca1b5b --- /dev/null +++ b/examples/api/README.md @@ -0,0 +1,67 @@ +# API Example Code + +This directory contains the API sample code that is referenced from the +API documentation in each class. + +They can be run individually by just specifying the path to the example on the +command line (or in the run configuration of an IDE). + +For example, to run, in Chrome, the first example from the `Curve2D` class, you +would run it like so, from this [api](.) directory: + +``` +% flutter run -d chrome lib/animation/curves/curve2_d.0.dart +``` + +These same examples are available on the API docs site. For instance, the +example above is available on [this +page](https://api.flutter.dev/flutter/animation/Curve2D-class.html#animation.Curve2D.1). +Most of them are available as interactive examples in Dartpad, but some just +don't make sense on the web, and so are available as standalone examples that +can be run here. + +## Naming + +The naming scheme for the files is similar to the hierarchy under +[packages/flutter/lib/src](../../packages/flutter/lib/src), except that the +files are represented as directories, and each sample in each file as a separate +file in that directory. So, for the example above, the examples are from the +[packages/flutter/lib/src/animation/curves.dart](../../packages/flutter/lib/src/animation/curves.dart) +file, the `Curve2D` class, and the first sample (hence the index "0") for that +symbol resides in the +[lib/animation/curves/curve2_d.0.dart](lib/animation/curves/curve2_d.0.dart) +file. + +## Authoring + +When authoring these examples, place a block like so in the Dartdoc +documentation for the symbol you would like to attach it to. Here's what it +might look like if you wanted to add a new example to the `Curve2D` class. First +add the stub to the symbol documentation: + +```dart +/// {@tool dartpad --template=material_scaffold} +/// Write a description of the example here. This description will appear in the +/// API web documentation to introduce the example. +/// +/// ```dart +/// // These are the sections you want to fill out in the template. +/// // They will be transferred to the example file when you extract it. +/// ``` +/// {@end-tool} +``` + +Then install the `extract_sample` command with: + +``` +% pub global activate snippets +``` + +And run the `extract_sample` command from the Flutter repo dir: + +``` +$ pub global run extract_sample packages/flutter/lib/src/animation/curves.dart +``` + +This will create a new file in the `examples/api` directory, in this case it +would create `examples/api/lib/animation/curves/curve2_d.1.dart` diff --git a/examples/api/android/.gitignore b/examples/api/android/.gitignore new file mode 100644 index 0000000000..6f568019d3 --- /dev/null +++ b/examples/api/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/examples/api/android/app/build.gradle b/examples/api/android/app/build.gradle new file mode 100644 index 0000000000..aa049f9322 --- /dev/null +++ b/examples/api/android/app/build.gradle @@ -0,0 +1,72 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + compileSdkVersion 30 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "dev.flutter.dartpad_curve2_d_0" + minSdkVersion 16 + targetSdkVersion 30 + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} diff --git a/examples/api/android/app/src/debug/AndroidManifest.xml b/examples/api/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000000..fd5699c0f5 --- /dev/null +++ b/examples/api/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/examples/api/android/app/src/main/AndroidManifest.xml b/examples/api/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..9a213650f5 --- /dev/null +++ b/examples/api/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/examples/api/android/app/src/main/kotlin/dev/flutter/dartpad_curve2_d_0/MainActivity.kt b/examples/api/android/app/src/main/kotlin/dev/flutter/dartpad_curve2_d_0/MainActivity.kt new file mode 100644 index 0000000000..1455157b4e --- /dev/null +++ b/examples/api/android/app/src/main/kotlin/dev/flutter/dartpad_curve2_d_0/MainActivity.kt @@ -0,0 +1,6 @@ +package dev.flutter.dartpad_curve2_d_0 + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/examples/api/android/app/src/main/res/color/fab_ripple_color.xml b/examples/api/android/app/src/main/res/color/fab_ripple_color.xml new file mode 100644 index 0000000000..ea2ccbdc35 --- /dev/null +++ b/examples/api/android/app/src/main/res/color/fab_ripple_color.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/examples/api/android/app/src/main/res/drawable/ic_add_black_24dp.xml b/examples/api/android/app/src/main/res/drawable/ic_add_black_24dp.xml new file mode 100644 index 0000000000..f99c4c64f6 --- /dev/null +++ b/examples/api/android/app/src/main/res/drawable/ic_add_black_24dp.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/examples/api/android/app/src/main/res/layout/flutter_view_layout.xml b/examples/api/android/app/src/main/res/layout/flutter_view_layout.xml new file mode 100644 index 0000000000..ba7e253a94 --- /dev/null +++ b/examples/api/android/app/src/main/res/layout/flutter_view_layout.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/api/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/examples/api/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000000..db77bb4b7b Binary files /dev/null and b/examples/api/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/examples/api/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/examples/api/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000000..17987b79bb Binary files /dev/null and b/examples/api/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/examples/api/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/examples/api/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000000..09d4391482 Binary files /dev/null and b/examples/api/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/examples/api/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/examples/api/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000000..d5f1c8d34e Binary files /dev/null and b/examples/api/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/examples/api/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/examples/api/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000000..4d6372eebd Binary files /dev/null and b/examples/api/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/examples/api/android/app/src/main/res/values/colors.xml b/examples/api/android/app/src/main/res/values/colors.xml new file mode 100644 index 0000000000..07f7af62e7 --- /dev/null +++ b/examples/api/android/app/src/main/res/values/colors.xml @@ -0,0 +1,8 @@ + + + + #9E9E9E + #FFFFFF + diff --git a/examples/api/android/app/src/main/res/values/dimens.xml b/examples/api/android/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000000..1078837b05 --- /dev/null +++ b/examples/api/android/app/src/main/res/values/dimens.xml @@ -0,0 +1,11 @@ + + + + 16dp + 6dp + 12dp + 17sp + 30sp + diff --git a/examples/api/android/app/src/main/res/values/strings.xml b/examples/api/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000000..53353042f3 --- /dev/null +++ b/examples/api/android/app/src/main/res/values/strings.xml @@ -0,0 +1,10 @@ + + + + Flutter View + Flutter Application + Flutter button tapped 0 times. + Android + diff --git a/examples/api/android/app/src/profile/AndroidManifest.xml b/examples/api/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000000..fd5699c0f5 --- /dev/null +++ b/examples/api/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/examples/api/android/build.gradle b/examples/api/android/build.gradle new file mode 100644 index 0000000000..05c070104b --- /dev/null +++ b/examples/api/android/build.gradle @@ -0,0 +1,33 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +buildscript { + ext.kotlin_version = '1.3.50' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/examples/api/android/gradle.properties b/examples/api/android/gradle.properties new file mode 100644 index 0000000000..94adc3a3f9 --- /dev/null +++ b/examples/api/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/examples/api/android/gradle/wrapper/gradle-wrapper.properties b/examples/api/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..bc6a58afdd --- /dev/null +++ b/examples/api/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jun 23 08:50:38 CEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/examples/api/android/settings.gradle b/examples/api/android/settings.gradle new file mode 100644 index 0000000000..d3b6a4013d --- /dev/null +++ b/examples/api/android/settings.gradle @@ -0,0 +1,15 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +include ':app' + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/examples/api/ios/.gitignore b/examples/api/ios/.gitignore new file mode 100644 index 0000000000..151026b91b --- /dev/null +++ b/examples/api/ios/.gitignore @@ -0,0 +1,33 @@ +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/ephemeral/ +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/examples/api/ios/Flutter/AppFrameworkInfo.plist b/examples/api/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000000..8d4492f977 --- /dev/null +++ b/examples/api/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 9.0 + + diff --git a/examples/api/ios/Flutter/Debug.xcconfig b/examples/api/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000000..592ceee85b --- /dev/null +++ b/examples/api/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/examples/api/ios/Flutter/Release.xcconfig b/examples/api/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000000..592ceee85b --- /dev/null +++ b/examples/api/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/examples/api/ios/Runner.xcodeproj/project.pbxproj b/examples/api/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..1d06767270 --- /dev/null +++ b/examples/api/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,471 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, + ); + path = Runner; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1100; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 249021D3217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 249021D4217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.dartpadCurve2D0; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.dartpadCurve2D0; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.dartpadCurve2D0; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 249021D3217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 249021D4217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/examples/api/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/examples/api/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..919434a625 --- /dev/null +++ b/examples/api/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/examples/api/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/api/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/examples/api/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/examples/api/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/examples/api/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000000..f9b0d7c5ea --- /dev/null +++ b/examples/api/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/examples/api/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/examples/api/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000..a28140cfdb --- /dev/null +++ b/examples/api/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/api/ios/Runner.xcworkspace/contents.xcworkspacedata b/examples/api/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..1d526a16ed --- /dev/null +++ b/examples/api/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/examples/api/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/api/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/examples/api/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/examples/api/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/examples/api/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000000..f9b0d7c5ea --- /dev/null +++ b/examples/api/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/examples/api/ios/Runner/AppDelegate.swift b/examples/api/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000000..d815fed684 --- /dev/null +++ b/examples/api/ios/Runner/AppDelegate.swift @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import UIKit +import Flutter + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..13929fcb3b --- /dev/null +++ b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,130 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000000..4cde12118d Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000000..d0ef06e7ed Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png new file mode 100644 index 0000000000..dcdc2306c2 Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png new file mode 100644 index 0000000000..2ccbfd967d Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000000..c8f9ed8f5c Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png new file mode 100644 index 0000000000..a6d6b8609d Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@1x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@1x.png new file mode 100644 index 0000000000..f091b6b0bc Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@1x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000000..a6d6b8609d Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000000..75b2d164a5 Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png new file mode 100644 index 0000000000..c4df70d39d Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png new file mode 100644 index 0000000000..6a84f41e14 Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@3x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@3x.png new file mode 100644 index 0000000000..5d2bad8503 Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@3x.png differ diff --git a/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000000..d0e1f58536 Binary files /dev/null and b/examples/api/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/examples/api/ios/Runner/Base.lproj/LaunchScreen.storyboard b/examples/api/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000..f2e259c7c9 --- /dev/null +++ b/examples/api/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/api/ios/Runner/Base.lproj/Main.storyboard b/examples/api/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000000..f3c28516fb --- /dev/null +++ b/examples/api/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/api/ios/Runner/Info.plist b/examples/api/ios/Runner/Info.plist new file mode 100644 index 0000000000..aa7201dce3 --- /dev/null +++ b/examples/api/ios/Runner/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + dartpad_curve2_d_0 + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + + diff --git a/examples/api/ios/Runner/Runner-Bridging-Header.h b/examples/api/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000000..95b7baf386 --- /dev/null +++ b/examples/api/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1,5 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "GeneratedPluginRegistrant.h" diff --git a/examples/api/lib/animation/curves/curve2_d.0.dart b/examples/api/lib/animation/curves/curve2_d.0.dart new file mode 100644 index 0000000000..cda16b172e --- /dev/null +++ b/examples/api/lib/animation/curves/curve2_d.0.dart @@ -0,0 +1,151 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Curve2D +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to use a [Curve2D] to modify the position of a widget +// so that it can follow an arbitrary path. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This is the path that the child will follow. It's a CatmullRomSpline so +// that the coordinates can be specified that it must pass through. If the +// tension is set to 1.0, it will linearly interpolate between those points, +// instead of interpolating smoothly. +final CatmullRomSpline path = CatmullRomSpline( + const [ + Offset(0.05, 0.75), + Offset(0.18, 0.23), + Offset(0.32, 0.04), + Offset(0.73, 0.5), + Offset(0.42, 0.74), + Offset(0.73, 0.01), + Offset(0.93, 0.93), + Offset(0.05, 0.75), + ], + startHandle: const Offset(0.93, 0.93), + endHandle: const Offset(0.18, 0.23), + tension: 0.0, +); + +class FollowCurve2D extends StatefulWidget { + const FollowCurve2D({ + Key? key, + required this.path, + this.curve = Curves.easeInOut, + required this.child, + this.duration = const Duration(seconds: 1), + }) : super(key: key); + + final Curve2D path; + final Curve curve; + final Duration duration; + final Widget child; + + @override + State createState() => _FollowCurve2DState(); +} + +class _FollowCurve2DState extends State + with TickerProviderStateMixin { + // The animation controller for this animation. + late AnimationController controller; + // The animation that will be used to apply the widget's animation curve. + late Animation animation; + + @override + void initState() { + super.initState(); + controller = AnimationController(duration: widget.duration, vsync: this); + animation = CurvedAnimation(parent: controller, curve: widget.curve); + // Have the controller repeat indefinitely. If you want it to "bounce" back + // and forth, set the reverse parameter to true. + controller.repeat(reverse: false); + controller.addListener(() => setState(() {})); + } + + @override + void dispose() { + super.dispose(); + // Always have to dispose of animation controllers when done. + controller.dispose(); + } + + @override + Widget build(BuildContext context) { + // Scale the path values to match the -1.0 to 1.0 domain of the Alignment widget. + final Offset position = + widget.path.transform(animation.value) * 2.0 - const Offset(1.0, 1.0); + return Align( + alignment: Alignment(position.dx, position.dy), + child: widget.child, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + color: Colors.white, + alignment: Alignment.center, + child: FollowCurve2D( + path: path, + curve: Curves.easeInOut, + duration: const Duration(seconds: 3), + child: CircleAvatar( + backgroundColor: Colors.yellow, + child: DefaultTextStyle( + style: Theme.of(context).textTheme.headline6!, + child: const Text('B'), // Buzz, buzz! + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart b/examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart new file mode 100644 index 0000000000..73b5e752ac --- /dev/null +++ b/examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CupertinoContextMenu +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a very simple CupertinoContextMenu for an empty red +// 100x100 Container. Simply long press on it to open. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/cupertino.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: SizedBox( + width: 100, + height: 100, + child: CupertinoContextMenu( + child: Container( + color: Colors.red, + ), + actions: [ + CupertinoContextMenuAction( + child: const Text('Action one'), + onPressed: () { + Navigator.pop(context); + }, + ), + CupertinoContextMenuAction( + child: const Text('Action two'), + onPressed: () { + Navigator.pop(context); + }, + ), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/nav_bar/cupertino_navigation_bar.0.dart b/examples/api/lib/cupertino/nav_bar/cupertino_navigation_bar.0.dart new file mode 100644 index 0000000000..7b3740769e --- /dev/null +++ b/examples/api/lib/cupertino/nav_bar/cupertino_navigation_bar.0.dart @@ -0,0 +1,76 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_cupertino.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CupertinoNavigationBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [CupertinoNavigationBar] placed in a [CupertinoPageScaffold]. +// Since [backgroundColor]'s opacity is not 1.0, there is a blur effect and +// content slides underneath. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/cupertino.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const CupertinoApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return CupertinoPageScaffold( + navigationBar: CupertinoNavigationBar( + // Try removing opacity to observe the lack of a blur effect and of sliding content. + backgroundColor: CupertinoColors.systemGrey.withOpacity(0.5), + middle: const Text('Sample Code'), + ), + child: Column( + children: [ + Container(height: 50, color: CupertinoColors.systemRed), + Container(height: 50, color: CupertinoColors.systemGreen), + Container(height: 50, color: CupertinoColors.systemBlue), + Container(height: 50, color: CupertinoColors.systemYellow), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/page_scaffold/cupertino_page_scaffold.0.dart b/examples/api/lib/cupertino/page_scaffold/cupertino_page_scaffold.0.dart new file mode 100644 index 0000000000..42903e90ce --- /dev/null +++ b/examples/api/lib/cupertino/page_scaffold/cupertino_page_scaffold.0.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_cupertino.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CupertinoPageScaffold +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [CupertinoPageScaffold] with a [ListView] as a [child]. +// The [CupertinoButton] is connected to a callback that increments a counter. +// The [backgroundColor] can be changed. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/cupertino.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const CupertinoApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _count = 0; + + @override + Widget build(BuildContext context) { + return CupertinoPageScaffold( + // Uncomment to change the background color + // backgroundColor: CupertinoColors.systemPink, + navigationBar: const CupertinoNavigationBar( + middle: Text('Sample Code'), + ), + child: ListView( + children: [ + CupertinoButton( + onPressed: () => setState(() => _count++), + child: const Icon(CupertinoIcons.add), + ), + Center( + child: Text('You have pressed the button $_count times.'), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/refresh/cupertino_sliver_refresh_control.0.dart b/examples/api/lib/cupertino/refresh/cupertino_sliver_refresh_control.0.dart new file mode 100644 index 0000000000..c1c7822fa9 --- /dev/null +++ b/examples/api/lib/cupertino/refresh/cupertino_sliver_refresh_control.0.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_cupertino.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CupertinoSliverRefreshControl +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// When the user scrolls past [refreshTriggerPullDistance], +// this sample shows the default iOS pull to refresh indicator for 1 second and +// adds a new item to the top of the list view. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/cupertino.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const CupertinoApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + List colors = [ + CupertinoColors.systemYellow, + CupertinoColors.systemOrange, + CupertinoColors.systemPink + ]; + List items = [ + Container(color: CupertinoColors.systemPink, height: 100.0), + Container(color: CupertinoColors.systemOrange, height: 100.0), + Container(color: CupertinoColors.systemYellow, height: 100.0), + ]; + + @override + Widget build(BuildContext context) { + return CupertinoApp( + home: CupertinoPageScaffold( + child: CustomScrollView( + physics: + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + slivers: [ + const CupertinoSliverNavigationBar(largeTitle: Text('Scroll down')), + CupertinoSliverRefreshControl( + refreshTriggerPullDistance: 100.0, + refreshIndicatorExtent: 60.0, + onRefresh: () async { + await Future.delayed(const Duration(milliseconds: 1000)); + setState(() { + items.insert( + 0, Container(color: colors[items.length % 3], height: 100.0)); + }); + }, + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => items[index], + childCount: items.length, + ), + ), + ], + ))); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/route/show_cupertino_dialog.0.dart b/examples/api/lib/cupertino/route/show_cupertino_dialog.0.dart new file mode 100644 index 0000000000..721e7325be --- /dev/null +++ b/examples/api/lib/cupertino/route/show_cupertino_dialog.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_restoration_cupertino.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for showCupertinoDialog +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample demonstrates how to create a restorable Cupertino dialog. This is +// accomplished by enabling state restoration by specifying +// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to +// push [CupertinoDialogRoute] when the [CupertinoButton] is tapped. +// +// {@macro flutter.widgets.RestorationManager} + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/cupertino.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const CupertinoApp( + restorationScopeId: 'app', + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return CupertinoPageScaffold( + navigationBar: const CupertinoNavigationBar( + middle: Text('Home'), + ), + child: Center( + child: CupertinoButton( + onPressed: () { + Navigator.of(context).restorablePush(_dialogBuilder); + }, + child: const Text('Open Dialog'), + )), + ); + } + + static Route _dialogBuilder( + BuildContext context, Object? arguments) { + return CupertinoDialogRoute( + context: context, + builder: (BuildContext context) { + return const CupertinoAlertDialog( + title: Text('Title'), + content: Text('Content'), + actions: [ + CupertinoDialogAction(child: Text('Yes')), + CupertinoDialogAction(child: Text('No')), + ], + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/route/show_cupertino_modal_popup.0.dart b/examples/api/lib/cupertino/route/show_cupertino_modal_popup.0.dart new file mode 100644 index 0000000000..2148565b3f --- /dev/null +++ b/examples/api/lib/cupertino/route/show_cupertino_modal_popup.0.dart @@ -0,0 +1,96 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_restoration_cupertino.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for showCupertinoModalPopup +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample demonstrates how to create a restorable Cupertino modal route. +// This is accomplished by enabling state restoration by specifying +// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to +// push [CupertinoModalPopupRoute] when the [CupertinoButton] is tapped. +// +// {@macro flutter.widgets.RestorationManager} + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/cupertino.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const CupertinoApp( + restorationScopeId: 'app', + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return CupertinoPageScaffold( + navigationBar: const CupertinoNavigationBar( + middle: Text('Home'), + ), + child: Center( + child: CupertinoButton( + onPressed: () { + Navigator.of(context).restorablePush(_modalBuilder); + }, + child: const Text('Open Modal'), + )), + ); + } + + static Route _modalBuilder(BuildContext context, Object? arguments) { + return CupertinoModalPopupRoute( + builder: (BuildContext context) { + return CupertinoActionSheet( + title: const Text('Title'), + message: const Text('Message'), + actions: [ + CupertinoActionSheetAction( + child: const Text('Action One'), + onPressed: () { + Navigator.pop(context); + }, + ), + CupertinoActionSheetAction( + child: const Text('Action Two'), + onPressed: () { + Navigator.pop(context); + }, + ), + ], + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.0.dart b/examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.0.dart new file mode 100644 index 0000000000..8cc9c656ba --- /dev/null +++ b/examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.0.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CupertinoScrollbar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [CupertinoScrollbar] that fades in and out of view as scrolling occurs. +// The scrollbar will fade into view as the user scrolls, and fade out when scrolling stops. +// The `thickness` of the scrollbar will animate from 6 pixels to the `thicknessWhileDragging` of 10 +// when it is dragged by the user. The `radius` of the scrollbar thumb corners will animate from 34 +// to the `radiusWhileDragging` of 0 when the scrollbar is being dragged by the user. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/cupertino.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return CupertinoScrollbar( + thickness: 6.0, + thicknessWhileDragging: 10.0, + radius: const Radius.circular(34.0), + radiusWhileDragging: Radius.zero, + child: ListView.builder( + itemCount: 120, + itemBuilder: (BuildContext context, int index) { + return Center( + child: Text('item $index'), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.1.dart b/examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.1.dart new file mode 100644 index 0000000000..7abe4cdc9a --- /dev/null +++ b/examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.1.dart @@ -0,0 +1,91 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CupertinoScrollbar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// When `isAlwaysShown` is true, the scrollbar thumb will remain visible without the +// fade animation. This requires that a [ScrollController] is provided to controller, +// or that the [PrimaryScrollController] is available. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/cupertino.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final ScrollController _controllerOne = ScrollController(); + + @override + Widget build(BuildContext context) { + return CupertinoScrollbar( + thickness: 6.0, + thicknessWhileDragging: 10.0, + radius: const Radius.circular(34.0), + radiusWhileDragging: Radius.zero, + controller: _controllerOne, + isAlwaysShown: true, + child: ListView.builder( + controller: _controllerOne, + itemCount: 120, + itemBuilder: (BuildContext context, int index) { + return Center( + child: Text('item $index'), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/cupertino/text_form_field_row/cupertino_text_form_field_row.1.dart b/examples/api/lib/cupertino/text_form_field_row/cupertino_text_form_field_row.1.dart new file mode 100644 index 0000000000..0bca5434f1 --- /dev/null +++ b/examples/api/lib/cupertino/text_form_field_row/cupertino_text_form_field_row.1.dart @@ -0,0 +1,93 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CupertinoTextFormFieldRow +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to move the focus to the next field when the user +// presses the SPACE key. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/cupertino.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return CupertinoPageScaffold( + child: Center( + child: Form( + autovalidateMode: AutovalidateMode.always, + onChanged: () { + Form.of(primaryFocus!.context!)?.save(); + }, + child: CupertinoFormSection.insetGrouped( + header: const Text('SECTION 1'), + children: List.generate(5, (int index) { + return CupertinoTextFormFieldRow( + prefix: const Text('Enter text'), + placeholder: 'Enter text', + validator: (String? value) { + if (value == null || value.isEmpty) { + return 'Please enter a value'; + } + return null; + }, + ); + }), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/gestures/pointer_signal_resolver/pointer_signal_resolver.0.dart b/examples/api/lib/gestures/pointer_signal_resolver/pointer_signal_resolver.0.dart new file mode 100644 index 0000000000..d04aaf91c7 --- /dev/null +++ b/examples/api/lib/gestures/pointer_signal_resolver/pointer_signal_resolver.0.dart @@ -0,0 +1,186 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for PointerSignalResolver +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example that demonstrates the effect of not using the resolver +// versus using it. +// +// When this example is set to _not_ use the resolver, then triggering the +// mouse wheel over the outer box will cause only the outer box to change +// color, but triggering the mouse wheel over the inner box will cause _both_ +// the outer and the inner boxes to change color (because they're both +// receiving the event). +// +// When this example is set to _use_ the resolver, then only the box located +// directly under the cursor will change color when the mouse wheel is +// triggered. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/gestures.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class ColorChanger extends StatefulWidget { + const ColorChanger({ + Key? key, + required this.initialColor, + required this.useResolver, + this.child, + }) : super(key: key); + + final HSVColor initialColor; + final bool useResolver; + final Widget? child; + + @override + State createState() => _ColorChangerState(); +} + +class _ColorChangerState extends State { + late HSVColor color; + + void rotateColor() { + setState(() { + color = color.withHue((color.hue + 3) % 360.0); + }); + } + + @override + void initState() { + super.initState(); + color = widget.initialColor; + } + + @override + Widget build(BuildContext context) { + return DecoratedBox( + decoration: BoxDecoration( + border: const Border.fromBorderSide(BorderSide()), + color: color.toColor(), + ), + child: Listener( + onPointerSignal: (PointerSignalEvent event) { + if (widget.useResolver) { + GestureBinding.instance!.pointerSignalResolver.register(event, + (PointerSignalEvent event) { + rotateColor(); + }); + } else { + rotateColor(); + } + }, + child: Stack( + fit: StackFit.expand, + children: [ + const AbsorbPointer(), + if (widget.child != null) widget.child!, + ], + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool useResolver = false; + + @override + Widget build(BuildContext context) { + return Material( + child: Stack( + fit: StackFit.expand, + children: [ + ColorChanger( + initialColor: const HSVColor.fromAHSV(0.2, 120.0, 1, 1), + useResolver: useResolver, + child: FractionallySizedBox( + widthFactor: 0.5, + heightFactor: 0.5, + child: ColorChanger( + initialColor: const HSVColor.fromAHSV(1, 60.0, 1, 1), + useResolver: useResolver, + ), + ), + ), + Align( + alignment: Alignment.topLeft, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Switch( + value: useResolver, + onChanged: (bool value) { + setState(() { + useResolver = value; + }); + }, + ), + const Text( + 'Use the PointerSignalResolver?', + style: TextStyle(fontWeight: FontWeight.bold), + ), + ], + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/about/about_list_tile.0.dart b/examples/api/lib/material/about/about_list_tile.0.dart new file mode 100644 index 0000000000..6c3906fcee --- /dev/null +++ b/examples/api/lib/material/about/about_list_tile.0.dart @@ -0,0 +1,109 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AboutListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows two ways to open [AboutDialog]. The first one +// uses an [AboutListTile], and the second uses the [showAboutDialog] function. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final TextStyle textStyle = theme.textTheme.bodyText2!; + final List aboutBoxChildren = [ + const SizedBox(height: 24), + RichText( + text: TextSpan( + children: [ + TextSpan( + style: textStyle, + text: "Flutter is Google's UI toolkit for building beautiful, " + 'natively compiled applications for mobile, web, and desktop ' + 'from a single codebase. Learn more about Flutter at '), + TextSpan( + style: textStyle.copyWith(color: theme.colorScheme.primary), + text: 'https://flutter.dev'), + TextSpan(style: textStyle, text: '.'), + ], + ), + ), + ]; + + return Scaffold( + appBar: AppBar( + title: const Text('Show About Example'), + ), + drawer: Drawer( + child: SingleChildScrollView( + child: SafeArea( + child: AboutListTile( + icon: const Icon(Icons.info), + applicationIcon: const FlutterLogo(), + applicationName: 'Show About Example', + applicationVersion: 'August 2019', + applicationLegalese: '\u{a9} 2014 The Flutter Authors', + aboutBoxChildren: aboutBoxChildren, + ), + ), + ), + ), + body: Center( + child: ElevatedButton( + child: const Text('Show About Example'), + onPressed: () { + showAboutDialog( + context: context, + applicationIcon: const FlutterLogo(), + applicationName: 'Show About Example', + applicationVersion: 'August 2019', + applicationLegalese: '\u{a9} 2014 The Flutter Authors', + children: aboutBoxChildren, + ); + }, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/app_bar/app_bar.0.dart b/examples/api/lib/material/app_bar/app_bar.0.dart new file mode 100644 index 0000000000..cb168a44ce --- /dev/null +++ b/examples/api/lib/material/app_bar/app_bar.0.dart @@ -0,0 +1,96 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AppBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows an [AppBar] with two simple actions. The first action +// opens a [SnackBar], while the second action navigates to a new page. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('AppBar Demo'), + actions: [ + IconButton( + icon: const Icon(Icons.add_alert), + tooltip: 'Show Snackbar', + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('This is a snackbar'))); + }, + ), + IconButton( + icon: const Icon(Icons.navigate_next), + tooltip: 'Go to the next page', + onPressed: () { + Navigator.push(context, MaterialPageRoute( + builder: (BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Next page'), + ), + body: const Center( + child: Text( + 'This is the next page', + style: TextStyle(fontSize: 24), + ), + ), + ); + }, + )); + }, + ), + ], + ), + body: const Center( + child: Text( + 'This is the home page', + style: TextStyle(fontSize: 24), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/app_bar/app_bar.1.dart b/examples/api/lib/material/app_bar/app_bar.1.dart new file mode 100644 index 0000000000..279c75b309 --- /dev/null +++ b/examples/api/lib/material/app_bar/app_bar.1.dart @@ -0,0 +1,71 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AppBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + final ButtonStyle style = + TextButton.styleFrom(primary: Theme.of(context).colorScheme.onPrimary); + return Scaffold( + appBar: AppBar( + actions: [ + TextButton( + style: style, + onPressed: () {}, + child: const Text('Action 1'), + ), + TextButton( + style: style, + onPressed: () {}, + child: const Text('Action 2'), + ) + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/app_bar/sliver_app_bar.1.dart b/examples/api/lib/material/app_bar/sliver_app_bar.1.dart new file mode 100644 index 0000000000..31e2f64520 --- /dev/null +++ b/examples/api/lib/material/app_bar/sliver_app_bar.1.dart @@ -0,0 +1,159 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverAppBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [SliverAppBar] and it's behavior when using the +// [pinned], [snap] and [floating] parameters. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _pinned = true; + bool _snap = false; + bool _floating = false; + +// [SliverAppBar]s are typically used in [CustomScrollView.slivers], which in +// turn can be placed in a [Scaffold.body]. + @override + Widget build(BuildContext context) { + return Scaffold( + body: CustomScrollView( + slivers: [ + SliverAppBar( + pinned: _pinned, + snap: _snap, + floating: _floating, + expandedHeight: 160.0, + flexibleSpace: const FlexibleSpaceBar( + title: Text('SliverAppBar'), + background: FlutterLogo(), + ), + ), + const SliverToBoxAdapter( + child: SizedBox( + height: 20, + child: Center( + child: Text('Scroll to see the SliverAppBar in effect.'), + ), + ), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Container( + color: index.isOdd ? Colors.white : Colors.black12, + height: 100.0, + child: Center( + child: Text('$index', textScaleFactor: 5), + ), + ); + }, + childCount: 20, + ), + ), + ], + ), + bottomNavigationBar: BottomAppBar( + child: Padding( + padding: const EdgeInsets.all(8), + child: OverflowBar( + overflowAlignment: OverflowBarAlignment.center, + children: [ + Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('pinned'), + Switch( + onChanged: (bool val) { + setState(() { + _pinned = val; + }); + }, + value: _pinned, + ), + ], + ), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('snap'), + Switch( + onChanged: (bool val) { + setState(() { + _snap = val; + // Snapping only applies when the app bar is floating. + _floating = _floating || _snap; + }); + }, + value: _snap, + ), + ], + ), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('floating'), + Switch( + onChanged: (bool val) { + setState(() { + _floating = val; + _snap = _snap && _floating; + }); + }, + value: _floating, + ), + ], + ), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/autocomplete/autocomplete.0.dart b/examples/api/lib/material/autocomplete/autocomplete.0.dart new file mode 100644 index 0000000000..3275c2e2b9 --- /dev/null +++ b/examples/api/lib/material/autocomplete/autocomplete.0.dart @@ -0,0 +1,74 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Autocomplete +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to create a very basic Autocomplete widget using the +// default UI. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +void main() => runApp(const AutocompleteExampleApp()); + +class AutocompleteExampleApp extends StatelessWidget { + const AutocompleteExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Autocomplete Basic'), + ), + body: const Center( + child: AutocompleteBasicExample(), + ), + ), + ); + } +} + +class AutocompleteBasicExample extends StatelessWidget { + const AutocompleteBasicExample({Key? key}) : super(key: key); + + static const List _kOptions = [ + 'aardvark', + 'bobcat', + 'chameleon', + ]; + + @override + Widget build(BuildContext context) { + return Autocomplete( + optionsBuilder: (TextEditingValue textEditingValue) { + if (textEditingValue.text == '') { + return const Iterable.empty(); + } + return _kOptions.where((String option) { + return option.contains(textEditingValue.text.toLowerCase()); + }); + }, + onSelected: (String selection) { + print('You just selected $selection'); + }, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/material/autocomplete/autocomplete.1.dart b/examples/api/lib/material/autocomplete/autocomplete.1.dart new file mode 100644 index 0000000000..3a3c6cb1cc --- /dev/null +++ b/examples/api/lib/material/autocomplete/autocomplete.1.dart @@ -0,0 +1,106 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Autocomplete +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to create an Autocomplete widget with a custom type. +// Try searching with text from the name or email field. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +void main() => runApp(const AutocompleteExampleApp()); + +class AutocompleteExampleApp extends StatelessWidget { + const AutocompleteExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Autocomplete Basic User'), + ), + body: const Center( + child: AutocompleteBasicUserExample(), + ), + ), + ); + } +} + +@immutable +class User { + const User({ + required this.email, + required this.name, + }); + + final String email; + final String name; + + @override + String toString() { + return '$name, $email'; + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is User && other.name == name && other.email == email; + } + + @override + int get hashCode => hashValues(email, name); +} + +class AutocompleteBasicUserExample extends StatelessWidget { + const AutocompleteBasicUserExample({Key? key}) : super(key: key); + + static const List _userOptions = [ + User(name: 'Alice', email: 'alice@example.com'), + User(name: 'Bob', email: 'bob@example.com'), + User(name: 'Charlie', email: 'charlie123@gmail.com'), + ]; + + static String _displayStringForOption(User option) => option.name; + + @override + Widget build(BuildContext context) { + return Autocomplete( + displayStringForOption: _displayStringForOption, + optionsBuilder: (TextEditingValue textEditingValue) { + if (textEditingValue.text == '') { + return const Iterable.empty(); + } + return _userOptions.where((User option) { + return option + .toString() + .contains(textEditingValue.text.toLowerCase()); + }); + }, + onSelected: (User selection) { + print('You just selected ${_displayStringForOption(selection)}'); + }, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/material/banner/material_banner.0.dart b/examples/api/lib/material/banner/material_banner.0.dart new file mode 100644 index 0000000000..dedd2d376a --- /dev/null +++ b/examples/api/lib/material/banner/material_banner.0.dart @@ -0,0 +1,74 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MaterialBanner +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Banners placed directly into the widget tree are static. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('The MaterialBanner is below'), + ), + body: const MaterialBanner( + padding: EdgeInsets.all(20), + content: Text('Hello, I am a Material Banner'), + leading: Icon(Icons.agriculture_outlined), + backgroundColor: Color(0xFFE0E0E0), + actions: [ + TextButton( + child: Text('OPEN'), + onPressed: null, + ), + TextButton( + child: Text('DISMISS'), + onPressed: null, + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/banner/material_banner.1.dart b/examples/api/lib/material/banner/material_banner.1.dart new file mode 100644 index 0000000000..9ff96d7b1a --- /dev/null +++ b/examples/api/lib/material/banner/material_banner.1.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MaterialBanner +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// MaterialBanner's can also be presented through a [ScaffoldMessenger]. +// Here is an example where ScaffoldMessengerState.showMaterialBanner() is used to show the MaterialBanner. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('The MaterialBanner is below'), + ), + body: Center( + child: ElevatedButton( + child: const Text('Show MaterialBanner'), + onPressed: () => ScaffoldMessenger.of(context).showMaterialBanner( + const MaterialBanner( + padding: EdgeInsets.all(20), + content: Text('Hello, I am a Material Banner'), + leading: Icon(Icons.agriculture_outlined), + backgroundColor: Colors.green, + actions: [ + TextButton( + child: Text('DISMISS'), + onPressed: null, + ), + ], + ), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/bottom_app_bar/bottom_app_bar.1.dart b/examples/api/lib/material/bottom_app_bar/bottom_app_bar.1.dart new file mode 100644 index 0000000000..43f512805c --- /dev/null +++ b/examples/api/lib/material/bottom_app_bar/bottom_app_bar.1.dart @@ -0,0 +1,186 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for BottomAppBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows the [BottomAppBar], which can be configured to have a notch using the +// [BottomAppBar.shape] property. This also includes an optional [FloatingActionButton], which illustrates +// the [FloatingActionButtonLocation]s in relation to the [BottomAppBar]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() { + runApp(const BottomAppBarDemo()); +} + +class BottomAppBarDemo extends StatefulWidget { + const BottomAppBarDemo({Key? key}) : super(key: key); + + @override + State createState() => _BottomAppBarDemoState(); +} + +class _BottomAppBarDemoState extends State { + bool _showFab = true; + bool _showNotch = true; + FloatingActionButtonLocation _fabLocation = + FloatingActionButtonLocation.endDocked; + + void _onShowNotchChanged(bool value) { + setState(() { + _showNotch = value; + }); + } + + void _onShowFabChanged(bool value) { + setState(() { + _showFab = value; + }); + } + + void _onFabLocationChanged(FloatingActionButtonLocation? value) { + setState(() { + _fabLocation = value ?? FloatingActionButtonLocation.endDocked; + }); + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + automaticallyImplyLeading: false, + title: const Text('Bottom App Bar Demo'), + ), + body: ListView( + padding: const EdgeInsets.only(bottom: 88), + children: [ + SwitchListTile( + title: const Text( + 'Floating Action Button', + ), + value: _showFab, + onChanged: _onShowFabChanged, + ), + SwitchListTile( + title: const Text('Notch'), + value: _showNotch, + onChanged: _onShowNotchChanged, + ), + const Padding( + padding: EdgeInsets.all(16), + child: Text('Floating action button position'), + ), + RadioListTile( + title: const Text('Docked - End'), + value: FloatingActionButtonLocation.endDocked, + groupValue: _fabLocation, + onChanged: _onFabLocationChanged, + ), + RadioListTile( + title: const Text('Docked - Center'), + value: FloatingActionButtonLocation.centerDocked, + groupValue: _fabLocation, + onChanged: _onFabLocationChanged, + ), + RadioListTile( + title: const Text('Floating - End'), + value: FloatingActionButtonLocation.endFloat, + groupValue: _fabLocation, + onChanged: _onFabLocationChanged, + ), + RadioListTile( + title: const Text('Floating - Center'), + value: FloatingActionButtonLocation.centerFloat, + groupValue: _fabLocation, + onChanged: _onFabLocationChanged, + ), + ], + ), + floatingActionButton: _showFab + ? FloatingActionButton( + onPressed: () {}, + child: const Icon(Icons.add), + tooltip: 'Create', + ) + : null, + floatingActionButtonLocation: _fabLocation, + bottomNavigationBar: _DemoBottomAppBar( + fabLocation: _fabLocation, + shape: _showNotch ? const CircularNotchedRectangle() : null, + ), + ), + ); + } +} + +class _DemoBottomAppBar extends StatelessWidget { + const _DemoBottomAppBar({ + this.fabLocation = FloatingActionButtonLocation.endDocked, + this.shape = const CircularNotchedRectangle(), + }); + + final FloatingActionButtonLocation fabLocation; + final NotchedShape? shape; + + static final List centerLocations = + [ + FloatingActionButtonLocation.centerDocked, + FloatingActionButtonLocation.centerFloat, + ]; + + @override + Widget build(BuildContext context) { + return BottomAppBar( + shape: shape, + color: Colors.blue, + child: IconTheme( + data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary), + child: Row( + children: [ + IconButton( + tooltip: 'Open navigation menu', + icon: const Icon(Icons.menu), + onPressed: () {}, + ), + if (centerLocations.contains(fabLocation)) const Spacer(), + IconButton( + tooltip: 'Search', + icon: const Icon(Icons.search), + onPressed: () {}, + ), + IconButton( + tooltip: 'Favorite', + icon: const Icon(Icons.favorite), + onPressed: () {}, + ), + ], + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.0.dart b/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.0.dart new file mode 100644 index 0000000000..a84ad21444 --- /dev/null +++ b/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.0.dart @@ -0,0 +1,115 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for BottomNavigationBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [BottomNavigationBar] as it is used within a [Scaffold] +// widget. The [BottomNavigationBar] has three [BottomNavigationBarItem] +// widgets, which means it defaults to [BottomNavigationBarType.fixed], and +// the [currentIndex] is set to index 0. The selected item is +// amber. The `_onItemTapped` function changes the selected item's index +// and displays a corresponding message in the center of the [Scaffold]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _selectedIndex = 0; + static const TextStyle optionStyle = + TextStyle(fontSize: 30, fontWeight: FontWeight.bold); + static const List _widgetOptions = [ + Text( + 'Index 0: Home', + style: optionStyle, + ), + Text( + 'Index 1: Business', + style: optionStyle, + ), + Text( + 'Index 2: School', + style: optionStyle, + ), + ]; + + void _onItemTapped(int index) { + setState(() { + _selectedIndex = index; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('BottomNavigationBar Sample'), + ), + body: Center( + child: _widgetOptions.elementAt(_selectedIndex), + ), + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'Home', + ), + BottomNavigationBarItem( + icon: Icon(Icons.business), + label: 'Business', + ), + BottomNavigationBarItem( + icon: Icon(Icons.school), + label: 'School', + ), + ], + currentIndex: _selectedIndex, + selectedItemColor: Colors.amber[800], + onTap: _onItemTapped, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.1.dart b/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.1.dart new file mode 100644 index 0000000000..8aa61241d5 --- /dev/null +++ b/examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.1.dart @@ -0,0 +1,130 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for BottomNavigationBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [BottomNavigationBar] as it is used within a [Scaffold] +// widget. The [BottomNavigationBar] has four [BottomNavigationBarItem] +// widgets, which means it defaults to [BottomNavigationBarType.shifting], and +// the [currentIndex] is set to index 0. The selected item is amber in color. +// With each [BottomNavigationBarItem] widget, backgroundColor property is +// also defined, which changes the background color of [BottomNavigationBar], +// when that item is selected. The `_onItemTapped` function changes the +// selected item's index and displays a corresponding message in the center of +// the [Scaffold]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _selectedIndex = 0; + static const TextStyle optionStyle = + TextStyle(fontSize: 30, fontWeight: FontWeight.bold); + static const List _widgetOptions = [ + Text( + 'Index 0: Home', + style: optionStyle, + ), + Text( + 'Index 1: Business', + style: optionStyle, + ), + Text( + 'Index 2: School', + style: optionStyle, + ), + Text( + 'Index 3: Settings', + style: optionStyle, + ), + ]; + + void _onItemTapped(int index) { + setState(() { + _selectedIndex = index; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('BottomNavigationBar Sample'), + ), + body: Center( + child: _widgetOptions.elementAt(_selectedIndex), + ), + bottomNavigationBar: BottomNavigationBar( + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'Home', + backgroundColor: Colors.red, + ), + BottomNavigationBarItem( + icon: Icon(Icons.business), + label: 'Business', + backgroundColor: Colors.green, + ), + BottomNavigationBarItem( + icon: Icon(Icons.school), + label: 'School', + backgroundColor: Colors.purple, + ), + BottomNavigationBarItem( + icon: Icon(Icons.settings), + label: 'Settings', + backgroundColor: Colors.pink, + ), + ], + currentIndex: _selectedIndex, + selectedItemColor: Colors.amber[800], + onTap: _onItemTapped, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart b/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart new file mode 100644 index 0000000000..7cae3c786c --- /dev/null +++ b/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for showModalBottomSheet +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example demonstrates how to use `showModalBottomSheet` to display a +// bottom sheet that obscures the content behind it when a user taps a button. +// It also demonstrates how to close the bottom sheet using the [Navigator] +// when a user taps on a button inside the bottom sheet. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Center( + child: ElevatedButton( + child: const Text('showModalBottomSheet'), + onPressed: () { + showModalBottomSheet( + context: context, + builder: (BuildContext context) { + return Container( + height: 200, + color: Colors.amber, + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + const Text('Modal BottomSheet'), + ElevatedButton( + child: const Text('Close BottomSheet'), + onPressed: () => Navigator.pop(context), + ) + ], + ), + ), + ); + }, + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/card/card.0.dart b/examples/api/lib/material/card/card.0.dart new file mode 100644 index 0000000000..abafd5c83b --- /dev/null +++ b/examples/api/lib/material/card/card.0.dart @@ -0,0 +1,86 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Card +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows creation of a [Card] widget that shows album information +// and two actions. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Center( + child: Card( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const ListTile( + leading: Icon(Icons.album), + title: Text('The Enchanted Nightingale'), + subtitle: Text('Music by Julie Gable. Lyrics by Sidney Stein.'), + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + child: const Text('BUY TICKETS'), + onPressed: () {/* ... */}, + ), + const SizedBox(width: 8), + TextButton( + child: const Text('LISTEN'), + onPressed: () {/* ... */}, + ), + const SizedBox(width: 8), + ], + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/card/card.1.dart b/examples/api/lib/material/card/card.1.dart new file mode 100644 index 0000000000..09ccd12aa5 --- /dev/null +++ b/examples/api/lib/material/card/card.1.dart @@ -0,0 +1,73 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Card +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows creation of a [Card] widget that can be tapped. When +// tapped this [Card]'s [InkWell] displays an "ink splash" that fills the +// entire card. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Center( + child: Card( + child: InkWell( + splashColor: Colors.blue.withAlpha(30), + onTap: () { + print('Card tapped.'); + }, + child: const SizedBox( + width: 300, + height: 100, + child: Text('A card that can be tapped'), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/checkbox/checkbox.0.dart b/examples/api/lib/material/checkbox/checkbox.0.dart new file mode 100644 index 0000000000..c5a4a90c10 --- /dev/null +++ b/examples/api/lib/material/checkbox/checkbox.0.dart @@ -0,0 +1,92 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Checkbox +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how you can override the default theme of +// of a [Checkbox] with a [MaterialStateProperty]. +// In this example, the checkbox's color will be `Colors.blue` when the [Checkbox] +// is being pressed, hovered, or focused. Otherwise, the checkbox's color will +// be `Colors.red`. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool isChecked = false; + + @override + Widget build(BuildContext context) { + Color getColor(Set states) { + const Set interactiveStates = { + MaterialState.pressed, + MaterialState.hovered, + MaterialState.focused, + }; + if (states.any(interactiveStates.contains)) { + return Colors.blue; + } + return Colors.red; + } + + return Checkbox( + checkColor: Colors.white, + fillColor: MaterialStateProperty.resolveWith(getColor), + value: isChecked, + onChanged: (bool? value) { + setState(() { + isChecked = value!; + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.0.dart b/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.0.dart new file mode 100644 index 0000000000..b4252ad7c7 --- /dev/null +++ b/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.0.dart @@ -0,0 +1,87 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CheckboxListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![CheckboxListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile.png) +// +// This widget shows a checkbox that, when checked, slows down all animations +// (including the animation of the checkbox itself getting checked!). +// +// This sample requires that you also import 'package:flutter/scheduler.dart', +// so that you can reference [timeDilation]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/scheduler.dart' show timeDilation; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return CheckboxListTile( + title: const Text('Animate Slowly'), + value: timeDilation != 1.0, + onChanged: (bool? value) { + setState(() { + timeDilation = value! ? 10.0 : 1.0; + }); + }, + secondary: const Icon(Icons.hourglass_empty), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.1.dart b/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.1.dart new file mode 100644 index 0000000000..98858387e3 --- /dev/null +++ b/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.1.dart @@ -0,0 +1,141 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CheckboxListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![Checkbox list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_semantics.png) +// +// Here is an example of a custom labeled checkbox widget, called +// LinkedLabelCheckbox, that includes an interactive [RichText] widget that +// handles tap gestures. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/gestures.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class LinkedLabelCheckbox extends StatelessWidget { + const LinkedLabelCheckbox({ + Key? key, + required this.label, + required this.padding, + required this.value, + required this.onChanged, + }) : super(key: key); + + final String label; + final EdgeInsets padding; + final bool value; + final ValueChanged onChanged; + + @override + Widget build(BuildContext context) { + return Padding( + padding: padding, + child: Row( + children: [ + Expanded( + child: RichText( + text: TextSpan( + text: label, + style: const TextStyle( + color: Colors.blueAccent, + decoration: TextDecoration.underline, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + print('Label has been tapped.'); + }, + ), + ), + ), + Checkbox( + value: value, + onChanged: (bool? newValue) { + onChanged(newValue!); + }, + ), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _isSelected = false; + + @override + Widget build(BuildContext context) { + return LinkedLabelCheckbox( + label: 'Linked, tappable label text', + padding: const EdgeInsets.symmetric(horizontal: 20.0), + value: _isSelected, + onChanged: (bool newValue) { + setState(() { + _isSelected = newValue; + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.2.dart b/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.2.dart new file mode 100644 index 0000000000..3b06398133 --- /dev/null +++ b/examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.2.dart @@ -0,0 +1,123 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CheckboxListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![Custom checkbox list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_custom.png) +// +// Here is an example of a custom LabeledCheckbox widget, but you can easily +// make your own configurable widget. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class LabeledCheckbox extends StatelessWidget { + const LabeledCheckbox({ + Key? key, + required this.label, + required this.padding, + required this.value, + required this.onChanged, + }) : super(key: key); + + final String label; + final EdgeInsets padding; + final bool value; + final ValueChanged onChanged; + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: () { + onChanged(!value); + }, + child: Padding( + padding: padding, + child: Row( + children: [ + Expanded(child: Text(label)), + Checkbox( + value: value, + onChanged: (bool? newValue) { + onChanged(newValue!); + }, + ), + ], + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _isSelected = false; + + @override + Widget build(BuildContext context) { + return LabeledCheckbox( + label: 'This is the label text', + padding: const EdgeInsets.symmetric(horizontal: 20.0), + value: _isSelected, + onChanged: (bool newValue) { + setState(() { + _isSelected = newValue; + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/chip/deletable_chip_attributes.on_deleted.0.dart b/examples/api/lib/material/chip/deletable_chip_attributes.on_deleted.0.dart new file mode 100644 index 0000000000..816c0b9450 --- /dev/null +++ b/examples/api/lib/material/chip/deletable_chip_attributes.on_deleted.0.dart @@ -0,0 +1,120 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DeletableChipAttributes.onDeleted +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to use [onDeleted] to remove an entry when the +// delete button is tapped. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class Actor { + const Actor(this.name, this.initials); + final String name; + final String initials; +} + +class CastList extends StatefulWidget { + const CastList({Key? key}) : super(key: key); + + @override + State createState() => CastListState(); +} + +class CastListState extends State { + final List _cast = [ + const Actor('Aaron Burr', 'AB'), + const Actor('Alexander Hamilton', 'AH'), + const Actor('Eliza Hamilton', 'EH'), + const Actor('James Madison', 'JM'), + ]; + + Iterable get actorWidgets sync* { + for (final Actor actor in _cast) { + yield Padding( + padding: const EdgeInsets.all(4.0), + child: Chip( + avatar: CircleAvatar(child: Text(actor.initials)), + label: Text(actor.name), + onDeleted: () { + setState(() { + _cast.removeWhere((Actor entry) { + return entry.name == actor.name; + }); + }); + }, + ), + ); + } + } + + @override + Widget build(BuildContext context) { + return Wrap( + children: actorWidgets.toList(), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return const CastList(); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/data_table/data_table.0.dart b/examples/api/lib/material/data_table/data_table.0.dart new file mode 100644 index 0000000000..9df66572bb --- /dev/null +++ b/examples/api/lib/material/data_table/data_table.0.dart @@ -0,0 +1,106 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DataTable +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to display a [DataTable] with three columns: name, age, and +// role. The columns are defined by three [DataColumn] objects. The table +// contains three rows of data for three example users, the data for which +// is defined by three [DataRow] objects. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/data_table.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return DataTable( + columns: const [ + DataColumn( + label: Text( + 'Name', + style: TextStyle(fontStyle: FontStyle.italic), + ), + ), + DataColumn( + label: Text( + 'Age', + style: TextStyle(fontStyle: FontStyle.italic), + ), + ), + DataColumn( + label: Text( + 'Role', + style: TextStyle(fontStyle: FontStyle.italic), + ), + ), + ], + rows: const [ + DataRow( + cells: [ + DataCell(Text('Sarah')), + DataCell(Text('19')), + DataCell(Text('Student')), + ], + ), + DataRow( + cells: [ + DataCell(Text('Janine')), + DataCell(Text('43')), + DataCell(Text('Professor')), + ], + ), + DataRow( + cells: [ + DataCell(Text('William')), + DataCell(Text('27')), + DataCell(Text('Associate Professor')), + ], + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/data_table/data_table.1.dart b/examples/api/lib/material/data_table/data_table.1.dart new file mode 100644 index 0000000000..454c24857d --- /dev/null +++ b/examples/api/lib/material/data_table/data_table.1.dart @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DataTable +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to display a [DataTable] with alternate colors per +// row, and a custom color for when the row is selected. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + static const int numItems = 10; + List selected = List.generate(numItems, (int index) => false); + + @override + Widget build(BuildContext context) { + return SizedBox( + width: double.infinity, + child: DataTable( + columns: const [ + DataColumn( + label: Text('Number'), + ), + ], + rows: List.generate( + numItems, + (int index) => DataRow( + color: MaterialStateProperty.resolveWith( + (Set states) { + // All rows will have the same selected color. + if (states.contains(MaterialState.selected)) { + return Theme.of(context).colorScheme.primary.withOpacity(0.08); + } + // Even rows will have a grey color. + if (index.isEven) { + return Colors.grey.withOpacity(0.3); + } + return null; // Use default value for other states and odd rows. + }), + cells: [DataCell(Text('Row $index'))], + selected: selected[index], + onSelectChanged: (bool? value) { + setState(() { + selected[index] = value!; + }); + }, + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/date_picker/show_date_picker.0.dart b/examples/api/lib/material/date_picker/show_date_picker.0.dart new file mode 100644 index 0000000000..09403e3a82 --- /dev/null +++ b/examples/api/lib/material/date_picker/show_date_picker.0.dart @@ -0,0 +1,132 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_restoration_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for showDatePicker +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample demonstrates how to create a restorable Material date picker. +// This is accomplished by enabling state restoration by specifying +// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to +// push [DatePickerDialog] when the button is tapped. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + restorationScopeId: 'app', + title: _title, + home: MyStatefulWidget(restorationId: 'main'), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key, this.restorationId}) : super(key: key); + + final String? restorationId; + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// RestorationProperty objects can be used because of RestorationMixin. +class _MyStatefulWidgetState extends State + with RestorationMixin { + // In this example, the restoration ID for the mixin is passed in through + // the [StatefulWidget]'s constructor. + @override + String? get restorationId => widget.restorationId; + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final RestorableDateTime _selectedDate = + RestorableDateTime(DateTime(2021, 7, 25)); + late final RestorableRouteFuture _restorableDatePickerRouteFuture = + RestorableRouteFuture( + onComplete: _selectDate, + onPresent: (NavigatorState navigator, Object? arguments) { + return navigator.restorablePush( + _datePickerRoute, + arguments: _selectedDate.value.millisecondsSinceEpoch, + ); + }, + ); + + static Route _datePickerRoute( + BuildContext context, + Object? arguments, + ) { + return DialogRoute( + context: context, + builder: (BuildContext context) { + return DatePickerDialog( + restorationId: 'date_picker_dialog', + initialEntryMode: DatePickerEntryMode.calendarOnly, + initialDate: DateTime.fromMillisecondsSinceEpoch(arguments! as int), + firstDate: DateTime(2021, 1, 1), + lastDate: DateTime(2022, 1, 1), + ); + }, + ); + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_selectedDate, 'selected_date'); + registerForRestoration( + _restorableDatePickerRouteFuture, 'date_picker_route_future'); + } + + void _selectDate(DateTime? newSelectedDate) { + if (newSelectedDate != null) { + setState(() { + _selectedDate.value = newSelectedDate; + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text( + 'Selected: ${_selectedDate.value.day}/${_selectedDate.value.month}/${_selectedDate.value.year}'), + )); + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: OutlinedButton( + onPressed: () { + _restorableDatePickerRouteFuture.present(); + }, + child: const Text('Open Date Picker'), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/date_picker/show_date_range_picker.0.dart b/examples/api/lib/material/date_picker/show_date_range_picker.0.dart new file mode 100644 index 0000000000..7deac2c22b --- /dev/null +++ b/examples/api/lib/material/date_picker/show_date_range_picker.0.dart @@ -0,0 +1,149 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_restoration_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for showDateRangePicker +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample demonstrates how to create a restorable Material date range picker. +// This is accomplished by enabling state restoration by specifying +// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to +// push [DateRangePickerDialog] when the button is tapped. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + restorationScopeId: 'app', + title: _title, + home: MyStatefulWidget(restorationId: 'main'), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key, this.restorationId}) : super(key: key); + + final String? restorationId; + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// RestorationProperty objects can be used because of RestorationMixin. +class _MyStatefulWidgetState extends State + with RestorationMixin { + // In this example, the restoration ID for the mixin is passed in through + // the [StatefulWidget]'s constructor. + @override + String? get restorationId => widget.restorationId; + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final RestorableDateTimeN _startDate = + RestorableDateTimeN(DateTime(2021, 1, 1)); + final RestorableDateTimeN _endDate = + RestorableDateTimeN(DateTime(2021, 1, 5)); + late final RestorableRouteFuture + _restorableDateRangePickerRouteFuture = + RestorableRouteFuture( + onComplete: _selectDateRange, + onPresent: (NavigatorState navigator, Object? arguments) { + return navigator + .restorablePush(_dateRangePickerRoute, arguments: { + 'initialStartDate': _startDate.value?.millisecondsSinceEpoch, + 'initialEndDate': _endDate.value?.millisecondsSinceEpoch, + }); + }, + ); + + void _selectDateRange(DateTimeRange? newSelectedDate) { + if (newSelectedDate != null) { + setState(() { + _startDate.value = newSelectedDate.start; + _endDate.value = newSelectedDate.end; + }); + } + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_startDate, 'start_date'); + registerForRestoration(_endDate, 'end_date'); + registerForRestoration( + _restorableDateRangePickerRouteFuture, 'date_picker_route_future'); + } + + static Route _dateRangePickerRoute( + BuildContext context, + Object? arguments, + ) { + return DialogRoute( + context: context, + builder: (BuildContext context) { + return DateRangePickerDialog( + restorationId: 'date_picker_dialog', + initialDateRange: + _initialDateTimeRange(arguments! as Map), + firstDate: DateTime(2021, 1, 1), + currentDate: DateTime(2021, 1, 25), + lastDate: DateTime(2022, 1, 1), + ); + }, + ); + } + + static DateTimeRange? _initialDateTimeRange(Map arguments) { + if (arguments['initialStartDate'] != null && + arguments['initialEndDate'] != null) { + return DateTimeRange( + start: DateTime.fromMillisecondsSinceEpoch( + arguments['initialStartDate'] as int), + end: DateTime.fromMillisecondsSinceEpoch( + arguments['initialEndDate'] as int), + ); + } + + return null; + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: OutlinedButton( + onPressed: () { + _restorableDateRangePickerRouteFuture.present(); + }, + child: const Text('Open Date Range Picker'), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/dialog/alert_dialog.1.dart b/examples/api/lib/material/dialog/alert_dialog.1.dart new file mode 100644 index 0000000000..98c7e1beb6 --- /dev/null +++ b/examples/api/lib/material/dialog/alert_dialog.1.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AlertDialog +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This demo shows a [TextButton] which when pressed, calls [showDialog]. When called, this method +// displays a Material dialog above the current contents of the app and returns +// a [Future] that completes when the dialog is dismissed. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return TextButton( + onPressed: () => showDialog( + context: context, + builder: (BuildContext context) => AlertDialog( + title: const Text('AlertDialog Title'), + content: const Text('AlertDialog description'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, 'Cancel'), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () => Navigator.pop(context, 'OK'), + child: const Text('OK'), + ), + ], + ), + ), + child: const Text('Show Dialog'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/dialog/show_dialog.0.dart b/examples/api/lib/material/dialog/show_dialog.0.dart new file mode 100644 index 0000000000..0e44b63bfa --- /dev/null +++ b/examples/api/lib/material/dialog/show_dialog.0.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_restoration_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for showDialog +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample demonstrates how to create a restorable Material dialog. This is +// accomplished by enabling state restoration by specifying +// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to +// push [DialogRoute] when the button is tapped. +// +// {@macro flutter.widgets.RestorationManager} + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + restorationScopeId: 'app', + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: OutlinedButton( + onPressed: () { + Navigator.of(context).restorablePush(_dialogBuilder); + }, + child: const Text('Open Dialog'), + ), + ), + ); + } + + static Route _dialogBuilder( + BuildContext context, Object? arguments) { + return DialogRoute( + context: context, + builder: (BuildContext context) => + const AlertDialog(title: Text('Material Alert!')), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/divider/divider.0.dart b/examples/api/lib/material/divider/divider.0.dart new file mode 100644 index 0000000000..e44e495780 --- /dev/null +++ b/examples/api/lib/material/divider/divider.0.dart @@ -0,0 +1,102 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Divider +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to display a Divider between an orange and blue box +// inside a column. The Divider is 20 logical pixels in height and contains a +// vertically centered black line that is 5 logical pixels thick. The black +// line is indented by 20 logical pixels. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/divider.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Center( + child: Column( + children: [ + Expanded( + child: Container( + color: Colors.amber, + child: const Center( + child: Text('Above'), + ), + ), + ), + const Divider( + height: 20, + thickness: 5, + indent: 20, + endIndent: 20, + ), + // Subheader example from Material spec. + // https://material.io/components/dividers#types + Container( + padding: const EdgeInsets.only(left: 20), + child: Align( + alignment: AlignmentDirectional.centerStart, + child: Text( + 'Subheader', + style: Theme.of(context).textTheme.caption, + textAlign: TextAlign.start, + ), + ), + ), + Expanded( + child: Container( + color: Theme.of(context).colorScheme.primary, + child: const Center( + child: Text('Below'), + ), + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/divider/vertical_divider.0.dart b/examples/api/lib/material/divider/vertical_divider.0.dart new file mode 100644 index 0000000000..daf05db768 --- /dev/null +++ b/examples/api/lib/material/divider/vertical_divider.0.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for VerticalDivider +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to display a [VerticalDivider] between an purple and orange box +// inside a [Row]. The [VerticalDivider] is 20 logical pixels in width and contains a +// horizontally centered black line that is 1 logical pixels thick. The grey +// line is indented by 20 logical pixels. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + padding: const EdgeInsets.all(10), + child: Row( + children: [ + Expanded( + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.deepPurpleAccent, + ), + ), + ), + const VerticalDivider( + color: Colors.grey, + thickness: 1, + indent: 20, + endIndent: 0, + width: 20, + ), + Expanded( + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.deepOrangeAccent, + ), + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/dropdown/dropdown_button.0.dart b/examples/api/lib/material/dropdown/dropdown_button.0.dart new file mode 100644 index 0000000000..98327b766b --- /dev/null +++ b/examples/api/lib/material/dropdown/dropdown_button.0.dart @@ -0,0 +1,93 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DropdownButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a `DropdownButton` with a large arrow icon, +// purple text style, and bold purple underline, whose value is one of "One", +// "Two", "Free", or "Four". +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/dropdown_button.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + String dropdownValue = 'One'; + + @override + Widget build(BuildContext context) { + return DropdownButton( + value: dropdownValue, + icon: const Icon(Icons.arrow_downward), + iconSize: 24, + elevation: 16, + style: const TextStyle(color: Colors.deepPurple), + underline: Container( + height: 2, + color: Colors.deepPurpleAccent, + ), + onChanged: (String? newValue) { + setState(() { + dropdownValue = newValue!; + }); + }, + items: ['One', 'Two', 'Free', 'Four'] + .map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/dropdown/dropdown_button.selected_item_builder.0.dart b/examples/api/lib/material/dropdown/dropdown_button.selected_item_builder.0.dart new file mode 100644 index 0000000000..ebd4982e66 --- /dev/null +++ b/examples/api/lib/material/dropdown/dropdown_button.selected_item_builder.0.dart @@ -0,0 +1,84 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DropdownButton.selectedItemBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a `DropdownButton` with a button with [Text] that +// corresponds to but is unique from [DropdownMenuItem]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final List items = ['1', '2', '3']; + String selectedItem = '1'; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: DropdownButton( + value: selectedItem, + onChanged: (String? string) => setState(() => selectedItem = string!), + selectedItemBuilder: (BuildContext context) { + return items.map((String item) { + return Text(item); + }).toList(); + }, + items: items.map((String item) { + return DropdownMenuItem( + child: Text('Log $item'), + value: item, + ); + }).toList(), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/dropdown/dropdown_button.style.0.dart b/examples/api/lib/material/dropdown/dropdown_button.style.0.dart new file mode 100644 index 0000000000..1776848558 --- /dev/null +++ b/examples/api/lib/material/dropdown/dropdown_button.style.0.dart @@ -0,0 +1,93 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DropdownButton.style +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a `DropdownButton` with a dropdown button text style +// that is different than its menu items. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + List options = ['One', 'Two', 'Free', 'Four']; + String dropdownValue = 'One'; + + @override + Widget build(BuildContext context) { + return Container( + alignment: Alignment.center, + color: Colors.blue, + child: DropdownButton( + value: dropdownValue, + onChanged: (String? newValue) { + setState(() { + dropdownValue = newValue!; + }); + }, + style: const TextStyle(color: Colors.blue), + selectedItemBuilder: (BuildContext context) { + return options.map((String value) { + return Text( + dropdownValue, + style: const TextStyle(color: Colors.white), + ); + }).toList(); + }, + items: options.map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/elevated_button/elevated_button.0.dart b/examples/api/lib/material/elevated_button/elevated_button.0.dart new file mode 100644 index 0000000000..a87dc98ae7 --- /dev/null +++ b/examples/api/lib/material/elevated_button/elevated_button.0.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ElevatedButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample produces an enabled and a disabled ElevatedButton. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + final ButtonStyle style = + ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20)); + + return Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ElevatedButton( + style: style, + onPressed: null, + child: const Text('Disabled'), + ), + const SizedBox(height: 30), + ElevatedButton( + style: style, + onPressed: () {}, + child: const Text('Enabled'), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/expansion_panel/expansion_panel_list.0.dart b/examples/api/lib/material/expansion_panel/expansion_panel_list.0.dart new file mode 100644 index 0000000000..54335dcb44 --- /dev/null +++ b/examples/api/lib/material/expansion_panel/expansion_panel_list.0.dart @@ -0,0 +1,127 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ExpansionPanelList +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is a simple example of how to implement ExpansionPanelList. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// stores ExpansionPanel state information +class Item { + Item({ + required this.expandedValue, + required this.headerValue, + this.isExpanded = false, + }); + + String expandedValue; + String headerValue; + bool isExpanded; +} + +List generateItems(int numberOfItems) { + return List.generate(numberOfItems, (int index) { + return Item( + headerValue: 'Panel $index', + expandedValue: 'This is item number $index', + ); + }); +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final List _data = generateItems(8); + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Container( + child: _buildPanel(), + ), + ); + } + + Widget _buildPanel() { + return ExpansionPanelList( + expansionCallback: (int index, bool isExpanded) { + setState(() { + _data[index].isExpanded = !isExpanded; + }); + }, + children: _data.map((Item item) { + return ExpansionPanel( + headerBuilder: (BuildContext context, bool isExpanded) { + return ListTile( + title: Text(item.headerValue), + ); + }, + body: ListTile( + title: Text(item.expandedValue), + subtitle: + const Text('To delete this panel, tap the trash can icon'), + trailing: const Icon(Icons.delete), + onTap: () { + setState(() { + _data.removeWhere((Item currentItem) => item == currentItem); + }); + }), + isExpanded: item.isExpanded, + ); + }).toList(), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart b/examples/api/lib/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart new file mode 100644 index 0000000000..7c68edd189 --- /dev/null +++ b/examples/api/lib/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart @@ -0,0 +1,124 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ExpansionPanelList.ExpansionPanelList.radio +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is a simple example of how to implement ExpansionPanelList.radio. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// stores ExpansionPanel state information +class Item { + Item({ + required this.id, + required this.expandedValue, + required this.headerValue, + }); + + int id; + String expandedValue; + String headerValue; +} + +List generateItems(int numberOfItems) { + return List.generate(numberOfItems, (int index) { + return Item( + id: index, + headerValue: 'Panel $index', + expandedValue: 'This is item number $index', + ); + }); +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final List _data = generateItems(8); + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Container( + child: _buildPanel(), + ), + ); + } + + Widget _buildPanel() { + return ExpansionPanelList.radio( + initialOpenPanelValue: 2, + children: _data.map((Item item) { + return ExpansionPanelRadio( + value: item.id, + headerBuilder: (BuildContext context, bool isExpanded) { + return ListTile( + title: Text(item.headerValue), + ); + }, + body: ListTile( + title: Text(item.expandedValue), + subtitle: + const Text('To delete this panel, tap the trash can icon'), + trailing: const Icon(Icons.delete), + onTap: () { + setState(() { + _data + .removeWhere((Item currentItem) => item == currentItem); + }); + })); + }).toList(), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/expansion_tile/expansion_tile.0.dart b/examples/api/lib/material/expansion_tile/expansion_tile.0.dart new file mode 100644 index 0000000000..9ac967e09d --- /dev/null +++ b/examples/api/lib/material/expansion_tile/expansion_tile.0.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ExpansionTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example demonstrates different configurations of ExpansionTile. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _customTileExpanded = false; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + const ExpansionTile( + title: Text('ExpansionTile 1'), + subtitle: Text('Trailing expansion arrow icon'), + children: [ + ListTile(title: Text('This is tile number 1')), + ], + ), + ExpansionTile( + title: const Text('ExpansionTile 2'), + subtitle: const Text('Custom expansion arrow icon'), + trailing: Icon( + _customTileExpanded + ? Icons.arrow_drop_down_circle + : Icons.arrow_drop_down, + ), + children: const [ + ListTile(title: Text('This is tile number 2')), + ], + onExpansionChanged: (bool expanded) { + setState(() => _customTileExpanded = expanded); + }, + ), + const ExpansionTile( + title: Text('ExpansionTile 3'), + subtitle: Text('Leading expansion arrow icon'), + controlAffinity: ListTileControlAffinity.leading, + children: [ + ListTile(title: Text('This is tile number 3')), + ], + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/flexible_space_bar/flexible_space_bar.0.dart b/examples/api/lib/material/flexible_space_bar/flexible_space_bar.0.dart new file mode 100644 index 0000000000..beff081730 --- /dev/null +++ b/examples/api/lib/material/flexible_space_bar/flexible_space_bar.0.dart @@ -0,0 +1,110 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FlexibleSpaceBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample application demonstrates the different features of the +// [FlexibleSpaceBar] when used in a [SliverAppBar]. This app bar is configured +// to stretch into the overscroll space, and uses the +// [FlexibleSpaceBar.stretchModes] to apply `fadeTitle`, `blurBackground` and +// `zoomBackground`. The app bar also makes use of [CollapseMode.parallax] by +// default. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() => runApp(const MaterialApp(home: MyApp())); + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: CustomScrollView( + physics: const BouncingScrollPhysics( + parent: AlwaysScrollableScrollPhysics()), + slivers: [ + SliverAppBar( + stretch: true, + onStretchTrigger: () { + // Function callback for stretch + return Future.value(); + }, + expandedHeight: 300.0, + flexibleSpace: FlexibleSpaceBar( + stretchModes: const [ + StretchMode.zoomBackground, + StretchMode.blurBackground, + StretchMode.fadeTitle, + ], + centerTitle: true, + title: const Text('Flight Report'), + background: Stack( + fit: StackFit.expand, + children: [ + Image.network( + 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg', + fit: BoxFit.cover, + ), + const DecoratedBox( + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment(0.0, 0.5), + end: Alignment.center, + colors: [ + Color(0x60000000), + Color(0x00000000), + ], + ), + ), + ), + ], + ), + ), + ), + SliverList( + delegate: SliverChildListDelegate( + const [ + ListTile( + leading: Icon(Icons.wb_sunny), + title: Text('Sunday'), + subtitle: Text('sunny, h: 80, l: 65'), + ), + ListTile( + leading: Icon(Icons.wb_sunny), + title: Text('Monday'), + subtitle: Text('sunny, h: 80, l: 65'), + ), + // ListTiles++ + ], + ), + ), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/material/floating_action_button/floating_action_button.0.dart b/examples/api/lib/material/floating_action_button/floating_action_button.0.dart new file mode 100644 index 0000000000..e515da123d --- /dev/null +++ b/examples/api/lib/material/floating_action_button/floating_action_button.0.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FloatingActionButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to display a [FloatingActionButton] in a +// [Scaffold], with a pink [backgroundColor] and a thumbs up [Icon]. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Floating Action Button'), + ), + body: const Center(child: Text('Press the button below!')), + floatingActionButton: FloatingActionButton( + onPressed: () { + // Add your onPressed code here! + }, + child: const Icon(Icons.navigation), + backgroundColor: Colors.green, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/floating_action_button/floating_action_button.1.dart b/examples/api/lib/material/floating_action_button/floating_action_button.1.dart new file mode 100644 index 0000000000..81b99e665a --- /dev/null +++ b/examples/api/lib/material/floating_action_button/floating_action_button.1.dart @@ -0,0 +1,73 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FloatingActionButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to make an extended [FloatingActionButton] in a +// [Scaffold], with a pink [backgroundColor], a thumbs up [Icon] and a +// [Text] label that reads "Approve". +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_label.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Floating Action Button Label'), + ), + body: const Center( + child: Text('Press the button with a label below!'), + ), + floatingActionButton: FloatingActionButton.extended( + onPressed: () { + // Add your onPressed code here! + }, + label: const Text('Approve'), + icon: const Icon(Icons.thumb_up), + backgroundColor: Colors.pink, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/floating_action_button_location/standard_fab_location.0.dart b/examples/api/lib/material/floating_action_button_location/standard_fab_location.0.dart new file mode 100644 index 0000000000..13b1ff996a --- /dev/null +++ b/examples/api/lib/material/floating_action_button_location/standard_fab_location.0.dart @@ -0,0 +1,94 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for StandardFabLocation +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This is an example of a user-defined [FloatingActionButtonLocation]. +// +// The example shows a [Scaffold] with an [AppBar], a [BottomAppBar], and a +// [FloatingActionButton] using a custom [FloatingActionButtonLocation]. +// +// The new [FloatingActionButtonLocation] is defined +// by extending [StandardFabLocation] with two mixins, +// [FabEndOffsetX] and [FabFloatOffsetY], and overriding the +// [getOffsetX] method to adjust the FAB's x-coordinate, creating a +// [FloatingActionButtonLocation] slightly different from +// [FloatingActionButtonLocation.endFloat]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class AlmostEndFloatFabLocation extends StandardFabLocation + with FabEndOffsetX, FabFloatOffsetY { + @override + double getOffsetX( + ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { + final double directionalAdjustment = + scaffoldGeometry.textDirection == TextDirection.ltr ? -50.0 : 50.0; + return super.getOffsetX(scaffoldGeometry, adjustment) + + directionalAdjustment; + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Home page'), + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + print('FAB pressed.'); + }, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + floatingActionButtonLocation: AlmostEndFloatFabLocation(), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/icon_button/icon_button.0.dart b/examples/api/lib/material/icon_button/icon_button.0.dart new file mode 100644 index 0000000000..83ac1954ee --- /dev/null +++ b/examples/api/lib/material/icon_button/icon_button.0.dart @@ -0,0 +1,90 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for IconButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows an `IconButton` that uses the Material icon "volume_up" to +// increase the volume. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +double _volume = 0.0; + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + icon: const Icon(Icons.volume_up), + tooltip: 'Increase volume by 10', + onPressed: () { + setState(() { + _volume += 10; + }); + }, + ), + Text('Volume : $_volume') + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/icon_button/icon_button.1.dart b/examples/api/lib/material/icon_button/icon_button.1.dart new file mode 100644 index 0000000000..1e9df6ea6c --- /dev/null +++ b/examples/api/lib/material/icon_button/icon_button.1.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for IconButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this sample the icon button's background color is defined with an [Ink] +// widget whose child is an [IconButton]. The icon button's filled background +// is a light shade of blue, it's a filled circle, and it's as big as the +// button is. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button_background.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return Material( + color: Colors.white, + child: Center( + child: Ink( + decoration: const ShapeDecoration( + color: Colors.lightBlue, + shape: CircleBorder(), + ), + child: IconButton( + icon: const Icon(Icons.android), + color: Colors.white, + onPressed: () {}, + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/ink_well/ink_well.0.dart b/examples/api/lib/material/ink_well/ink_well.0.dart new file mode 100644 index 0000000000..62dfdfd6ab --- /dev/null +++ b/examples/api/lib/material/ink_well/ink_well.0.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InkWell +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Tap the container to cause it to grow. Then, tap it again and hold before +// the widget reaches its maximum size to observe the clipped ink splash. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + double sideLength = 50; + + @override + Widget build(BuildContext context) { + return AnimatedContainer( + height: sideLength, + width: sideLength, + duration: const Duration(seconds: 2), + curve: Curves.easeIn, + child: Material( + color: Colors.yellow, + child: InkWell( + onTap: () { + setState(() { + sideLength == 50 ? sideLength = 100 : sideLength = 50; + }); + }, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.0.dart b/examples/api/lib/material/input_decorator/input_decoration.0.dart new file mode 100644 index 0000000000..7b1bb00743 --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.0.dart @@ -0,0 +1,71 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InputDecoration +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to style a `TextField` using an `InputDecorator`. The +// TextField displays a "send message" icon to the left of the input area, +// which is surrounded by a border an all sides. It displays the `hintText` +// inside the input area to help the user understand what input is required. It +// displays the `helperText` and `counterText` below the input area. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return const TextField( + decoration: InputDecoration( + icon: Icon(Icons.send), + hintText: 'Hint Text', + helperText: 'Helper Text', + counterText: '0 characters', + border: OutlineInputBorder(), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.1.dart b/examples/api/lib/material/input_decorator/input_decoration.1.dart new file mode 100644 index 0000000000..a0368b724e --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.1.dart @@ -0,0 +1,66 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InputDecoration +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to style a "collapsed" `TextField` using an +// `InputDecorator`. The collapsed `TextField` surrounds the hint text and +// input area with a border, but does not add padding around them. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_collapsed.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return const TextField( + decoration: InputDecoration.collapsed( + hintText: 'Hint Text', + border: OutlineInputBorder(), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.2.dart b/examples/api/lib/material/input_decorator/input_decoration.2.dart new file mode 100644 index 0000000000..a04d025d3b --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.2.dart @@ -0,0 +1,67 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InputDecoration +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to create a `TextField` with hint text, a red border +// on all sides, and an error message. To display a red border and error +// message, provide `errorText` to the `InputDecoration` constructor. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_error.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return const TextField( + decoration: InputDecoration( + hintText: 'Hint Text', + errorText: 'Error Text', + border: OutlineInputBorder(), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.3.dart b/examples/api/lib/material/input_decorator/input_decoration.3.dart new file mode 100644 index 0000000000..b2dd8ba32e --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.3.dart @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InputDecoration +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to style a `TextField` with a round border and +// additional text before and after the input area. It displays "Prefix" before +// the input area, and "Suffix" after the input area. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_prefix_suffix.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return TextFormField( + initialValue: 'abc', + decoration: const InputDecoration( + prefix: Text('Prefix'), + suffix: Text('Suffix'), + border: OutlineInputBorder(), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.label.0.dart b/examples/api/lib/material/input_decorator/input_decoration.label.0.dart new file mode 100644 index 0000000000..93eec55771 --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.label.0.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InputDecoration.label +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a `TextField` with a [Text.rich] widget as the [label]. +// The widget contains multiple [Text] widgets with different [TextStyle]'s. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return const Center( + child: TextField( + decoration: InputDecoration( + label: Text.rich( + TextSpan( + children: [ + WidgetSpan( + child: Text( + 'Username', + ), + ), + WidgetSpan( + child: Text( + '*', + style: TextStyle(color: Colors.red), + ), + ), + ], + ), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.prefix_icon_constraints.0.dart b/examples/api/lib/material/input_decorator/input_decoration.prefix_icon_constraints.0.dart new file mode 100644 index 0000000000..439dfc07cc --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.prefix_icon_constraints.0.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InputDecoration.prefixIconConstraints +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows the differences between two `TextField` widgets when +// [prefixIconConstraints] is set to the default value and when one is not. +// +// Note that [isDense] must be set to true to be able to +// set the constraints smaller than 48px. +// +// If null, [BoxConstraints] with a minimum width and height of 48px is +// used. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + TextField( + decoration: InputDecoration( + hintText: 'Normal Icon Constraints', + prefixIcon: Icon(Icons.search), + ), + ), + SizedBox(height: 10), + TextField( + decoration: InputDecoration( + isDense: true, + hintText: 'Smaller Icon Constraints', + prefixIcon: Icon(Icons.search), + prefixIconConstraints: BoxConstraints( + minHeight: 32, + minWidth: 32, + ), + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/input_decorator/input_decoration.suffix_icon_constraints.0.dart b/examples/api/lib/material/input_decorator/input_decoration.suffix_icon_constraints.0.dart new file mode 100644 index 0000000000..231c95fae6 --- /dev/null +++ b/examples/api/lib/material/input_decorator/input_decoration.suffix_icon_constraints.0.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InputDecoration.suffixIconConstraints +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows the differences between two `TextField` widgets when +// [suffixIconConstraints] is set to the default value and when one is not. +// +// Note that [isDense] must be set to true to be able to +// set the constraints smaller than 48px. +// +// If null, [BoxConstraints] with a minimum width and height of 48px is +// used. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + TextField( + decoration: InputDecoration( + hintText: 'Normal Icon Constraints', + suffixIcon: Icon(Icons.search), + ), + ), + SizedBox(height: 10), + TextField( + decoration: InputDecoration( + isDense: true, + hintText: 'Smaller Icon Constraints', + suffixIcon: Icon(Icons.search), + suffixIconConstraints: BoxConstraints( + minHeight: 32, + minWidth: 32, + ), + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/list_tile/list_tile.4.dart b/examples/api/lib/material/list_tile/list_tile.4.dart new file mode 100644 index 0000000000..c9703c006f --- /dev/null +++ b/examples/api/lib/material/list_tile/list_tile.4.dart @@ -0,0 +1,172 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of a custom list item that resembles a YouTube-related +// video list item created with [Expanded] and [Container] widgets. +// +// ![Custom list item a](https://flutter.github.io/assets-for-api-docs/assets/widgets/custom_list_item_a.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class CustomListItem extends StatelessWidget { + const CustomListItem({ + Key? key, + required this.thumbnail, + required this.title, + required this.user, + required this.viewCount, + }) : super(key: key); + + final Widget thumbnail; + final String title; + final String user; + final int viewCount; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 5.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 2, + child: thumbnail, + ), + Expanded( + flex: 3, + child: _VideoDescription( + title: title, + user: user, + viewCount: viewCount, + ), + ), + const Icon( + Icons.more_vert, + size: 16.0, + ), + ], + ), + ); + } +} + +class _VideoDescription extends StatelessWidget { + const _VideoDescription({ + Key? key, + required this.title, + required this.user, + required this.viewCount, + }) : super(key: key); + + final String title; + final String user; + final int viewCount; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.fromLTRB(5.0, 0.0, 0.0, 0.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + style: const TextStyle( + fontWeight: FontWeight.w500, + fontSize: 14.0, + ), + ), + const Padding(padding: EdgeInsets.symmetric(vertical: 2.0)), + Text( + user, + style: const TextStyle(fontSize: 10.0), + ), + const Padding(padding: EdgeInsets.symmetric(vertical: 1.0)), + Text( + '$viewCount views', + style: const TextStyle(fontSize: 10.0), + ), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return ListView( + padding: const EdgeInsets.all(8.0), + itemExtent: 106.0, + children: [ + CustomListItem( + user: 'Flutter', + viewCount: 999000, + thumbnail: Container( + decoration: const BoxDecoration(color: Colors.blue), + ), + title: 'The Flutter YouTube Channel', + ), + CustomListItem( + user: 'Dash', + viewCount: 884000, + thumbnail: Container( + decoration: const BoxDecoration(color: Colors.yellow), + ), + title: 'Announcing Flutter 1.0', + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/list_tile/list_tile.5.dart b/examples/api/lib/material/list_tile/list_tile.5.dart new file mode 100644 index 0000000000..b777770015 --- /dev/null +++ b/examples/api/lib/material/list_tile/list_tile.5.dart @@ -0,0 +1,217 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of an article list item with multiline titles and +// subtitles. It utilizes [Row]s and [Column]s, as well as [Expanded] and +// [AspectRatio] widgets to organize its layout. +// +// ![Custom list item b](https://flutter.github.io/assets-for-api-docs/assets/widgets/custom_list_item_b.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class _ArticleDescription extends StatelessWidget { + const _ArticleDescription({ + Key? key, + required this.title, + required this.subtitle, + required this.author, + required this.publishDate, + required this.readDuration, + }) : super(key: key); + + final String title; + final String subtitle; + final String author; + final String publishDate; + final String readDuration; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 1, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: const TextStyle( + fontWeight: FontWeight.bold, + ), + ), + const Padding(padding: EdgeInsets.only(bottom: 2.0)), + Text( + subtitle, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: const TextStyle( + fontSize: 12.0, + color: Colors.black54, + ), + ), + ], + ), + ), + Expanded( + flex: 1, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text( + author, + style: const TextStyle( + fontSize: 12.0, + color: Colors.black87, + ), + ), + Text( + '$publishDate - $readDuration', + style: const TextStyle( + fontSize: 12.0, + color: Colors.black54, + ), + ), + ], + ), + ), + ], + ); + } +} + +class CustomListItemTwo extends StatelessWidget { + const CustomListItemTwo({ + Key? key, + required this.thumbnail, + required this.title, + required this.subtitle, + required this.author, + required this.publishDate, + required this.readDuration, + }) : super(key: key); + + final Widget thumbnail; + final String title; + final String subtitle; + final String author; + final String publishDate; + final String readDuration; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 10.0), + child: SizedBox( + height: 100, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AspectRatio( + aspectRatio: 1.0, + child: thumbnail, + ), + Expanded( + child: Padding( + padding: const EdgeInsets.fromLTRB(20.0, 0.0, 2.0, 0.0), + child: _ArticleDescription( + title: title, + subtitle: subtitle, + author: author, + publishDate: publishDate, + readDuration: readDuration, + ), + ), + ) + ], + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return ListView( + padding: const EdgeInsets.all(10.0), + children: [ + CustomListItemTwo( + thumbnail: Container( + decoration: const BoxDecoration(color: Colors.pink), + ), + title: 'Flutter 1.0 Launch', + subtitle: 'Flutter continues to improve and expand its horizons. ' + 'This text should max out at two lines and clip', + author: 'Dash', + publishDate: 'Dec 28', + readDuration: '5 mins', + ), + CustomListItemTwo( + thumbnail: Container( + decoration: const BoxDecoration(color: Colors.blue), + ), + title: 'Flutter 1.2 Release - Continual updates to the framework', + subtitle: 'Flutter once again improves and makes updates.', + author: 'Flutter', + publishDate: 'Feb 26', + readDuration: '12 mins', + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/list_tile/list_tile.selected.0.dart b/examples/api/lib/material/list_tile/list_tile.selected.0.dart new file mode 100644 index 0000000000..7429b95163 --- /dev/null +++ b/examples/api/lib/material/list_tile/list_tile.selected.0.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ListTile.selected +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of using a [StatefulWidget] to keep track of the +// selected index, and using that to set the `selected` property on the +// corresponding [ListTile]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _selectedIndex = 0; + + @override + Widget build(BuildContext context) { + return ListView.builder( + itemCount: 10, + itemBuilder: (BuildContext context, int index) { + return ListTile( + title: Text('Item $index'), + selected: index == _selectedIndex, + onTap: () { + setState(() { + _selectedIndex = index; + }); + }, + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/material_state/material_state_border_side.0.dart b/examples/api/lib/material/material_state/material_state_border_side.0.dart new file mode 100644 index 0000000000..2f5882d2b6 --- /dev/null +++ b/examples/api/lib/material/material_state/material_state_border_side.0.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MaterialStateBorderSide +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example defines a subclass of [MaterialStateBorderSide], that resolves +// to a red border side when its widget is selected. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool isSelected = true; + + @override + Widget build(BuildContext context) { + return FilterChip( + label: const Text('Select chip'), + selected: isSelected, + onSelected: (bool value) { + setState(() { + isSelected = value; + }); + }, + side: MaterialStateBorderSide.resolveWith((Set states) { + if (states.contains(MaterialState.selected)) { + return const BorderSide(width: 1, color: Colors.red); + } + return null; // Defer to default value on the theme or widget. + }), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart b/examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart new file mode 100644 index 0000000000..d3e9d5615c --- /dev/null +++ b/examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart @@ -0,0 +1,90 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MaterialStateMouseCursor +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example defines a mouse cursor that resolves to +// [SystemMouseCursors.forbidden] when its widget is disabled. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/rendering.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class ListTileCursor extends MaterialStateMouseCursor { + @override + MouseCursor resolve(Set states) { + if (states.contains(MaterialState.disabled)) { + return SystemMouseCursors.forbidden; + } + return SystemMouseCursors.click; + } + + @override + String get debugDescription => 'ListTileCursor()'; +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return ListTile( + title: const Text('Disabled ListTile'), + enabled: false, + mouseCursor: ListTileCursor(), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/material_state/material_state_outlined_border.0.dart b/examples/api/lib/material/material_state/material_state_outlined_border.0.dart new file mode 100644 index 0000000000..e9fb8a4424 --- /dev/null +++ b/examples/api/lib/material/material_state/material_state_outlined_border.0.dart @@ -0,0 +1,92 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MaterialStateOutlinedBorder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example defines a subclass of [RoundedRectangleBorder] and an +// implementation of [MaterialStateOutlinedBorder], that resolves to +// [RoundedRectangleBorder] when its widget is selected. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class SelectedBorder extends RoundedRectangleBorder + implements MaterialStateOutlinedBorder { + @override + OutlinedBorder? resolve(Set states) { + if (states.contains(MaterialState.selected)) { + return const RoundedRectangleBorder(); + } + return null; // Defer to default value on the theme or widget. + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool isSelected = true; + + @override + Widget build(BuildContext context) { + return Material( + child: FilterChip( + label: const Text('Select chip'), + selected: isSelected, + onSelected: (bool value) { + setState(() { + isSelected = value; + }); + }, + shape: SelectedBorder(), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/material_state/material_state_property.0.dart b/examples/api/lib/material/material_state/material_state_property.0.dart new file mode 100644 index 0000000000..57f7021987 --- /dev/null +++ b/examples/api/lib/material/material_state/material_state_property.0.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MaterialStateProperty +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how you can override the default text and icon +// color (the "foreground color") of a [TextButton] with a +// [MaterialStateProperty]. In this example, the button's text color +// will be `Colors.blue` when the button is being pressed, hovered, +// or focused. Otherwise, the text color will be `Colors.red`. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + Color getColor(Set states) { + const Set interactiveStates = { + MaterialState.pressed, + MaterialState.hovered, + MaterialState.focused, + }; + if (states.any(interactiveStates.contains)) { + return Colors.blue; + } + return Colors.red; + } + + return TextButton( + style: ButtonStyle( + foregroundColor: MaterialStateProperty.resolveWith(getColor), + ), + onPressed: () {}, + child: const Text('TextButton'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/navigation_rail/navigation_rail.0.dart b/examples/api/lib/material/navigation_rail/navigation_rail.0.dart new file mode 100644 index 0000000000..2bb70b87e1 --- /dev/null +++ b/examples/api/lib/material/navigation_rail/navigation_rail.0.dart @@ -0,0 +1,103 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NavigationRail +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [NavigationRail] used within a Scaffold with 3 +// [NavigationRailDestination]s. The main content is separated by a divider +// (although elevation on the navigation rail can be used instead). The +// `_selectedIndex` is updated by the `onDestinationSelected` callback. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _selectedIndex = 0; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Row( + children: [ + NavigationRail( + selectedIndex: _selectedIndex, + onDestinationSelected: (int index) { + setState(() { + _selectedIndex = index; + }); + }, + labelType: NavigationRailLabelType.selected, + destinations: const [ + NavigationRailDestination( + icon: Icon(Icons.favorite_border), + selectedIcon: Icon(Icons.favorite), + label: Text('First'), + ), + NavigationRailDestination( + icon: Icon(Icons.bookmark_border), + selectedIcon: Icon(Icons.book), + label: Text('Second'), + ), + NavigationRailDestination( + icon: Icon(Icons.star_border), + selectedIcon: Icon(Icons.star), + label: Text('Third'), + ), + ], + ), + const VerticalDivider(thickness: 1, width: 1), + // This is the main content. + Expanded( + child: Center( + child: Text('selectedIndex: $_selectedIndex'), + ), + ) + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/navigation_rail/navigation_rail.extended_animation.0.dart b/examples/api/lib/material/navigation_rail/navigation_rail.extended_animation.0.dart new file mode 100644 index 0000000000..bfe949d458 --- /dev/null +++ b/examples/api/lib/material/navigation_rail/navigation_rail.extended_animation.0.dart @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NavigationRail.extendedAnimation +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to use this animation to create a +// [FloatingActionButton] that animates itself between the normal and +// extended states of the [NavigationRail]. +// +// An instance of `ExtendableFab` would be created for +// [NavigationRail.leading]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//******************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-dartImports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'dart:ui'; + +//* ▲▲▲▲▲▲▲▲ code-dartImports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + final Animation animation = + NavigationRail.extendedAnimation(context); + return AnimatedBuilder( + animation: animation, + builder: (BuildContext context, Widget? child) { + // The extended fab has a shorter height than the regular fab. + return Container( + height: 56, + padding: EdgeInsets.symmetric( + vertical: lerpDouble(0, 6, animation.value)!, + ), + child: animation.value == 0 + ? FloatingActionButton( + child: const Icon(Icons.add), + onPressed: () {}, + ) + : Align( + alignment: AlignmentDirectional.centerStart, + widthFactor: animation.value, + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 8), + child: FloatingActionButton.extended( + icon: const Icon(Icons.add), + label: const Text('CREATE'), + onPressed: () {}, + ), + ), + ), + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/outlined_button/outlined_button.0.dart b/examples/api/lib/material/outlined_button/outlined_button.0.dart new file mode 100644 index 0000000000..c7f07350ec --- /dev/null +++ b/examples/api/lib/material/outlined_button/outlined_button.0.dart @@ -0,0 +1,64 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for OutlinedButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of a basic [OutlinedButton]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return OutlinedButton( + onPressed: () { + print('Received click'); + }, + child: const Text('Click Me'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/progress_indicator/circular_progress_indicator.0.dart b/examples/api/lib/material/progress_indicator/circular_progress_indicator.0.dart new file mode 100644 index 0000000000..45b39cf86c --- /dev/null +++ b/examples/api/lib/material/progress_indicator/circular_progress_indicator.0.dart @@ -0,0 +1,99 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CircularProgressIndicator +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [CircularProgressIndicator] with a changing value. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late AnimationController controller; + + @override + void initState() { + controller = AnimationController( + vsync: this, + duration: const Duration(seconds: 5), + )..addListener(() { + setState(() {}); + }); + controller.repeat(reverse: true); + super.initState(); + } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Text( + 'Linear progress indicator with a fixed color', + style: Theme.of(context).textTheme.headline6, + ), + CircularProgressIndicator( + value: controller.value, + semanticsLabel: 'Linear progress indicator', + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/progress_indicator/linear_progress_indicator.0.dart b/examples/api/lib/material/progress_indicator/linear_progress_indicator.0.dart new file mode 100644 index 0000000000..d2f0ee184e --- /dev/null +++ b/examples/api/lib/material/progress_indicator/linear_progress_indicator.0.dart @@ -0,0 +1,99 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for LinearProgressIndicator +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [LinearProgressIndicator] with a changing value. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late AnimationController controller; + + @override + void initState() { + controller = AnimationController( + vsync: this, + duration: const Duration(seconds: 5), + )..addListener(() { + setState(() {}); + }); + controller.repeat(reverse: true); + super.initState(); + } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + const Text( + 'Linear progress indicator with a fixed color', + style: TextStyle(fontSize: 20), + ), + LinearProgressIndicator( + value: controller.value, + semanticsLabel: 'Linear progress indicator', + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/radio/radio.0.dart b/examples/api/lib/material/radio/radio.0.dart new file mode 100644 index 0000000000..a814bfbdb4 --- /dev/null +++ b/examples/api/lib/material/radio/radio.0.dart @@ -0,0 +1,115 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Radio +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of Radio widgets wrapped in ListTiles, which is similar +// to what you could get with the RadioListTile widget. +// +// The currently selected character is passed into `groupValue`, which is +// maintained by the example's `State`. In this case, the first `Radio` +// will start off selected because `_character` is initialized to +// `SingingCharacter.lafayette`. +// +// If the second radio button is pressed, the example's state is updated +// with `setState`, updating `_character` to `SingingCharacter.jefferson`. +// This causes the buttons to rebuild with the updated `groupValue`, and +// therefore the selection of the second button. +// +// Requires one of its ancestors to be a [Material] widget. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +enum SingingCharacter { lafayette, jefferson } + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + SingingCharacter? _character = SingingCharacter.lafayette; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + ListTile( + title: const Text('Lafayette'), + leading: Radio( + value: SingingCharacter.lafayette, + groupValue: _character, + onChanged: (SingingCharacter? value) { + setState(() { + _character = value; + }); + }, + ), + ), + ListTile( + title: const Text('Thomas Jefferson'), + leading: Radio( + value: SingingCharacter.jefferson, + groupValue: _character, + onChanged: (SingingCharacter? value) { + setState(() { + _character = value; + }); + }, + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/radio/radio.toggleable.0.dart b/examples/api/lib/material/radio/radio.toggleable.0.dart new file mode 100644 index 0000000000..4c8049443e --- /dev/null +++ b/examples/api/lib/material/radio/radio.toggleable.0.dart @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Radio.toggleable +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to enable deselecting a radio button by setting the +// [toggleable] attribute. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int? groupValue; + static const List selections = [ + 'Hercules Mulligan', + 'Eliza Hamilton', + 'Philip Schuyler', + 'Maria Reynolds', + 'Samuel Seabury', + ]; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: ListView.builder( + itemBuilder: (BuildContext context, int index) { + return Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Radio( + value: index, + groupValue: groupValue, + // TRY THIS: Try setting the toggleable value to false and + // see how that changes the behavior of the widget. + toggleable: true, + onChanged: (int? value) { + setState(() { + groupValue = value; + }); + }), + Text(selections[index]), + ], + ); + }, + itemCount: selections.length, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/radio_list_tile/radio_list_tile.0.dart b/examples/api/lib/material/radio_list_tile/radio_list_tile.0.dart new file mode 100644 index 0000000000..1c6dfb1d9b --- /dev/null +++ b/examples/api/lib/material/radio_list_tile/radio_list_tile.0.dart @@ -0,0 +1,99 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RadioListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![RadioListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile.png) +// +// This widget shows a pair of radio buttons that control the `_character` +// field. The field is of the type `SingingCharacter`, an enum. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +enum SingingCharacter { lafayette, jefferson } + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + SingingCharacter? _character = SingingCharacter.lafayette; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + RadioListTile( + title: const Text('Lafayette'), + value: SingingCharacter.lafayette, + groupValue: _character, + onChanged: (SingingCharacter? value) { + setState(() { + _character = value; + }); + }, + ), + RadioListTile( + title: const Text('Thomas Jefferson'), + value: SingingCharacter.jefferson, + groupValue: _character, + onChanged: (SingingCharacter? value) { + setState(() { + _character = value; + }); + }, + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/radio_list_tile/radio_list_tile.1.dart b/examples/api/lib/material/radio_list_tile/radio_list_tile.1.dart new file mode 100644 index 0000000000..bc40b81ed7 --- /dev/null +++ b/examples/api/lib/material/radio_list_tile/radio_list_tile.1.dart @@ -0,0 +1,158 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RadioListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![Radio list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile_semantics.png) +// +// Here is an example of a custom labeled radio widget, called +// LinkedLabelRadio, that includes an interactive [RichText] widget that +// handles tap gestures. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/gestures.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class LinkedLabelRadio extends StatelessWidget { + const LinkedLabelRadio({ + Key? key, + required this.label, + required this.padding, + required this.groupValue, + required this.value, + required this.onChanged, + }) : super(key: key); + + final String label; + final EdgeInsets padding; + final bool groupValue; + final bool value; + final ValueChanged onChanged; + + @override + Widget build(BuildContext context) { + return Padding( + padding: padding, + child: Row( + children: [ + Radio( + groupValue: groupValue, + value: value, + onChanged: (bool? newValue) { + onChanged(newValue!); + }), + RichText( + text: TextSpan( + text: label, + style: const TextStyle( + color: Colors.blueAccent, + decoration: TextDecoration.underline, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + print('Label has been tapped.'); + }, + ), + ), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _isRadioSelected = false; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + LinkedLabelRadio( + label: 'First tappable label text', + padding: const EdgeInsets.symmetric(horizontal: 5.0), + value: true, + groupValue: _isRadioSelected, + onChanged: (bool newValue) { + setState(() { + _isRadioSelected = newValue; + }); + }, + ), + LinkedLabelRadio( + label: 'Second tappable label text', + padding: const EdgeInsets.symmetric(horizontal: 5.0), + value: false, + groupValue: _isRadioSelected, + onChanged: (bool newValue) { + setState(() { + _isRadioSelected = newValue; + }); + }, + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/radio_list_tile/radio_list_tile.2.dart b/examples/api/lib/material/radio_list_tile/radio_list_tile.2.dart new file mode 100644 index 0000000000..968360c3df --- /dev/null +++ b/examples/api/lib/material/radio_list_tile/radio_list_tile.2.dart @@ -0,0 +1,145 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RadioListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![Custom radio list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile_custom.png) +// +// Here is an example of a custom LabeledRadio widget, but you can easily +// make your own configurable widget. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class LabeledRadio extends StatelessWidget { + const LabeledRadio({ + Key? key, + required this.label, + required this.padding, + required this.groupValue, + required this.value, + required this.onChanged, + }) : super(key: key); + + final String label; + final EdgeInsets padding; + final bool groupValue; + final bool value; + final ValueChanged onChanged; + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: () { + if (value != groupValue) { + onChanged(value); + } + }, + child: Padding( + padding: padding, + child: Row( + children: [ + Radio( + groupValue: groupValue, + value: value, + onChanged: (bool? newValue) { + onChanged(newValue!); + }, + ), + Text(label), + ], + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _isRadioSelected = false; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + LabeledRadio( + label: 'This is the first label text', + padding: const EdgeInsets.symmetric(horizontal: 5.0), + value: true, + groupValue: _isRadioSelected, + onChanged: (bool newValue) { + setState(() { + _isRadioSelected = newValue; + }); + }, + ), + LabeledRadio( + label: 'This is the second label text', + padding: const EdgeInsets.symmetric(horizontal: 5.0), + value: false, + groupValue: _isRadioSelected, + onChanged: (bool newValue) { + setState(() { + _isRadioSelected = newValue; + }); + }, + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/radio_list_tile/radio_list_tile.toggleable.0.dart b/examples/api/lib/material/radio_list_tile/radio_list_tile.toggleable.0.dart new file mode 100644 index 0000000000..1cde466ce8 --- /dev/null +++ b/examples/api/lib/material/radio_list_tile/radio_list_tile.toggleable.0.dart @@ -0,0 +1,90 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RadioListTile.toggleable +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to enable deselecting a radio button by setting the +// [toggleable] attribute. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int? groupValue; + static const List selections = [ + 'Hercules Mulligan', + 'Eliza Hamilton', + 'Philip Schuyler', + 'Maria Reynolds', + 'Samuel Seabury', + ]; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: ListView.builder( + itemBuilder: (BuildContext context, int index) { + return RadioListTile( + value: index, + groupValue: groupValue, + toggleable: true, + title: Text(selections[index]), + onChanged: (int? value) { + setState(() { + groupValue = value; + }); + }, + ); + }, + itemCount: selections.length, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/range_slider/range_slider.0.dart b/examples/api/lib/material/range_slider/range_slider.0.dart new file mode 100644 index 0000000000..56b414f82b --- /dev/null +++ b/examples/api/lib/material/range_slider/range_slider.0.dart @@ -0,0 +1,84 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RangeSlider +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![A range slider widget, consisting of 5 divisions and showing the default +// value indicator.](https://flutter.github.io/assets-for-api-docs/assets/material/range_slider.png) +// +// This range values are in intervals of 20 because the Range Slider has 5 +// divisions, from 0 to 100. This means are values are split between 0, 20, 40, +// 60, 80, and 100. The range values are initialized with 40 and 80 in this demo. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + RangeValues _currentRangeValues = const RangeValues(40, 80); + + @override + Widget build(BuildContext context) { + return RangeSlider( + values: _currentRangeValues, + min: 0, + max: 100, + divisions: 5, + labels: RangeLabels( + _currentRangeValues.start.round().toString(), + _currentRangeValues.end.round().toString(), + ), + onChanged: (RangeValues values) { + setState(() { + _currentRangeValues = values; + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/reorderable_list/reorderable_list_view.0.dart b/examples/api/lib/material/reorderable_list/reorderable_list_view.0.dart new file mode 100644 index 0000000000..76b8a1b1e9 --- /dev/null +++ b/examples/api/lib/material/reorderable_list/reorderable_list_view.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ReorderableListView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final List _items = List.generate(50, (int index) => index); + + @override + Widget build(BuildContext context) { + final ColorScheme colorScheme = Theme.of(context).colorScheme; + final Color oddItemColor = colorScheme.primary.withOpacity(0.05); + final Color evenItemColor = colorScheme.primary.withOpacity(0.15); + + return ReorderableListView( + padding: const EdgeInsets.symmetric(horizontal: 40), + children: [ + for (int index = 0; index < _items.length; index++) + ListTile( + key: Key('$index'), + tileColor: _items[index].isOdd ? oddItemColor : evenItemColor, + title: Text('Item ${_items[index]}'), + ), + ], + onReorder: (int oldIndex, int newIndex) { + setState(() { + if (oldIndex < newIndex) { + newIndex -= 1; + } + final int item = _items.removeAt(oldIndex); + _items.insert(newIndex, item); + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart b/examples/api/lib/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart new file mode 100644 index 0000000000..bd0ad6b949 --- /dev/null +++ b/examples/api/lib/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart @@ -0,0 +1,104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ReorderableListView.buildDefaultDragHandles +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final List _items = List.generate(50, (int index) => index); + + @override + Widget build(BuildContext context) { + final ColorScheme colorScheme = Theme.of(context).colorScheme; + final Color oddItemColor = colorScheme.primary.withOpacity(0.05); + final Color evenItemColor = colorScheme.primary.withOpacity(0.15); + + return ReorderableListView( + buildDefaultDragHandles: false, + children: [ + for (int index = 0; index < _items.length; index++) + Container( + key: Key('$index'), + color: _items[index].isOdd ? oddItemColor : evenItemColor, + child: Row( + children: [ + Container( + width: 64, + height: 64, + padding: const EdgeInsets.all(8), + child: ReorderableDragStartListener( + index: index, + child: Card( + color: colorScheme.primary, + elevation: 2, + ), + ), + ), + Text('Item ${_items[index]}'), + ], + ), + ), + ], + onReorder: (int oldIndex, int newIndex) { + setState(() { + if (oldIndex < newIndex) { + newIndex -= 1; + } + final int item = _items.removeAt(oldIndex); + _items.insert(newIndex, item); + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart b/examples/api/lib/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart new file mode 100644 index 0000000000..2f221572e1 --- /dev/null +++ b/examples/api/lib/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart @@ -0,0 +1,85 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ReorderableListView.ReorderableListView.builder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final List _items = List.generate(50, (int index) => index); + + @override + Widget build(BuildContext context) { + final ColorScheme colorScheme = Theme.of(context).colorScheme; + final Color oddItemColor = colorScheme.primary.withOpacity(0.05); + final Color evenItemColor = colorScheme.primary.withOpacity(0.15); + + return ReorderableListView.builder( + padding: const EdgeInsets.symmetric(horizontal: 40), + itemCount: _items.length, + itemBuilder: (BuildContext context, int index) { + return ListTile( + key: Key('$index'), + tileColor: _items[index].isOdd ? oddItemColor : evenItemColor, + title: Text('Item ${_items[index]}'), + ); + }, + onReorder: (int oldIndex, int newIndex) { + setState(() { + if (oldIndex < newIndex) { + newIndex -= 1; + } + final int item = _items.removeAt(oldIndex); + _items.insert(newIndex, item); + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold.0.dart b/examples/api/lib/material/scaffold/scaffold.0.dart new file mode 100644 index 0000000000..702622685b --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold.0.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scaffold +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [Scaffold] with a [body] and [FloatingActionButton]. +// The [body] is a [Text] placed in a [Center] in order to center the text +// within the [Scaffold]. The [FloatingActionButton] is connected to a +// callback that increments a counter. +// +// ![The Scaffold has a white background with a blue AppBar at the top. A blue FloatingActionButton is positioned at the bottom right corner of the Scaffold.](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _count = 0; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + body: Center(child: Text('You have pressed the button $_count times.')), + floatingActionButton: FloatingActionButton( + onPressed: () => setState(() => _count++), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold.1.dart b/examples/api/lib/material/scaffold/scaffold.1.dart new file mode 100644 index 0000000000..8b84ce8d55 --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold.1.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scaffold +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [Scaffold] with a blueGrey [backgroundColor], [body] +// and [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in +// order to center the text within the [Scaffold]. The [FloatingActionButton] +// is connected to a callback that increments a counter. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_background_color.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _count = 0; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + body: Center(child: Text('You have pressed the button $_count times.')), + backgroundColor: Colors.blueGrey.shade200, + floatingActionButton: FloatingActionButton( + onPressed: () => setState(() => _count++), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold.2.dart b/examples/api/lib/material/scaffold/scaffold.2.dart new file mode 100644 index 0000000000..cf27d3ddac --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold.2.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scaffold +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [Scaffold] with an [AppBar], a [BottomAppBar] and a +// [FloatingActionButton]. The [body] is a [Text] placed in a [Center] in order +// to center the text within the [Scaffold]. The [FloatingActionButton] is +// centered and docked within the [BottomAppBar] using +// [FloatingActionButtonLocation.centerDocked]. The [FloatingActionButton] is +// connected to a callback that increments a counter. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_bottom_app_bar.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _count = 0; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + body: Center( + child: Text('You have pressed the button $_count times.'), + ), + bottomNavigationBar: BottomAppBar( + shape: const CircularNotchedRectangle(), + child: Container(height: 50.0), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => setState(() { + _count++; + }), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold.drawer.0.dart b/examples/api/lib/material/scaffold/scaffold.drawer.0.dart new file mode 100644 index 0000000000..906e260ee4 --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold.drawer.0.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scaffold.drawer +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// To disable the drawer edge swipe, set the +// [Scaffold.drawerEnableOpenDragGesture] to false. Then, use +// [ScaffoldState.openDrawer] to open the drawer and [Navigator.pop] to close +// it. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final GlobalKey _scaffoldKey = GlobalKey(); + + void _openDrawer() { + _scaffoldKey.currentState!.openDrawer(); + } + + void _closeDrawer() { + Navigator.of(context).pop(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + key: _scaffoldKey, + appBar: AppBar(title: const Text('Drawer Demo')), + body: Center( + child: ElevatedButton( + onPressed: _openDrawer, + child: const Text('Open Drawer'), + ), + ), + drawer: Drawer( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('This is the Drawer'), + ElevatedButton( + onPressed: _closeDrawer, + child: const Text('Close Drawer'), + ), + ], + ), + ), + ), + // Disable opening the drawer with a swipe gesture. + drawerEnableOpenDragGesture: false, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold.end_drawer.0.dart b/examples/api/lib/material/scaffold/scaffold.end_drawer.0.dart new file mode 100644 index 0000000000..9930556792 --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold.end_drawer.0.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scaffold.endDrawer +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// To disable the drawer edge swipe, set the +// [Scaffold.endDrawerEnableOpenDragGesture] to false. Then, use +// [ScaffoldState.openEndDrawer] to open the drawer and [Navigator.pop] to +// close it. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final GlobalKey _scaffoldKey = GlobalKey(); + + void _openEndDrawer() { + _scaffoldKey.currentState!.openEndDrawer(); + } + + void _closeEndDrawer() { + Navigator.of(context).pop(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + key: _scaffoldKey, + appBar: AppBar(title: const Text('Drawer Demo')), + body: Center( + child: ElevatedButton( + onPressed: _openEndDrawer, + child: const Text('Open End Drawer'), + ), + ), + endDrawer: Drawer( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('This is the Drawer'), + ElevatedButton( + onPressed: _closeEndDrawer, + child: const Text('Close Drawer'), + ), + ], + ), + ), + ), + // Disable opening the end drawer with a swipe gesture. + endDrawerEnableOpenDragGesture: false, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold.of.0.dart b/examples/api/lib/material/scaffold/scaffold.of.0.dart new file mode 100644 index 0000000000..817be5a5df --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold.of.0.dart @@ -0,0 +1,105 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scaffold.of +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage of the [Scaffold.of] function is to call it from within the +// `build` method of a child of a [Scaffold]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() => runApp(const MyApp()); + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + // This widget is the root of your application. + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Code Sample for Scaffold.of.', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: Scaffold( + body: const MyScaffoldBody(), + appBar: AppBar(title: const Text('Scaffold.of Example')), + ), + color: Colors.white, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class MyScaffoldBody extends StatelessWidget { + const MyScaffoldBody({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Center( + child: ElevatedButton( + child: const Text('SHOW BOTTOM SHEET'), + onPressed: () { + Scaffold.of(context).showBottomSheet( + (BuildContext context) { + return Container( + alignment: Alignment.center, + height: 200, + color: Colors.amber, + child: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('BottomSheet'), + ElevatedButton( + child: const Text('Close BottomSheet'), + onPressed: () { + Navigator.pop(context); + }, + ) + ], + ), + ), + ); + }, + ); + }, + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/material/scaffold/scaffold.of.1.dart b/examples/api/lib/material/scaffold/scaffold.of.1.dart new file mode 100644 index 0000000000..045af593bf --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold.of.1.dart @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scaffold.of +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// When the [Scaffold] is actually created in the same `build` function, the +// `context` argument to the `build` function can't be used to find the +// [Scaffold] (since it's "above" the widget being returned in the widget +// tree). In such cases, the following technique with a [Builder] can be used +// to provide a new scope with a [BuildContext] that is "under" the +// [Scaffold]: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('Demo')), + body: Builder( + // Create an inner BuildContext so that the onPressed methods + // can refer to the Scaffold with Scaffold.of(). + builder: (BuildContext context) { + return Center( + child: ElevatedButton( + child: const Text('SHOW BOTTOM SHEET'), + onPressed: () { + Scaffold.of(context).showBottomSheet( + (BuildContext context) { + return Container( + alignment: Alignment.center, + height: 200, + color: Colors.amber, + child: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('BottomSheet'), + ElevatedButton( + child: const Text('Close BottomSheet'), + onPressed: () { + Navigator.pop(context); + }, + ) + ], + ), + ), + ); + }, + ); + }, + ), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold_messenger.0.dart b/examples/api/lib/material/scaffold/scaffold_messenger.0.dart new file mode 100644 index 0000000000..273e65a1ff --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold_messenger.0.dart @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaffoldMessenger +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of showing a [SnackBar] when the user presses a button. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return OutlinedButton( + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('A SnackBar has been shown.'), + ), + ); + }, + child: const Text('Show SnackBar'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold_messenger.of.0.dart b/examples/api/lib/material/scaffold/scaffold_messenger.of.0.dart new file mode 100644 index 0000000000..ba6c6af95e --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold_messenger.of.0.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaffoldMessenger.of +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage of the [ScaffoldMessenger.of] function is to call it in +// response to a user gesture or an application state change. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return ElevatedButton( + child: const Text('SHOW A SNACKBAR'), + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Have a snack!'), + ), + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold_messenger.of.1.dart b/examples/api/lib/material/scaffold/scaffold_messenger.of.1.dart new file mode 100644 index 0000000000..1cfac77f78 --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold_messenger.of.1.dart @@ -0,0 +1,92 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaffoldMessenger.of +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Sometimes [SnackBar]s are produced by code that doesn't have ready access +// to a valid [BuildContext]. One such example of this is when you show a +// SnackBar from a method outside of the `build` function. In these +// cases, you can assign a [GlobalKey] to the [ScaffoldMessenger]. This +// example shows a key being used to obtain the [ScaffoldMessengerState] +// provided by the [MaterialApp]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() => runApp(const MyApp()); + +class MyApp extends StatefulWidget { + const MyApp({Key? key}) : super(key: key); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + final GlobalKey _scaffoldMessengerKey = + GlobalKey(); + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + if (_counter % 10 == 0) { + _scaffoldMessengerKey.currentState!.showSnackBar(const SnackBar( + content: Text('A multiple of ten!'), + )); + } + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + scaffoldMessengerKey: _scaffoldMessengerKey, + home: Scaffold( + appBar: AppBar(title: const Text('ScaffoldMessenger Demo')), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headline4, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/material/scaffold/scaffold_messenger_state.show_material_banner.0.dart b/examples/api/lib/material/scaffold/scaffold_messenger_state.show_material_banner.0.dart new file mode 100644 index 0000000000..bd607e6972 --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold_messenger_state.show_material_banner.0.dart @@ -0,0 +1,74 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaffoldMessengerState.showMaterialBanner +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of showing a [MaterialBanner] when the user presses a button. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return OutlinedButton( + onPressed: () { + ScaffoldMessenger.of(context).showMaterialBanner( + const MaterialBanner( + content: Text('This is a MaterialBanner'), + actions: [ + TextButton( + child: Text('DISMISS'), + onPressed: null, + ), + ], + ), + ); + }, + child: const Text('Show MaterialBanner'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart b/examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart new file mode 100644 index 0000000000..b3d0f4cffa --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaffoldMessengerState.showSnackBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of showing a [SnackBar] when the user presses a button. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return OutlinedButton( + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('A SnackBar has been shown.'), + ), + ); + }, + child: const Text('Show SnackBar'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold_state.show_bottom_sheet.0.dart b/examples/api/lib/material/scaffold/scaffold_state.show_bottom_sheet.0.dart new file mode 100644 index 0000000000..84fa82e386 --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold_state.show_bottom_sheet.0.dart @@ -0,0 +1,87 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaffoldState.showBottomSheet +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example demonstrates how to use `showBottomSheet` to display a +// bottom sheet when a user taps a button. It also demonstrates how to +// close a bottom sheet using the Navigator. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Center( + child: ElevatedButton( + child: const Text('showBottomSheet'), + onPressed: () { + Scaffold.of(context).showBottomSheet( + (BuildContext context) { + return Container( + height: 200, + color: Colors.amber, + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + const Text('BottomSheet'), + ElevatedButton( + child: const Text('Close BottomSheet'), + onPressed: () { + Navigator.pop(context); + }) + ], + ), + ), + ); + }, + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scaffold/scaffold_state.show_snack_bar.0.dart b/examples/api/lib/material/scaffold/scaffold_state.show_snack_bar.0.dart new file mode 100644 index 0000000000..a61bcb4cfd --- /dev/null +++ b/examples/api/lib/material/scaffold/scaffold_state.show_snack_bar.0.dart @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaffoldState.showSnackBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of showing a [SnackBar] when the user presses a button. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return OutlinedButton( + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('A SnackBar has been shown.'), + ), + ); + }, + child: const Text('Show SnackBar'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scrollbar/scrollbar.0.dart b/examples/api/lib/material/scrollbar/scrollbar.0.dart new file mode 100644 index 0000000000..74658dfc10 --- /dev/null +++ b/examples/api/lib/material/scrollbar/scrollbar.0.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scrollbar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [Scrollbar] that executes a fade animation as scrolling occurs. +// The Scrollbar will fade into view as the user scrolls, and fade out when scrolling stops. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scrollbar( + child: GridView.builder( + itemCount: 120, + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), + itemBuilder: (BuildContext context, int index) { + return Center( + child: Text('item $index'), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/scrollbar/scrollbar.1.dart b/examples/api/lib/material/scrollbar/scrollbar.1.dart new file mode 100644 index 0000000000..27fa0b916a --- /dev/null +++ b/examples/api/lib/material/scrollbar/scrollbar.1.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Scrollbar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// When isAlwaysShown is true, the scrollbar thumb will remain visible without the +// fade animation. This requires that a ScrollController is provided to controller, +// or that the PrimaryScrollController is available. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final ScrollController _controllerOne = ScrollController(); + + @override + Widget build(BuildContext context) { + return Scrollbar( + controller: _controllerOne, + isAlwaysShown: true, + child: GridView.builder( + controller: _controllerOne, + itemCount: 120, + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), + itemBuilder: (BuildContext context, int index) { + return Center( + child: Text('item $index'), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/slider/slider.0.dart b/examples/api/lib/material/slider/slider.0.dart new file mode 100644 index 0000000000..0c86e40780 --- /dev/null +++ b/examples/api/lib/material/slider/slider.0.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Slider +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![A slider widget, consisting of 5 divisions and showing the default value +// indicator.](https://flutter.github.io/assets-for-api-docs/assets/material/slider.png) +// +// The Sliders value is part of the Stateful widget subclass to change the value +// setState was called. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + double _currentSliderValue = 20; + + @override + Widget build(BuildContext context) { + return Slider( + value: _currentSliderValue, + min: 0, + max: 100, + divisions: 5, + label: _currentSliderValue.round().toString(), + onChanged: (double value) { + setState(() { + _currentSliderValue = value; + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/snack_bar/snack_bar.0.dart b/examples/api/lib/material/snack_bar/snack_bar.0.dart new file mode 100644 index 0000000000..72887d18de --- /dev/null +++ b/examples/api/lib/material/snack_bar/snack_bar.0.dart @@ -0,0 +1,75 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SnackBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of a [SnackBar] with an [action] button implemented using +// [SnackBarAction]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return ElevatedButton( + child: const Text('Show Snackbar'), + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text('Awesome Snackbar!'), + action: SnackBarAction( + label: 'Action', + onPressed: () { + // Code to execute. + }, + ), + ), + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/snack_bar/snack_bar.1.dart b/examples/api/lib/material/snack_bar/snack_bar.1.dart new file mode 100644 index 0000000000..a2347b9927 --- /dev/null +++ b/examples/api/lib/material/snack_bar/snack_bar.1.dart @@ -0,0 +1,85 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SnackBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of a customized [SnackBar]. It utilizes +// [behavior], [shape], [padding], [width], and [duration] to customize the +// location, appearance, and the duration for which the [SnackBar] is visible. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return ElevatedButton( + child: const Text('Show Snackbar'), + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + action: SnackBarAction( + label: 'Action', + onPressed: () { + // Code to execute. + }, + ), + content: const Text('Awesome SnackBar!'), + duration: const Duration(milliseconds: 1500), + width: 280.0, // Width of the SnackBar. + padding: const EdgeInsets.symmetric( + horizontal: 8.0, // Inner padding for SnackBar content. + ), + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + ), + ), + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/stepper/stepper.0.dart b/examples/api/lib/material/stepper/stepper.0.dart new file mode 100644 index 0000000000..1e6aec6a37 --- /dev/null +++ b/examples/api/lib/material/stepper/stepper.0.dart @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Stepper +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _index = 0; + + @override + Widget build(BuildContext context) { + return Stepper( + currentStep: _index, + onStepCancel: () { + if (_index > 0) { + setState(() { + _index -= 1; + }); + } + }, + onStepContinue: () { + if (_index <= 0) { + setState(() { + _index += 1; + }); + } + }, + onStepTapped: (int index) { + setState(() { + _index = index; + }); + }, + steps: [ + Step( + title: const Text('Step 1 title'), + content: Container( + alignment: Alignment.centerLeft, + child: const Text('Content for Step 1')), + ), + const Step( + title: Text('Step 2 title'), + content: Text('Content for Step 2'), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/stepper/stepper.controls_builder.0.dart b/examples/api/lib/material/stepper/stepper.controls_builder.0.dart new file mode 100644 index 0000000000..de179cf97c --- /dev/null +++ b/examples/api/lib/material/stepper/stepper.controls_builder.0.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Stepper.controlsBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Creates a stepper control with custom buttons. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Stepper( + controlsBuilder: (BuildContext context, + {VoidCallback? onStepContinue, VoidCallback? onStepCancel}) { + return Row( + children: [ + TextButton( + onPressed: onStepContinue, + child: const Text('NEXT'), + ), + TextButton( + onPressed: onStepCancel, + child: const Text('CANCEL'), + ), + ], + ); + }, + steps: const [ + Step( + title: Text('A'), + content: SizedBox( + width: 100.0, + height: 100.0, + ), + ), + Step( + title: Text('B'), + content: SizedBox( + width: 100.0, + height: 100.0, + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/switch_list_tile/switch_list_tile.0.dart b/examples/api/lib/material/switch_list_tile/switch_list_tile.0.dart new file mode 100644 index 0000000000..73b26dee13 --- /dev/null +++ b/examples/api/lib/material/switch_list_tile/switch_list_tile.0.dart @@ -0,0 +1,79 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SwitchListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![SwitchListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile.png) +// +// This widget shows a switch that, when toggled, changes the state of a [bool] +// member field called `_lights`. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _lights = false; + + @override + Widget build(BuildContext context) { + return SwitchListTile( + title: const Text('Lights'), + value: _lights, + onChanged: (bool value) { + setState(() { + _lights = value; + }); + }, + secondary: const Icon(Icons.lightbulb_outline), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/switch_list_tile/switch_list_tile.1.dart b/examples/api/lib/material/switch_list_tile/switch_list_tile.1.dart new file mode 100644 index 0000000000..3931541b1f --- /dev/null +++ b/examples/api/lib/material/switch_list_tile/switch_list_tile.1.dart @@ -0,0 +1,141 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SwitchListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![Switch list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_semantics.png) +// +// Here is an example of a custom labeled radio widget, called +// LinkedLabelRadio, that includes an interactive [RichText] widget that +// handles tap gestures. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/gestures.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class LinkedLabelSwitch extends StatelessWidget { + const LinkedLabelSwitch({ + Key? key, + required this.label, + required this.padding, + required this.value, + required this.onChanged, + }) : super(key: key); + + final String label; + final EdgeInsets padding; + final bool value; + final ValueChanged onChanged; + + @override + Widget build(BuildContext context) { + return Padding( + padding: padding, + child: Row( + children: [ + Expanded( + child: RichText( + text: TextSpan( + text: label, + style: const TextStyle( + color: Colors.blueAccent, + decoration: TextDecoration.underline, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + print('Label has been tapped.'); + }, + ), + ), + ), + Switch( + value: value, + onChanged: (bool newValue) { + onChanged(newValue); + }, + ), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _isSelected = false; + + @override + Widget build(BuildContext context) { + return LinkedLabelSwitch( + label: 'Linked, tappable label text', + padding: const EdgeInsets.symmetric(horizontal: 20.0), + value: _isSelected, + onChanged: (bool newValue) { + setState(() { + _isSelected = newValue; + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/switch_list_tile/switch_list_tile.2.dart b/examples/api/lib/material/switch_list_tile/switch_list_tile.2.dart new file mode 100644 index 0000000000..2939ad8afe --- /dev/null +++ b/examples/api/lib/material/switch_list_tile/switch_list_tile.2.dart @@ -0,0 +1,123 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SwitchListTile +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// ![Custom switch list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_custom.png) +// +// Here is an example of a custom LabeledSwitch widget, but you can easily +// make your own configurable widget. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class LabeledSwitch extends StatelessWidget { + const LabeledSwitch({ + Key? key, + required this.label, + required this.padding, + required this.value, + required this.onChanged, + }) : super(key: key); + + final String label; + final EdgeInsets padding; + final bool value; + final ValueChanged onChanged; + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: () { + onChanged(!value); + }, + child: Padding( + padding: padding, + child: Row( + children: [ + Expanded(child: Text(label)), + Switch( + value: value, + onChanged: (bool newValue) { + onChanged(newValue); + }, + ), + ], + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _isSelected = false; + + @override + Widget build(BuildContext context) { + return LabeledSwitch( + label: 'This is the label text', + padding: const EdgeInsets.symmetric(horizontal: 20.0), + value: _isSelected, + onChanged: (bool newValue) { + setState(() { + _isSelected = newValue; + }); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/tab_controller/tab_controller.1.dart b/examples/api/lib/material/tab_controller/tab_controller.1.dart new file mode 100644 index 0000000000..7ebb657cb8 --- /dev/null +++ b/examples/api/lib/material/tab_controller/tab_controller.1.dart @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TabController +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to listen to page updates in [TabBar] and [TabBarView] +// when using [DefaultTabController]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +const List tabs = [ + Tab(text: 'Zeroth'), + Tab(text: 'First'), + Tab(text: 'Second'), +]; + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return DefaultTabController( + length: tabs.length, + // The Builder widget is used to have a different BuildContext to access + // closest DefaultTabController. + child: Builder(builder: (BuildContext context) { + final TabController tabController = DefaultTabController.of(context)!; + tabController.addListener(() { + if (!tabController.indexIsChanging) { + // Your code goes here. + // To get index of current tab use tabController.index + } + }); + return Scaffold( + appBar: AppBar( + bottom: const TabBar( + tabs: tabs, + ), + ), + body: TabBarView( + children: tabs.map((Tab tab) { + return Center( + child: Text( + '${tab.text!} Tab', + style: Theme.of(context).textTheme.headline5, + ), + ); + }).toList(), + ), + ); + }), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/tabs/tab_bar.0.dart b/examples/api/lib/material/tabs/tab_bar.0.dart new file mode 100644 index 0000000000..0919b9f6e2 --- /dev/null +++ b/examples/api/lib/material/tabs/tab_bar.0.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TabBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows the implementation of [TabBar] and [TabBarView] using a [DefaultTabController]. +// Each [Tab] corresponds to a child of the [TabBarView] in the order they are written. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return DefaultTabController( + initialIndex: 1, + length: 3, + child: Scaffold( + appBar: AppBar( + title: const Text('TabBar Widget'), + bottom: const TabBar( + tabs: [ + Tab( + icon: Icon(Icons.cloud_outlined), + ), + Tab( + icon: Icon(Icons.beach_access_sharp), + ), + Tab( + icon: Icon(Icons.brightness_5_sharp), + ), + ], + ), + ), + body: const TabBarView( + children: [ + Center( + child: Text("It's cloudy here"), + ), + Center( + child: Text("It's rainy here"), + ), + Center( + child: Text("It's sunny here"), + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/tabs/tab_bar.1.dart b/examples/api/lib/material/tabs/tab_bar.1.dart new file mode 100644 index 0000000000..387450c96c --- /dev/null +++ b/examples/api/lib/material/tabs/tab_bar.1.dart @@ -0,0 +1,104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TabBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// [TabBar] can also be implemented by using a [TabController] which provides more options +// to control the behavior of the [TabBar] and [TabBarView]. This can be used instead of +// a [DefaultTabController], demonstrated below. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late TabController _tabController; + + @override + void initState() { + super.initState(); + _tabController = TabController(length: 3, vsync: this); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('TabBar Widget'), + bottom: TabBar( + controller: _tabController, + tabs: const [ + Tab( + icon: Icon(Icons.cloud_outlined), + ), + Tab( + icon: Icon(Icons.beach_access_sharp), + ), + Tab( + icon: Icon(Icons.brightness_5_sharp), + ), + ], + ), + ), + body: TabBarView( + controller: _tabController, + children: const [ + Center( + child: Text("It's cloudy here"), + ), + Center( + child: Text("It's rainy here"), + ), + Center( + child: Text("It's sunny here"), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/text_button/text_button.0.dart b/examples/api/lib/material/text_button/text_button.0.dart new file mode 100644 index 0000000000..6d183c4d4b --- /dev/null +++ b/examples/api/lib/material/text_button/text_button.0.dart @@ -0,0 +1,109 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TextButton +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to render a disabled TextButton, an enabled TextButton +// and lastly a TextButton with gradient background. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextButton( + style: TextButton.styleFrom( + textStyle: const TextStyle(fontSize: 20), + ), + onPressed: null, + child: const Text('Disabled'), + ), + const SizedBox(height: 30), + TextButton( + style: TextButton.styleFrom( + textStyle: const TextStyle(fontSize: 20), + ), + onPressed: () {}, + child: const Text('Enabled'), + ), + const SizedBox(height: 30), + ClipRRect( + borderRadius: BorderRadius.circular(4), + child: Stack( + children: [ + Positioned.fill( + child: Container( + decoration: const BoxDecoration( + gradient: LinearGradient( + colors: [ + Color(0xFF0D47A1), + Color(0xFF1976D2), + Color(0xFF42A5F5), + ], + ), + ), + ), + ), + TextButton( + style: TextButton.styleFrom( + padding: const EdgeInsets.all(16.0), + primary: Colors.white, + textStyle: const TextStyle(fontSize: 20), + ), + onPressed: () {}, + child: const Text('Gradient'), + ), + ], + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/text_field/text_field.1.dart b/examples/api/lib/material/text_field/text_field.1.dart new file mode 100644 index 0000000000..cfa0418100 --- /dev/null +++ b/examples/api/lib/material/text_field/text_field.1.dart @@ -0,0 +1,101 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TextField +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to get a value from a TextField via the [onSubmitted] +// callback. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late TextEditingController _controller; + + @override + void initState() { + super.initState(); + _controller = TextEditingController(); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: TextField( + controller: _controller, + onSubmitted: (String value) async { + await showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Thanks!'), + content: Text( + 'You typed "$value", which has length ${value.characters.length}.'), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text('OK'), + ), + ], + ); + }, + ); + }, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/text_form_field/text_form_field.1.dart b/examples/api/lib/material/text_form_field/text_form_field.1.dart new file mode 100644 index 0000000000..97f0e0df15 --- /dev/null +++ b/examples/api/lib/material/text_form_field/text_form_field.1.dart @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TextFormField +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to move the focus to the next field when the user +// presses the SPACE key. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return Material( + child: Center( + child: Shortcuts( + shortcuts: const { + // Pressing space in the field will now move to the next field. + SingleActivator(LogicalKeyboardKey.space): NextFocusIntent(), + }, + child: FocusTraversalGroup( + child: Form( + autovalidateMode: AutovalidateMode.always, + onChanged: () { + Form.of(primaryFocus!.context!)!.save(); + }, + child: Wrap( + children: List.generate(5, (int index) { + return Padding( + padding: const EdgeInsets.all(8.0), + child: ConstrainedBox( + constraints: BoxConstraints.tight(const Size(200, 50)), + child: TextFormField( + onSaved: (String? value) { + print('Value for field $index saved as "$value"'); + }, + ), + ), + ); + }), + ), + ), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/tooltip/tooltip.0.dart b/examples/api/lib/material/tooltip/tooltip.0.dart new file mode 100644 index 0000000000..06cc953f24 --- /dev/null +++ b/examples/api/lib/material/tooltip/tooltip.0.dart @@ -0,0 +1,65 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Tooltip +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example show a basic [Tooltip] which has a [Text] as child. +// [message] contains your label to be shown by the tooltip when +// the child that Tooltip wraps is hovered over on web or desktop. On mobile, +// the tooltip is shown when the widget is long pressed. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return const Tooltip( + message: 'I am a Tooltip', + child: Text('Hover over the text to show a tooltip.'), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/material/tooltip/tooltip.1.dart b/examples/api/lib/material/tooltip/tooltip.1.dart new file mode 100644 index 0000000000..6ab2a7c69b --- /dev/null +++ b/examples/api/lib/material/tooltip/tooltip.1.dart @@ -0,0 +1,85 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Tooltip +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example covers most of the attributes available in Tooltip. +// `decoration` has been used to give a gradient and borderRadius to Tooltip. +// `height` has been used to set a specific height of the Tooltip. +// `preferBelow` is false, the tooltip will prefer showing above [Tooltip]'s child widget. +// However, it may show the tooltip below if there's not enough space +// above the widget. +// `textStyle` has been used to set the font size of the 'message'. +// `showDuration` accepts a Duration to continue showing the message after the long +// press has been released or the mouse pointer exits the child widget. +// `waitDuration` accepts a Duration for which a mouse pointer has to hover over the child +// widget before the tooltip is shown. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Tooltip( + message: 'I am a Tooltip', + child: const Text('Tap this text and hold down to show a tooltip.'), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(25), + gradient: + const LinearGradient(colors: [Colors.amber, Colors.red]), + ), + height: 50, + padding: const EdgeInsets.all(8.0), + preferBelow: false, + textStyle: const TextStyle( + fontSize: 24, + ), + showDuration: const Duration(seconds: 2), + waitDuration: const Duration(seconds: 1), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/painting/gradient/linear_gradient.0.dart b/examples/api/lib/painting/gradient/linear_gradient.0.dart new file mode 100644 index 0000000000..a6416fde3e --- /dev/null +++ b/examples/api/lib/painting/gradient/linear_gradient.0.dart @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for LinearGradient +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample draws a picture that looks like vertical window shades by having +// a [Container] display a [BoxDecoration] with a [LinearGradient]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: + Alignment(0.8, 0.0), // 10% of the width, so there are ten blinds. + colors: [ + Color(0xffee0000), + Color(0xffeeee00) + ], // red to yellow + tileMode: TileMode.repeated, // repeats the gradient over the canvas + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart b/examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart new file mode 100644 index 0000000000..3161cf58c6 --- /dev/null +++ b/examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverGridDelegateWithFixedCrossAxisCount +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example using the [childAspectRatio] property. On a device with a +// screen width of 800.0, it creates a GridView with each tile with a width of +// 200.0 and a height of 100.0. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return GridView( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, + childAspectRatio: 0.5, + ), + children: List.generate(20, (int i) { + return Builder(builder: (BuildContext context) { + return Text('$i'); + }); + }), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart b/examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart new file mode 100644 index 0000000000..237ec95a76 --- /dev/null +++ b/examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverGridDelegateWithFixedCrossAxisCount +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example using the [mainAxisExtent] property. On a device with a +// screen width of 800.0, it creates a GridView with each tile with a width of +// 200.0 and a height of 150.0. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return GridView( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, + mainAxisExtent: 150.0, + ), + children: List.generate(20, (int i) { + return Builder(builder: (BuildContext context) { + return Text('$i'); + }); + }), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/services/keyboard_key/logical_keyboard_key.0.dart b/examples/api/lib/services/keyboard_key/logical_keyboard_key.0.dart new file mode 100644 index 0000000000..6815402b2e --- /dev/null +++ b/examples/api/lib/services/keyboard_key/logical_keyboard_key.0.dart @@ -0,0 +1,127 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for LogicalKeyboardKey +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to detect if the user has selected the logical "Q" +// key. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The node used to request the keyboard focus. + final FocusNode _focusNode = FocusNode(); +// The message to display. + String? _message; + +// Focus nodes need to be disposed. + @override + void dispose() { + _focusNode.dispose(); + super.dispose(); + } + +// Handles the key events from the RawKeyboardListener and update the +// _message. + void _handleKeyEvent(RawKeyEvent event) { + setState(() { + if (event.logicalKey == LogicalKeyboardKey.keyQ) { + _message = 'Pressed the "Q" key!'; + } else { + if (kReleaseMode) { + _message = + 'Not a Q: Pressed 0x${event.logicalKey.keyId.toRadixString(16)}'; + } else { + // The debugName will only print useful information in debug mode. + _message = 'Not a Q: Pressed ${event.logicalKey.debugName}'; + } + } + }); + } + + @override + Widget build(BuildContext context) { + final TextTheme textTheme = Theme.of(context).textTheme; + return Container( + color: Colors.white, + alignment: Alignment.center, + child: DefaultTextStyle( + style: textTheme.headline4!, + child: RawKeyboardListener( + focusNode: _focusNode, + onKey: _handleKeyEvent, + child: AnimatedBuilder( + animation: _focusNode, + builder: (BuildContext context, Widget? child) { + if (!_focusNode.hasFocus) { + return GestureDetector( + onTap: () { + FocusScope.of(context).requestFocus(_focusNode); + }, + child: const Text('Tap to focus'), + ); + } + return Text(_message ?? 'Press a key'); + }, + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/services/keyboard_key/physical_keyboard_key.0.dart b/examples/api/lib/services/keyboard_key/physical_keyboard_key.0.dart new file mode 100644 index 0000000000..01b046d8fa --- /dev/null +++ b/examples/api/lib/services/keyboard_key/physical_keyboard_key.0.dart @@ -0,0 +1,120 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for PhysicalKeyboardKey +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to detect if the user has selected the physical key +// to the right of the CAPS LOCK key. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The node used to request the keyboard focus. + final FocusNode _focusNode = FocusNode(); +// The message to display. + String? _message; + +// Focus nodes need to be disposed. + @override + void dispose() { + _focusNode.dispose(); + super.dispose(); + } + +// Handles the key events from the RawKeyboardListener and update the +// _message. + void _handleKeyEvent(RawKeyEvent event) { + setState(() { + if (event.physicalKey == PhysicalKeyboardKey.keyA) { + _message = 'Pressed the key next to CAPS LOCK!'; + } else { + _message = 'Wrong key.'; + } + }); + } + + @override + Widget build(BuildContext context) { + final TextTheme textTheme = Theme.of(context).textTheme; + return Container( + color: Colors.white, + alignment: Alignment.center, + child: DefaultTextStyle( + style: textTheme.headline4!, + child: RawKeyboardListener( + focusNode: _focusNode, + onKey: _handleKeyEvent, + child: AnimatedBuilder( + animation: _focusNode, + builder: (BuildContext context, Widget? child) { + if (!_focusNode.hasFocus) { + return GestureDetector( + onTap: () { + FocusScope.of(context).requestFocus(_focusNode); + }, + child: const Text('Tap to focus'), + ); + } + return Text(_message ?? 'Press a key'); + }, + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/services/system_chrome/system_chrome.set_system_u_i_overlay_style.1.dart b/examples/api/lib/services/system_chrome/system_chrome.set_system_u_i_overlay_style.1.dart new file mode 100644 index 0000000000..2d61616b84 --- /dev/null +++ b/examples/api/lib/services/system_chrome/system_chrome.set_system_u_i_overlay_style.1.dart @@ -0,0 +1,101 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SystemChrome.setSystemUIOverlayStyle +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example creates a widget that changes the status bar color +// to a random value on Android. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//******************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-dartImports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'dart:math' as math; + +//* ▲▲▲▲▲▲▲▲ code-dartImports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final math.Random _random = math.Random(); + SystemUiOverlayStyle _currentStyle = SystemUiOverlayStyle.light; + + void _changeColor() { + final Color color = Color.fromRGBO( + _random.nextInt(255), + _random.nextInt(255), + _random.nextInt(255), + 1.0, + ); + setState(() { + _currentStyle = SystemUiOverlayStyle.dark.copyWith( + statusBarColor: color, + ); + }); + } + + @override + Widget build(BuildContext context) { + return AnnotatedRegion( + value: _currentStyle, + child: Center( + child: ElevatedButton( + child: const Text('Change Color'), + onPressed: _changeColor, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/actions/action.action_overridable.0.dart b/examples/api/lib/widgets/actions/action.action_overridable.0.dart new file mode 100644 index 0000000000..0f35817558 --- /dev/null +++ b/examples/api/lib/widgets/actions/action.action_overridable.0.dart @@ -0,0 +1,201 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Action.Action.overridable +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample implements a custom text input field that handles the +// [DeleteTextIntent] intent, as well as a US telephone number input widget +// that consists of multiple text fields for area code, prefix and line +// number. When the backspace key is pressed, the phone number input widget +// sends the focus to the preceding text field when the currently focused +// field becomes empty. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() { + runApp( + const MaterialApp( + home: Scaffold( + body: Center(child: SimpleUSPhoneNumberEntry()), + ), + ), + ); +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This implements a custom phone number input field that handles the +// [DeleteTextIntent] intent. +class DigitInput extends StatefulWidget { + const DigitInput({ + Key? key, + required this.controller, + required this.focusNode, + this.maxLength, + this.textInputAction = TextInputAction.next, + }) : super(key: key); + + final int? maxLength; + final TextEditingController controller; + final TextInputAction textInputAction; + final FocusNode focusNode; + + @override + DigitInputState createState() => DigitInputState(); +} + +class DigitInputState extends State { + late final Action _deleteTextAction = + CallbackAction( + onInvoke: (DeleteTextIntent intent) { + // For simplicity we delete everything in the section. + widget.controller.clear(); + }, + ); + + @override + Widget build(BuildContext context) { + return Actions( + actions: >{ + // Make the default `DeleteTextIntent` handler overridable. + DeleteTextIntent: Action.overridable( + defaultAction: _deleteTextAction, context: context), + }, + child: TextField( + controller: widget.controller, + textInputAction: TextInputAction.next, + keyboardType: TextInputType.phone, + focusNode: widget.focusNode, + decoration: const InputDecoration( + border: OutlineInputBorder(), + ), + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly, + LengthLimitingTextInputFormatter(widget.maxLength), + ], + ), + ); + } +} + +class SimpleUSPhoneNumberEntry extends StatefulWidget { + const SimpleUSPhoneNumberEntry({Key? key}) : super(key: key); + + @override + State createState() => + _SimpleUSPhoneNumberEntryState(); +} + +class _DeleteDigit extends Action { + _DeleteDigit(this.state); + + final _SimpleUSPhoneNumberEntryState state; + @override + Object? invoke(DeleteTextIntent intent) { + assert(callingAction != null); + callingAction?.invoke(intent); + + if (state.lineNumberController.text.isEmpty && + state.lineNumberFocusNode.hasFocus) { + state.prefixFocusNode.requestFocus(); + } + + if (state.prefixController.text.isEmpty && state.prefixFocusNode.hasFocus) { + state.areaCodeFocusNode.requestFocus(); + } + } + + // This action is only enabled when the `callingAction` exists and is + // enabled. + @override + bool get isActionEnabled => callingAction?.isActionEnabled ?? false; +} + +class _SimpleUSPhoneNumberEntryState extends State { + final FocusNode areaCodeFocusNode = FocusNode(); + final TextEditingController areaCodeController = TextEditingController(); + final FocusNode prefixFocusNode = FocusNode(); + final TextEditingController prefixController = TextEditingController(); + final FocusNode lineNumberFocusNode = FocusNode(); + final TextEditingController lineNumberController = TextEditingController(); + + @override + Widget build(BuildContext context) { + return Actions( + actions: >{ + DeleteTextIntent: _DeleteDigit(this), + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Expanded( + child: Text( + '(', + textAlign: TextAlign.center, + ), + flex: 1), + Expanded( + child: DigitInput( + focusNode: areaCodeFocusNode, + controller: areaCodeController, + maxLength: 3), + flex: 3), + const Expanded( + child: Text( + ')', + textAlign: TextAlign.center, + ), + flex: 1), + Expanded( + child: DigitInput( + focusNode: prefixFocusNode, + controller: prefixController, + maxLength: 3), + flex: 3), + const Expanded( + child: Text( + '-', + textAlign: TextAlign.center, + ), + flex: 1), + Expanded( + child: DigitInput( + focusNode: lineNumberFocusNode, + controller: lineNumberController, + textInputAction: TextInputAction.done, + maxLength: 4), + flex: 4), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/actions/action_listener.0.dart b/examples/api/lib/widgets/actions/action_listener.0.dart new file mode 100644 index 0000000000..0a1a43ba40 --- /dev/null +++ b/examples/api/lib/widgets/actions/action_listener.0.dart @@ -0,0 +1,156 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ActionListener +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how ActionListener handles adding and removing of +// the [listener] in the widget lifecycle. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class ActionListenerExample extends StatefulWidget { + const ActionListenerExample({Key? key}) : super(key: key); + + @override + State createState() => _ActionListenerExampleState(); +} + +class _ActionListenerExampleState extends State { + bool _on = false; + late final MyAction _myAction; + + @override + void initState() { + super.initState(); + _myAction = MyAction(); + } + + void _toggleState() { + setState(() { + _on = !_on; + }); + } + + @override + Widget build(BuildContext context) { + return Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: OutlinedButton( + onPressed: _toggleState, + child: Text(_on ? 'Disable' : 'Enable'), + ), + ), + if (_on) + Padding( + padding: const EdgeInsets.all(8.0), + child: ActionListener( + listener: (Action action) { + if (action.intentType == MyIntent) { + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text('Action Listener Called'), + )); + } + }, + action: _myAction, + child: ElevatedButton( + onPressed: () => const ActionDispatcher() + .invokeAction(_myAction, const MyIntent()), + child: const Text('Call Action Listener'), + ), + ), + ), + if (!_on) Container(), + ], + ); + } +} + +class MyAction extends Action { + @override + void addActionListener(ActionListenerCallback listener) { + super.addActionListener(listener); + print('Action Listener was added'); + } + + @override + void removeActionListener(ActionListenerCallback listener) { + super.removeActionListener(listener); + print('Action Listener was removed'); + } + + @override + void invoke(covariant MyIntent intent) { + notifyActionListeners(); + } +} + +class MyIntent extends Intent { + const MyIntent(); +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return const ActionListenerExample(); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/actions/actions.0.dart b/examples/api/lib/widgets/actions/actions.0.dart new file mode 100644 index 0000000000..2a7c3a7d04 --- /dev/null +++ b/examples/api/lib/widgets/actions/actions.0.dart @@ -0,0 +1,219 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Actions +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example creates a custom [Action] subclass `ModifyAction` for modifying +// a model, and another, `SaveAction` for saving it. +// +// This example demonstrates passing arguments to the [Intent] to be carried to +// the [Action]. Actions can get data either from their own construction (like +// the `model` in this example), or from the intent passed to them when invoked +// (like the increment `amount` in this example). +// +// This example also demonstrates how to use Intents to limit a widget's +// dependencies on its surroundings. The `SaveButton` widget defined in this +// example can invoke actions defined in its ancestor widgets, which can be +// customized to match the part of the widget tree that it is in. It doesn't +// need to know about the `SaveAction` class, only the `SaveIntent`, and it +// only needs to know about a value notifier, not the entire model. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// A simple model class that notifies listeners when it changes. +class Model { + ValueNotifier isDirty = ValueNotifier(false); + ValueNotifier data = ValueNotifier(0); + + int save() { + if (isDirty.value) { + print('Saved Data: ${data.value}'); + isDirty.value = false; + } + return data.value; + } + + void setValue(int newValue) { + isDirty.value = data.value != newValue; + data.value = newValue; + } +} + +class ModifyIntent extends Intent { + const ModifyIntent(this.value); + + final int value; +} + +// An Action that modifies the model by setting it to the value that it gets +// from the Intent passed to it when invoked. +class ModifyAction extends Action { + ModifyAction(this.model); + + final Model model; + + @override + void invoke(covariant ModifyIntent intent) { + model.setValue(intent.value); + } +} + +// An intent for saving data. +class SaveIntent extends Intent { + const SaveIntent(); +} + +// An Action that saves the data in the model it is created with. +class SaveAction extends Action { + SaveAction(this.model); + + final Model model; + + @override + int invoke(covariant SaveIntent intent) => model.save(); +} + +class SaveButton extends StatefulWidget { + const SaveButton(this.valueNotifier, {Key? key}) : super(key: key); + + final ValueNotifier valueNotifier; + + @override + State createState() => _SaveButtonState(); +} + +class _SaveButtonState extends State { + int savedValue = 0; + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: widget.valueNotifier, + builder: (BuildContext context, Widget? child) { + return TextButton.icon( + icon: const Icon(Icons.save), + label: Text('$savedValue'), + style: ButtonStyle( + foregroundColor: MaterialStateProperty.all( + widget.valueNotifier.value ? Colors.red : Colors.green, + ), + ), + onPressed: () { + setState(() { + savedValue = Actions.invoke(context, const SaveIntent())! as int; + }); + }, + ); + }, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Model model = Model(); + int count = 0; + + @override + Widget build(BuildContext context) { + return Actions( + actions: >{ + ModifyIntent: ModifyAction(model), + SaveIntent: SaveAction(model), + }, + child: Builder( + builder: (BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + const Spacer(), + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + IconButton( + icon: const Icon(Icons.exposure_plus_1), + onPressed: () { + Actions.invoke(context, ModifyIntent(++count)); + }, + ), + AnimatedBuilder( + animation: model.data, + builder: (BuildContext context, Widget? child) { + return Padding( + padding: const EdgeInsets.all(8.0), + child: Text('${model.data.value}', + style: Theme.of(context).textTheme.headline4), + ); + }), + IconButton( + icon: const Icon(Icons.exposure_minus_1), + onPressed: () { + Actions.invoke(context, ModifyIntent(--count)); + }, + ), + ], + ), + SaveButton(model.isDirty), + const Spacer(), + ], + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/actions/focusable_action_detector.0.dart b/examples/api/lib/widgets/actions/focusable_action_detector.0.dart new file mode 100644 index 0000000000..b650993d52 --- /dev/null +++ b/examples/api/lib/widgets/actions/focusable_action_detector.0.dart @@ -0,0 +1,194 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FocusableActionDetector +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how keyboard interaction can be added to a custom control +// that changes color when hovered and focused, and can toggle a light when +// activated, either by touch or by hitting the `X` key on the keyboard when +// the "And Me" button has the keyboard focus (be sure to use TAB to move the +// focus to the "And Me" button before trying it out). +// +// This example defines its own key binding for the `X` key, but in this case, +// there is also a default key binding for [ActivateAction] in the default key +// bindings created by [WidgetsApp] (the parent for [MaterialApp], and +// [CupertinoApp]), so the `ENTER` key will also activate the buttons. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class FadButton extends StatefulWidget { + const FadButton({ + Key? key, + required this.onPressed, + required this.child, + }) : super(key: key); + + final VoidCallback onPressed; + final Widget child; + + @override + State createState() => _FadButtonState(); +} + +class _FadButtonState extends State { + bool _focused = false; + bool _hovering = false; + bool _on = false; + late final Map> _actionMap; + final Map _shortcutMap = + const { + SingleActivator(LogicalKeyboardKey.keyX): ActivateIntent(), + }; + + @override + void initState() { + super.initState(); + _actionMap = >{ + ActivateIntent: CallbackAction( + onInvoke: (Intent intent) => _toggleState(), + ), + }; + } + + Color get color { + Color baseColor = Colors.lightBlue; + if (_focused) { + baseColor = Color.alphaBlend(Colors.black.withOpacity(0.25), baseColor); + } + if (_hovering) { + baseColor = Color.alphaBlend(Colors.black.withOpacity(0.1), baseColor); + } + return baseColor; + } + + void _toggleState() { + setState(() { + _on = !_on; + }); + } + + void _handleFocusHighlight(bool value) { + setState(() { + _focused = value; + }); + } + + void _handleHoveHighlight(bool value) { + setState(() { + _hovering = value; + }); + } + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: _toggleState, + child: FocusableActionDetector( + actions: _actionMap, + shortcuts: _shortcutMap, + onShowFocusHighlight: _handleFocusHighlight, + onShowHoverHighlight: _handleHoveHighlight, + child: Row( + children: [ + Container( + padding: const EdgeInsets.all(10.0), + color: color, + child: widget.child, + ), + Container( + width: 30, + height: 30, + margin: const EdgeInsets.all(10.0), + color: _on ? Colors.red : Colors.transparent, + ), + ], + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('FocusableActionDetector Example'), + ), + body: Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: + TextButton(onPressed: () {}, child: const Text('Press Me')), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: FadButton(onPressed: () {}, child: const Text('And Me')), + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/animated_list/animated_list.0.dart b/examples/api/lib/widgets/animated_list/animated_list.0.dart new file mode 100644 index 0000000000..6dcb51c18a --- /dev/null +++ b/examples/api/lib/widgets/animated_list/animated_list.0.dart @@ -0,0 +1,243 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedList +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample application uses an [AnimatedList] to create an effect when +// items are removed or added to the list. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() { + runApp(const AnimatedListSample()); +} + +class AnimatedListSample extends StatefulWidget { + const AnimatedListSample({Key? key}) : super(key: key); + + @override + State createState() => _AnimatedListSampleState(); +} + +class _AnimatedListSampleState extends State { + final GlobalKey _listKey = GlobalKey(); + late ListModel _list; + int? _selectedItem; + late int + _nextItem; // The next item inserted when the user presses the '+' button. + + @override + void initState() { + super.initState(); + _list = ListModel( + listKey: _listKey, + initialItems: [0, 1, 2], + removedItemBuilder: _buildRemovedItem, + ); + _nextItem = 3; + } + + // Used to build list items that haven't been removed. + Widget _buildItem( + BuildContext context, int index, Animation animation) { + return CardItem( + animation: animation, + item: _list[index], + selected: _selectedItem == _list[index], + onTap: () { + setState(() { + _selectedItem = _selectedItem == _list[index] ? null : _list[index]; + }); + }, + ); + } + + // Used to build an item after it has been removed from the list. This + // method is needed because a removed item remains visible until its + // animation has completed (even though it's gone as far this ListModel is + // concerned). The widget will be used by the + // [AnimatedListState.removeItem] method's + // [AnimatedListRemovedItemBuilder] parameter. + Widget _buildRemovedItem( + int item, BuildContext context, Animation animation) { + return CardItem( + animation: animation, + item: item, + selected: false, + // No gesture detector here: we don't want removed items to be interactive. + ); + } + + // Insert the "next item" into the list model. + void _insert() { + final int index = + _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!); + _list.insert(index, _nextItem++); + } + + // Remove the selected item from the list model. + void _remove() { + if (_selectedItem != null) { + _list.removeAt(_list.indexOf(_selectedItem!)); + setState(() { + _selectedItem = null; + }); + } + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('AnimatedList'), + actions: [ + IconButton( + icon: const Icon(Icons.add_circle), + onPressed: _insert, + tooltip: 'insert a new item', + ), + IconButton( + icon: const Icon(Icons.remove_circle), + onPressed: _remove, + tooltip: 'remove the selected item', + ), + ], + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: AnimatedList( + key: _listKey, + initialItemCount: _list.length, + itemBuilder: _buildItem, + ), + ), + ), + ); + } +} + +typedef RemovedItemBuilder = Widget Function( + T item, BuildContext context, Animation animation); + +/// Keeps a Dart [List] in sync with an [AnimatedList]. +/// +/// The [insert] and [removeAt] methods apply to both the internal list and +/// the animated list that belongs to [listKey]. +/// +/// This class only exposes as much of the Dart List API as is needed by the +/// sample app. More list methods are easily added, however methods that +/// mutate the list must make the same changes to the animated list in terms +/// of [AnimatedListState.insertItem] and [AnimatedList.removeItem]. +class ListModel { + ListModel({ + required this.listKey, + required this.removedItemBuilder, + Iterable? initialItems, + }) : _items = List.from(initialItems ?? []); + + final GlobalKey listKey; + final RemovedItemBuilder removedItemBuilder; + final List _items; + + AnimatedListState? get _animatedList => listKey.currentState; + + void insert(int index, E item) { + _items.insert(index, item); + _animatedList!.insertItem(index); + } + + E removeAt(int index) { + final E removedItem = _items.removeAt(index); + if (removedItem != null) { + _animatedList!.removeItem( + index, + (BuildContext context, Animation animation) { + return removedItemBuilder(removedItem, context, animation); + }, + ); + } + return removedItem; + } + + int get length => _items.length; + + E operator [](int index) => _items[index]; + + int indexOf(E item) => _items.indexOf(item); +} + +/// Displays its integer item as 'item N' on a Card whose color is based on +/// the item's value. +/// +/// The text is displayed in bright green if [selected] is +/// true. This widget's height is based on the [animation] parameter, it +/// varies from 0 to 128 as the animation varies from 0.0 to 1.0. +class CardItem extends StatelessWidget { + const CardItem({ + Key? key, + this.onTap, + this.selected = false, + required this.animation, + required this.item, + }) : assert(item >= 0), + super(key: key); + + final Animation animation; + final VoidCallback? onTap; + final int item; + final bool selected; + + @override + Widget build(BuildContext context) { + TextStyle textStyle = Theme.of(context).textTheme.headline4!; + if (selected) { + textStyle = textStyle.copyWith(color: Colors.lightGreenAccent[400]); + } + return Padding( + padding: const EdgeInsets.all(2.0), + child: SizeTransition( + axis: Axis.vertical, + sizeFactor: animation, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: onTap, + child: SizedBox( + height: 80.0, + child: Card( + color: Colors.primaries[item % Colors.primaries.length], + child: Center( + child: Text('Item $item', style: textStyle), + ), + ), + ), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/animated_list/sliver_animated_list.0.dart b/examples/api/lib/widgets/animated_list/sliver_animated_list.0.dart new file mode 100644 index 0000000000..1e809e65b2 --- /dev/null +++ b/examples/api/lib/widgets/animated_list/sliver_animated_list.0.dart @@ -0,0 +1,267 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverAnimatedList +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample application uses a [SliverAnimatedList] to create an animated +// effect when items are removed or added to the list. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() => runApp(const SliverAnimatedListSample()); + +class SliverAnimatedListSample extends StatefulWidget { + const SliverAnimatedListSample({Key? key}) : super(key: key); + + @override + State createState() => + _SliverAnimatedListSampleState(); +} + +class _SliverAnimatedListSampleState extends State { + final GlobalKey _listKey = + GlobalKey(); + final GlobalKey _scaffoldKey = GlobalKey(); + final GlobalKey _scaffoldMessengerKey = + GlobalKey(); + late ListModel _list; + int? _selectedItem; + late int + _nextItem; // The next item inserted when the user presses the '+' button. + + @override + void initState() { + super.initState(); + _list = ListModel( + listKey: _listKey, + initialItems: [0, 1, 2], + removedItemBuilder: _buildRemovedItem, + ); + _nextItem = 3; + } + + // Used to build list items that haven't been removed. + Widget _buildItem( + BuildContext context, int index, Animation animation) { + return CardItem( + animation: animation, + item: _list[index], + selected: _selectedItem == _list[index], + onTap: () { + setState(() { + _selectedItem = _selectedItem == _list[index] ? null : _list[index]; + }); + }, + ); + } + + // Used to build an item after it has been removed from the list. This + // method is needed because a removed item remains visible until its + // animation has completed (even though it's gone as far this ListModel is + // concerned). The widget will be used by the + // [AnimatedListState.removeItem] method's + // [AnimatedListRemovedItemBuilder] parameter. + Widget _buildRemovedItem( + int item, BuildContext context, Animation animation) { + return CardItem( + animation: animation, + item: item, + selected: false, + ); + } + + // Insert the "next item" into the list model. + void _insert() { + final int index = + _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!); + _list.insert(index, _nextItem++); + } + + // Remove the selected item from the list model. + void _remove() { + if (_selectedItem != null) { + _list.removeAt(_list.indexOf(_selectedItem!)); + setState(() { + _selectedItem = null; + }); + } else { + _scaffoldMessengerKey.currentState!.showSnackBar(const SnackBar( + content: Text( + 'Select an item to remove from the list.', + style: TextStyle(fontSize: 20), + ), + )); + } + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + scaffoldMessengerKey: _scaffoldMessengerKey, + home: Scaffold( + key: _scaffoldKey, + body: CustomScrollView( + slivers: [ + SliverAppBar( + title: const Text( + 'SliverAnimatedList', + style: TextStyle(fontSize: 30), + ), + expandedHeight: 60, + centerTitle: true, + backgroundColor: Colors.amber[900], + leading: IconButton( + icon: const Icon(Icons.add_circle), + onPressed: _insert, + tooltip: 'Insert a new item.', + iconSize: 32, + ), + actions: [ + IconButton( + icon: const Icon(Icons.remove_circle), + onPressed: _remove, + tooltip: 'Remove the selected item.', + iconSize: 32, + ), + ], + ), + SliverAnimatedList( + key: _listKey, + initialItemCount: _list.length, + itemBuilder: _buildItem, + ), + ], + ), + ), + ); + } +} + +typedef RemovedItemBuilder = Widget Function( + int item, BuildContext context, Animation animation); + +// Keeps a Dart [List] in sync with an [AnimatedList]. +// +// The [insert] and [removeAt] methods apply to both the internal list and +// the animated list that belongs to [listKey]. +// +// This class only exposes as much of the Dart List API as is needed by the +// sample app. More list methods are easily added, however methods that +// mutate the list must make the same changes to the animated list in terms +// of [AnimatedListState.insertItem] and [AnimatedList.removeItem]. +class ListModel { + ListModel({ + required this.listKey, + required this.removedItemBuilder, + Iterable? initialItems, + }) : _items = List.from(initialItems ?? []); + + final GlobalKey listKey; + final RemovedItemBuilder removedItemBuilder; + final List _items; + + SliverAnimatedListState get _animatedList => listKey.currentState!; + + void insert(int index, E item) { + _items.insert(index, item); + _animatedList.insertItem(index); + } + + E removeAt(int index) { + final E removedItem = _items.removeAt(index); + if (removedItem != null) { + _animatedList.removeItem( + index, + (BuildContext context, Animation animation) => + removedItemBuilder(index, context, animation), + ); + } + return removedItem; + } + + int get length => _items.length; + + E operator [](int index) => _items[index]; + + int indexOf(E item) => _items.indexOf(item); +} + +// Displays its integer item as 'Item N' on a Card whose color is based on +// the item's value. +// +// The card turns gray when [selected] is true. This widget's height +// is based on the [animation] parameter. It varies as the animation value +// transitions from 0.0 to 1.0. +class CardItem extends StatelessWidget { + const CardItem({ + Key? key, + this.onTap, + this.selected = false, + required this.animation, + required this.item, + }) : assert(item >= 0), + super(key: key); + + final Animation animation; + final VoidCallback? onTap; + final int item; + final bool selected; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.only( + left: 2.0, + right: 2.0, + top: 2.0, + bottom: 0.0, + ), + child: SizeTransition( + axis: Axis.vertical, + sizeFactor: animation, + child: GestureDetector( + onTap: onTap, + child: SizedBox( + height: 80.0, + child: Card( + color: selected + ? Colors.black12 + : Colors.primaries[item % Colors.primaries.length], + child: Center( + child: Text( + 'Item $item', + style: Theme.of(context).textTheme.headline4, + ), + ), + ), + ), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/animated_size/animated_size.0.dart b/examples/api/lib/widgets/animated_size/animated_size.0.dart new file mode 100644 index 0000000000..1512250c05 --- /dev/null +++ b/examples/api/lib/widgets/animated_size/animated_size.0.dart @@ -0,0 +1,85 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedSize +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example makes a [Container] react to being touched, causing the child +// of the [AnimatedSize] widget, here a [FlutterLogo], to animate. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class _MyStatefulWidgetState extends State { + double _size = 50.0; + bool _large = false; + + void _updateSize() { + setState(() { + _size = _large ? 250.0 : 100.0; + _large = !_large; + }); + } + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () => _updateSize(), + child: Container( + color: Colors.amberAccent, + child: AnimatedSize( + curve: Curves.easeIn, + duration: const Duration(seconds: 1), + child: FlutterLogo(size: _size), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/animated_switcher/animated_switcher.0.dart b/examples/api/lib/widgets/animated_switcher/animated_switcher.0.dart new file mode 100644 index 0000000000..15622a4073 --- /dev/null +++ b/examples/api/lib/widgets/animated_switcher/animated_switcher.0.dart @@ -0,0 +1,92 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedSwitcher +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a counter that animates the scale of a text widget +// whenever the value changes. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _count = 0; + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + AnimatedSwitcher( + duration: const Duration(milliseconds: 500), + transitionBuilder: (Widget child, Animation animation) { + return ScaleTransition(child: child, scale: animation); + }, + child: Text( + '$_count', + // This key causes the AnimatedSwitcher to interpret this as a "new" + // child each time the count changes, so that it will begin its animation + // when the count changes. + key: ValueKey(_count), + style: Theme.of(context).textTheme.headline4, + ), + ), + ElevatedButton( + child: const Text('Increment'), + onPressed: () { + setState(() { + _count += 1; + }); + }, + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/async/future_builder.0.dart b/examples/api/lib/widgets/async/future_builder.0.dart new file mode 100644 index 0000000000..8d684d6566 --- /dev/null +++ b/examples/api/lib/widgets/async/future_builder.0.dart @@ -0,0 +1,122 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FutureBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [FutureBuilder] that displays a loading spinner while it +// loads data. It displays a success icon and text if the [Future] completes +// with a result, or an error icon and text if the [Future] completes with an +// error. Assume the `_calculation` field is set by pressing a button elsewhere +// in the UI. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final Future _calculation = Future.delayed( + const Duration(seconds: 2), + () => 'Data Loaded', + ); + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: Theme.of(context).textTheme.headline2!, + textAlign: TextAlign.center, + child: FutureBuilder( + future: _calculation, // a previously-obtained Future or null + builder: (BuildContext context, AsyncSnapshot snapshot) { + List children; + if (snapshot.hasData) { + children = [ + const Icon( + Icons.check_circle_outline, + color: Colors.green, + size: 60, + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: Text('Result: ${snapshot.data}'), + ) + ]; + } else if (snapshot.hasError) { + children = [ + const Icon( + Icons.error_outline, + color: Colors.red, + size: 60, + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: Text('Error: ${snapshot.error}'), + ) + ]; + } else { + children = const [ + SizedBox( + child: CircularProgressIndicator(), + width: 60, + height: 60, + ), + Padding( + padding: EdgeInsets.only(top: 16), + child: Text('Awaiting result...'), + ) + ]; + } + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: children, + ), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/async/stream_builder.0.dart b/examples/api/lib/widgets/async/stream_builder.0.dart new file mode 100644 index 0000000000..b25bdc9259 --- /dev/null +++ b/examples/api/lib/widgets/async/stream_builder.0.dart @@ -0,0 +1,161 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for StreamBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [StreamBuilder] that listens to a Stream that emits bids +// for an auction. Every time the StreamBuilder receives a bid from the Stream, +// it will display the price of the bid below an icon. If the Stream emits an +// error, the error is displayed below an error icon. When the Stream finishes +// emitting bids, the final price is displayed. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final Stream _bids = (() async* { + await Future.delayed(const Duration(seconds: 1)); + yield 1; + await Future.delayed(const Duration(seconds: 1)); + })(); + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: Theme.of(context).textTheme.headline2!, + textAlign: TextAlign.center, + child: Container( + alignment: FractionalOffset.center, + color: Colors.white, + child: StreamBuilder( + stream: _bids, + builder: (BuildContext context, AsyncSnapshot snapshot) { + List children; + if (snapshot.hasError) { + children = [ + const Icon( + Icons.error_outline, + color: Colors.red, + size: 60, + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: Text('Error: ${snapshot.error}'), + ), + Padding( + padding: const EdgeInsets.only(top: 8), + child: Text('Stack trace: ${snapshot.stackTrace}'), + ), + ]; + } else { + switch (snapshot.connectionState) { + case ConnectionState.none: + children = const [ + Icon( + Icons.info, + color: Colors.blue, + size: 60, + ), + Padding( + padding: EdgeInsets.only(top: 16), + child: Text('Select a lot'), + ) + ]; + break; + case ConnectionState.waiting: + children = const [ + SizedBox( + child: CircularProgressIndicator(), + width: 60, + height: 60, + ), + Padding( + padding: EdgeInsets.only(top: 16), + child: Text('Awaiting bids...'), + ) + ]; + break; + case ConnectionState.active: + children = [ + const Icon( + Icons.check_circle_outline, + color: Colors.green, + size: 60, + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: Text('\$${snapshot.data}'), + ) + ]; + break; + case ConnectionState.done: + children = [ + const Icon( + Icons.info, + color: Colors.blue, + size: 60, + ), + Padding( + padding: const EdgeInsets.only(top: 16), + child: Text('\$${snapshot.data} (closed)'), + ) + ]; + break; + } + } + + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: children, + ); + }, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/autocomplete/raw_autocomplete.0.dart b/examples/api/lib/widgets/autocomplete/raw_autocomplete.0.dart new file mode 100644 index 0000000000..1c8b31557d --- /dev/null +++ b/examples/api/lib/widgets/autocomplete/raw_autocomplete.0.dart @@ -0,0 +1,108 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RawAutocomplete +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to create a very basic autocomplete widget using the +// [fieldViewBuilder] and [optionsViewBuilder] parameters. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +void main() => runApp(const AutocompleteExampleApp()); + +class AutocompleteExampleApp extends StatelessWidget { + const AutocompleteExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('RawAutocomplete Basic'), + ), + body: const Center( + child: AutocompleteBasicExample(), + ), + ), + ); + } +} + +class AutocompleteBasicExample extends StatelessWidget { + const AutocompleteBasicExample({Key? key}) : super(key: key); + + static const List _options = [ + 'aardvark', + 'bobcat', + 'chameleon', + ]; + + @override + Widget build(BuildContext context) { + return RawAutocomplete( + optionsBuilder: (TextEditingValue textEditingValue) { + return _options.where((String option) { + return option.contains(textEditingValue.text.toLowerCase()); + }); + }, + fieldViewBuilder: (BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + VoidCallback onFieldSubmitted) { + return TextFormField( + controller: textEditingController, + focusNode: focusNode, + onFieldSubmitted: (String value) { + onFieldSubmitted(); + }, + ); + }, + optionsViewBuilder: (BuildContext context, + AutocompleteOnSelected onSelected, Iterable options) { + return Align( + alignment: Alignment.topLeft, + child: Material( + elevation: 4.0, + child: SizedBox( + height: 200.0, + child: ListView.builder( + padding: const EdgeInsets.all(8.0), + itemCount: options.length, + itemBuilder: (BuildContext context, int index) { + final String option = options.elementAt(index); + return GestureDetector( + onTap: () { + onSelected(option); + }, + child: ListTile( + title: Text(option), + ), + ); + }, + ), + ), + ), + ); + }, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/widgets/autocomplete/raw_autocomplete.1.dart b/examples/api/lib/widgets/autocomplete/raw_autocomplete.1.dart new file mode 100644 index 0000000000..2a16259197 --- /dev/null +++ b/examples/api/lib/widgets/autocomplete/raw_autocomplete.1.dart @@ -0,0 +1,143 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RawAutocomplete +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example is similar to the previous example, but it uses a custom T data +// type instead of directly using String. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +void main() => runApp(const AutocompleteExampleApp()); + +class AutocompleteExampleApp extends StatelessWidget { + const AutocompleteExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('RawAutocomplete Custom Type'), + ), + body: const Center( + child: AutocompleteCustomTypeExample(), + ), + ), + ); + } +} + +// An example of a type that someone might want to autocomplete a list of. +@immutable +class User { + const User({ + required this.email, + required this.name, + }); + + final String email; + final String name; + + @override + String toString() { + return '$name, $email'; + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + return other is User && other.name == name && other.email == email; + } + + @override + int get hashCode => hashValues(email, name); +} + +class AutocompleteCustomTypeExample extends StatelessWidget { + const AutocompleteCustomTypeExample({Key? key}) : super(key: key); + + static const List _userOptions = [ + User(name: 'Alice', email: 'alice@example.com'), + User(name: 'Bob', email: 'bob@example.com'), + User(name: 'Charlie', email: 'charlie123@gmail.com'), + ]; + + static String _displayStringForOption(User option) => option.name; + + @override + Widget build(BuildContext context) { + return RawAutocomplete( + optionsBuilder: (TextEditingValue textEditingValue) { + return _userOptions.where((User option) { + // Search based on User.toString, which includes both name and + // email, even though the display string is just the name. + return option + .toString() + .contains(textEditingValue.text.toLowerCase()); + }); + }, + displayStringForOption: _displayStringForOption, + fieldViewBuilder: (BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + VoidCallback onFieldSubmitted) { + return TextFormField( + controller: textEditingController, + focusNode: focusNode, + onFieldSubmitted: (String value) { + onFieldSubmitted(); + }, + ); + }, + optionsViewBuilder: (BuildContext context, + AutocompleteOnSelected onSelected, Iterable options) { + return Align( + alignment: Alignment.topLeft, + child: Material( + elevation: 4.0, + child: SizedBox( + height: 200.0, + child: ListView.builder( + padding: const EdgeInsets.all(8.0), + itemCount: options.length, + itemBuilder: (BuildContext context, int index) { + final User option = options.elementAt(index); + return GestureDetector( + onTap: () { + onSelected(option); + }, + child: ListTile( + title: Text(_displayStringForOption(option)), + ), + ); + }, + ), + ), + ), + ); + }, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/widgets/autocomplete/raw_autocomplete.2.dart b/examples/api/lib/widgets/autocomplete/raw_autocomplete.2.dart new file mode 100644 index 0000000000..253e616409 --- /dev/null +++ b/examples/api/lib/widgets/autocomplete/raw_autocomplete.2.dart @@ -0,0 +1,212 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RawAutocomplete +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows the use of RawAutocomplete in a form. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +void main() => runApp(const AutocompleteExampleApp()); + +class AutocompleteExampleApp extends StatelessWidget { + const AutocompleteExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('RawAutocomplete Form'), + ), + body: const Center( + child: AutocompleteFormExample(), + ), + ), + ); + } +} + +class AutocompleteFormExample extends StatefulWidget { + const AutocompleteFormExample({Key? key}) : super(key: key); + + @override + AutocompleteFormExampleState createState() => AutocompleteFormExampleState(); +} + +class AutocompleteFormExampleState extends State { + final GlobalKey _formKey = GlobalKey(); + final TextEditingController _textEditingController = TextEditingController(); + String? _dropdownValue; + String? _autocompleteSelection; + + static const List _options = [ + 'aardvark', + 'bobcat', + 'chameleon', + ]; + + @override + Widget build(BuildContext context) { + return Form( + key: _formKey, + child: Column( + children: [ + DropdownButtonFormField( + value: _dropdownValue, + icon: const Icon(Icons.arrow_downward), + hint: const Text('This is a regular DropdownButtonFormField'), + iconSize: 24, + elevation: 16, + style: const TextStyle(color: Colors.deepPurple), + onChanged: (String? newValue) { + setState(() { + _dropdownValue = newValue; + }); + }, + items: ['One', 'Two', 'Free', 'Four'] + .map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + validator: (String? value) { + if (value == null) { + return 'Must make a selection.'; + } + return null; + }, + ), + TextFormField( + controller: _textEditingController, + decoration: const InputDecoration( + hintText: 'This is a regular TextFormField', + ), + validator: (String? value) { + if (value == null || value.isEmpty) { + return "Can't be empty."; + } + return null; + }, + ), + RawAutocomplete( + optionsBuilder: (TextEditingValue textEditingValue) { + return _options.where((String option) { + return option.contains(textEditingValue.text.toLowerCase()); + }); + }, + onSelected: (String selection) { + setState(() { + _autocompleteSelection = selection; + }); + }, + fieldViewBuilder: (BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + VoidCallback onFieldSubmitted) { + return TextFormField( + controller: textEditingController, + decoration: const InputDecoration( + hintText: 'This is a RawAutocomplete!', + ), + focusNode: focusNode, + onFieldSubmitted: (String value) { + onFieldSubmitted(); + }, + validator: (String? value) { + if (!_options.contains(value)) { + return 'Nothing selected.'; + } + return null; + }, + ); + }, + optionsViewBuilder: (BuildContext context, + AutocompleteOnSelected onSelected, + Iterable options) { + return Align( + alignment: Alignment.topLeft, + child: Material( + elevation: 4.0, + child: SizedBox( + height: 200.0, + child: ListView.builder( + padding: const EdgeInsets.all(8.0), + itemCount: options.length, + itemBuilder: (BuildContext context, int index) { + final String option = options.elementAt(index); + return GestureDetector( + onTap: () { + onSelected(option); + }, + child: ListTile( + title: Text(option), + ), + ); + }, + ), + ), + ), + ); + }, + ), + ElevatedButton( + onPressed: () { + FocusScope.of(context).unfocus(); + if (!_formKey.currentState!.validate()) { + return; + } + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Successfully submitted'), + content: SingleChildScrollView( + child: ListBody( + children: [ + Text('DropdownButtonFormField: "$_dropdownValue"'), + Text( + 'TextFormField: "${_textEditingController.text}"'), + Text('RawAutocomplete: "$_autocompleteSelection"'), + ], + ), + ), + actions: [ + TextButton( + child: const Text('Ok'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + }, + child: const Text('Submit'), + ), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/widgets/autocomplete/raw_autocomplete.focus_node.0.dart b/examples/api/lib/widgets/autocomplete/raw_autocomplete.focus_node.0.dart new file mode 100644 index 0000000000..42b800e604 --- /dev/null +++ b/examples/api/lib/widgets/autocomplete/raw_autocomplete.focus_node.0.dart @@ -0,0 +1,111 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RawAutocomplete.focusNode +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This examples shows how to create an autocomplete widget with the text +// field in the AppBar and the results in the main body of the app. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +void main() => runApp(const AutocompleteExampleApp()); + +class AutocompleteExampleApp extends StatelessWidget { + const AutocompleteExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const MaterialApp( + home: RawAutocompleteSplit(), + ); + } +} + +const List _options = [ + 'aardvark', + 'bobcat', + 'chameleon', +]; + +class RawAutocompleteSplit extends StatefulWidget { + const RawAutocompleteSplit({Key? key}) : super(key: key); + + @override + RawAutocompleteSplitState createState() => RawAutocompleteSplitState(); +} + +class RawAutocompleteSplitState extends State { + final TextEditingController _textEditingController = TextEditingController(); + final FocusNode _focusNode = FocusNode(); + final GlobalKey _autocompleteKey = GlobalKey(); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + // This is where the real field is being built. + title: TextFormField( + controller: _textEditingController, + focusNode: _focusNode, + decoration: const InputDecoration( + hintText: 'Split RawAutocomplete App', + ), + onFieldSubmitted: (String value) { + RawAutocomplete.onFieldSubmitted(_autocompleteKey); + }, + ), + ), + body: Align( + alignment: Alignment.topLeft, + child: RawAutocomplete( + key: _autocompleteKey, + focusNode: _focusNode, + textEditingController: _textEditingController, + optionsBuilder: (TextEditingValue textEditingValue) { + return _options.where((String option) { + return option.contains(textEditingValue.text.toLowerCase()); + }).toList(); + }, + optionsViewBuilder: (BuildContext context, + AutocompleteOnSelected onSelected, + Iterable options) { + return Material( + elevation: 4.0, + child: ListView( + children: options + .map((String option) => GestureDetector( + onTap: () { + onSelected(option); + }, + child: ListTile( + title: Text(option), + ), + )) + .toList(), + ), + ); + }, + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/widgets/autofill/autofill_group.0.dart b/examples/api/lib/widgets/autofill/autofill_group.0.dart new file mode 100644 index 0000000000..ef41276e50 --- /dev/null +++ b/examples/api/lib/widgets/autofill/autofill_group.0.dart @@ -0,0 +1,152 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AutofillGroup +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// An example form with autofillable fields grouped into different +// `AutofillGroup`s. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool isSameAddress = true; + final TextEditingController shippingAddress1 = TextEditingController(); + final TextEditingController shippingAddress2 = TextEditingController(); + final TextEditingController billingAddress1 = TextEditingController(); + final TextEditingController billingAddress2 = TextEditingController(); + + final TextEditingController creditCardNumber = TextEditingController(); + final TextEditingController creditCardSecurityCode = TextEditingController(); + + final TextEditingController phoneNumber = TextEditingController(); + + @override + Widget build(BuildContext context) { + return ListView( + children: [ + const Text('Shipping address'), + // The address fields are grouped together as some platforms are + // capable of autofilling all of these fields in one go. + AutofillGroup( + child: Column( + children: [ + TextField( + controller: shippingAddress1, + autofillHints: const [AutofillHints.streetAddressLine1], + ), + TextField( + controller: shippingAddress2, + autofillHints: const [AutofillHints.streetAddressLine2], + ), + ], + ), + ), + const Text('Billing address'), + Checkbox( + value: isSameAddress, + onChanged: (bool? newValue) { + if (newValue != null) { + setState(() { + isSameAddress = newValue; + }); + } + }, + ), + // Again the address fields are grouped together for the same reason. + if (!isSameAddress) + AutofillGroup( + child: Column( + children: [ + TextField( + controller: billingAddress1, + autofillHints: const [ + AutofillHints.streetAddressLine1 + ], + ), + TextField( + controller: billingAddress2, + autofillHints: const [ + AutofillHints.streetAddressLine2 + ], + ), + ], + ), + ), + const Text('Credit Card Information'), + // The credit card number and the security code are grouped together + // as some platforms are capable of autofilling both fields. + AutofillGroup( + child: Column( + children: [ + TextField( + controller: creditCardNumber, + autofillHints: const [AutofillHints.creditCardNumber], + ), + TextField( + controller: creditCardSecurityCode, + autofillHints: const [ + AutofillHints.creditCardSecurityCode + ], + ), + ], + ), + ), + const Text('Contact Phone Number'), + // The phone number field can still be autofilled despite lacking an + // `AutofillScope`. + TextField( + controller: phoneNumber, + autofillHints: const [AutofillHints.telephoneNumber], + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/absorb_pointer.0.dart b/examples/api/lib/widgets/basic/absorb_pointer.0.dart new file mode 100644 index 0000000000..a5f5960f3e --- /dev/null +++ b/examples/api/lib/widgets/basic/absorb_pointer.0.dart @@ -0,0 +1,87 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AbsorbPointer +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following sample has an [AbsorbPointer] widget wrapping the button on +// top of the stack, which absorbs pointer events, preventing its child button +// __and__ the button below it in the stack from receiving the pointer events. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Stack( + alignment: AlignmentDirectional.center, + children: [ + SizedBox( + width: 200.0, + height: 100.0, + child: ElevatedButton( + onPressed: () {}, + child: null, + ), + ), + SizedBox( + width: 100.0, + height: 200.0, + child: AbsorbPointer( + absorbing: true, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Colors.blue.shade200, + ), + onPressed: () {}, + child: null, + ), + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/aspect_ratio.0.dart b/examples/api/lib/widgets/basic/aspect_ratio.0.dart new file mode 100644 index 0000000000..81f928c395 --- /dev/null +++ b/examples/api/lib/widgets/basic/aspect_ratio.0.dart @@ -0,0 +1,73 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AspectRatio +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This examples shows how AspectRatio sets width when its parent's width +// constraint is infinite. Since its parent's allowed height is a fixed value, +// the actual width is determined via the given AspectRatio. +// +// Since the height is fixed at 100.0 in this example and the aspect ratio is +// set to 16 / 9, the width should then be 100.0 / 9 * 16. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + color: Colors.blue, + alignment: Alignment.center, + width: double.infinity, + height: 100.0, + child: AspectRatio( + aspectRatio: 16 / 9, + child: Container( + color: Colors.green, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/aspect_ratio.1.dart b/examples/api/lib/widgets/basic/aspect_ratio.1.dart new file mode 100644 index 0000000000..e114038a82 --- /dev/null +++ b/examples/api/lib/widgets/basic/aspect_ratio.1.dart @@ -0,0 +1,70 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AspectRatio +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + color: Colors.blue, + alignment: Alignment.center, + width: 100.0, + height: 100.0, + child: AspectRatio( + aspectRatio: 2.0, + child: Container( + width: 100.0, + height: 50.0, + color: Colors.green, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/aspect_ratio.2.dart b/examples/api/lib/widgets/basic/aspect_ratio.2.dart new file mode 100644 index 0000000000..a43cf5dd3d --- /dev/null +++ b/examples/api/lib/widgets/basic/aspect_ratio.2.dart @@ -0,0 +1,70 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AspectRatio +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + color: Colors.blue, + alignment: Alignment.center, + width: 100.0, + height: 100.0, + child: AspectRatio( + aspectRatio: 0.5, + child: Container( + width: 100.0, + height: 50.0, + color: Colors.green, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/expanded.0.dart b/examples/api/lib/widgets/basic/expanded.0.dart new file mode 100644 index 0000000000..214dd80c81 --- /dev/null +++ b/examples/api/lib/widgets/basic/expanded.0.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Expanded +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to use an [Expanded] widget in a [Column] so that +// its middle child, a [Container] here, expands to fill the space. +// +// ![This results in two thin blue boxes with a larger amber box in between.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_column.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Expanded Column Sample'), + ), + body: Center( + child: Column( + children: [ + Container( + color: Colors.blue, + height: 100, + width: 100, + ), + Expanded( + child: Container( + color: Colors.amber, + width: 100, + ), + ), + Container( + color: Colors.blue, + height: 100, + width: 100, + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/expanded.1.dart b/examples/api/lib/widgets/basic/expanded.1.dart new file mode 100644 index 0000000000..dd705fe7bc --- /dev/null +++ b/examples/api/lib/widgets/basic/expanded.1.dart @@ -0,0 +1,86 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Expanded +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to use an [Expanded] widget in a [Row] with multiple +// children expanded, utilizing the [flex] factor to prioritize available space. +// +// ![This results in a wide amber box, followed by a thin blue box, with a medium width amber box at the end.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_row.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Expanded Row Sample'), + ), + body: Center( + child: Row( + children: [ + Expanded( + flex: 2, + child: Container( + color: Colors.amber, + height: 100, + ), + ), + Container( + color: Colors.blue, + height: 100, + width: 50, + ), + Expanded( + flex: 1, + child: Container( + color: Colors.amber, + height: 100, + ), + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/fitted_box.0.dart b/examples/api/lib/widgets/basic/fitted_box.0.dart new file mode 100644 index 0000000000..262a695a96 --- /dev/null +++ b/examples/api/lib/widgets/basic/fitted_box.0.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FittedBox +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this example, the image is stretched to fill the entire [Container], which would +// not happen normally without using FittedBox. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + height: 400, + width: 300, + color: Colors.red, + child: FittedBox( + child: Image.network( + 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'), + fit: BoxFit.fill, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/flow.0.dart b/examples/api/lib/widgets/basic/flow.0.dart new file mode 100644 index 0000000000..6c1c12ed95 --- /dev/null +++ b/examples/api/lib/widgets/basic/flow.0.dart @@ -0,0 +1,143 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Flow +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example uses the [Flow] widget to create a menu that opens and closes +// as it is interacted with, shown above. The color of the button in the menu +// changes to indicate which one has been selected. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +void main() => runApp(const FlowApp()); + +class FlowApp extends StatelessWidget { + const FlowApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Flow Example'), + ), + body: const FlowMenu(), + ), + ); + } +} + +class FlowMenu extends StatefulWidget { + const FlowMenu({Key? key}) : super(key: key); + + @override + State createState() => _FlowMenuState(); +} + +class _FlowMenuState extends State + with SingleTickerProviderStateMixin { + late AnimationController menuAnimation; + IconData lastTapped = Icons.notifications; + final List menuItems = [ + Icons.home, + Icons.new_releases, + Icons.notifications, + Icons.settings, + Icons.menu, + ]; + + void _updateMenu(IconData icon) { + if (icon != Icons.menu) { + setState(() => lastTapped = icon); + } + } + + @override + void initState() { + super.initState(); + menuAnimation = AnimationController( + duration: const Duration(milliseconds: 250), + vsync: this, + ); + } + + Widget flowMenuItem(IconData icon) { + final double buttonDiameter = + MediaQuery.of(context).size.width / menuItems.length; + return Padding( + padding: const EdgeInsets.symmetric(vertical: 8.0), + child: RawMaterialButton( + fillColor: lastTapped == icon ? Colors.amber[700] : Colors.blue, + splashColor: Colors.amber[100], + shape: const CircleBorder(), + constraints: BoxConstraints.tight(Size(buttonDiameter, buttonDiameter)), + onPressed: () { + _updateMenu(icon); + menuAnimation.status == AnimationStatus.completed + ? menuAnimation.reverse() + : menuAnimation.forward(); + }, + child: Icon( + icon, + color: Colors.white, + size: 45.0, + ), + ), + ); + } + + @override + Widget build(BuildContext context) { + return Flow( + delegate: FlowMenuDelegate(menuAnimation: menuAnimation), + children: + menuItems.map((IconData icon) => flowMenuItem(icon)).toList(), + ); + } +} + +class FlowMenuDelegate extends FlowDelegate { + FlowMenuDelegate({required this.menuAnimation}) + : super(repaint: menuAnimation); + + final Animation menuAnimation; + + @override + bool shouldRepaint(FlowMenuDelegate oldDelegate) { + return menuAnimation != oldDelegate.menuAnimation; + } + + @override + void paintChildren(FlowPaintingContext context) { + double dx = 0.0; + for (int i = 0; i < context.childCount; ++i) { + dx = context.getChildSize(i)!.width * i; + context.paintChild( + i, + transform: Matrix4.translationValues( + dx * menuAnimation.value, + 0, + 0, + ), + ); + } + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/widgets/basic/fractionally_sized_box.0.dart b/examples/api/lib/widgets/basic/fractionally_sized_box.0.dart new file mode 100644 index 0000000000..2bf6b55c19 --- /dev/null +++ b/examples/api/lib/widgets/basic/fractionally_sized_box.0.dart @@ -0,0 +1,73 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FractionallySizedBox +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [FractionallySizedBox] whose one child is 50% of +// the box's size per the width and height factor parameters, and centered +// within that box by the alignment parameter. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return SizedBox.expand( + child: FractionallySizedBox( + widthFactor: 0.5, + heightFactor: 0.5, + alignment: FractionalOffset.center, + child: DecoratedBox( + decoration: BoxDecoration( + border: Border.all( + color: Colors.blue, + width: 4, + ), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/ignore_pointer.0.dart b/examples/api/lib/widgets/basic/ignore_pointer.0.dart new file mode 100644 index 0000000000..d1ede6ca5b --- /dev/null +++ b/examples/api/lib/widgets/basic/ignore_pointer.0.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for IgnorePointer +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following sample has an [IgnorePointer] widget wrapping the `Column` +// which contains a button. +// When [ignoring] is set to `true` anything inside the `Column` can +// not be tapped. When [ignoring] is set to `false` anything +// inside the `Column` can be tapped. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool ignoring = false; + void setIgnoring(bool newValue) { + setState(() { + ignoring = newValue; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + centerTitle: true, + title: ElevatedButton( + onPressed: () { + setIgnoring(!ignoring); + }, + child: Text( + ignoring ? 'Set ignoring to false' : 'Set ignoring to true', + ), + ), + ), + body: Center( + child: IgnorePointer( + ignoring: ignoring, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Text('Ignoring: $ignoring'), + ElevatedButton( + onPressed: () {}, + child: const Text('Click me!'), + ), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/listener.0.dart b/examples/api/lib/widgets/basic/listener.0.dart new file mode 100644 index 0000000000..99282bd76e --- /dev/null +++ b/examples/api/lib/widgets/basic/listener.0.dart @@ -0,0 +1,123 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Listener +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example makes a [Container] react to being touched, showing a count of +// the number of pointer downs and ups. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/widgets.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _downCounter = 0; + int _upCounter = 0; + double x = 0.0; + double y = 0.0; + + void _incrementDown(PointerEvent details) { + _updateLocation(details); + setState(() { + _downCounter++; + }); + } + + void _incrementUp(PointerEvent details) { + _updateLocation(details); + setState(() { + _upCounter++; + }); + } + + void _updateLocation(PointerEvent details) { + setState(() { + x = details.position.dx; + y = details.position.dy; + }); + } + + @override + Widget build(BuildContext context) { + return ConstrainedBox( + constraints: BoxConstraints.tight(const Size(300.0, 200.0)), + child: Listener( + onPointerDown: _incrementDown, + onPointerMove: _updateLocation, + onPointerUp: _incrementUp, + child: Container( + color: Colors.lightBlueAccent, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have pressed or released in this area this many times:'), + Text( + '$_downCounter presses\n$_upCounter releases', + style: Theme.of(context).textTheme.headline4, + ), + Text( + 'The cursor is here: (${x.toStringAsFixed(2)}, ${y.toStringAsFixed(2)})', + ), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/mouse_region.0.dart b/examples/api/lib/widgets/basic/mouse_region.0.dart new file mode 100644 index 0000000000..3b11edc9cf --- /dev/null +++ b/examples/api/lib/widgets/basic/mouse_region.0.dart @@ -0,0 +1,121 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MouseRegion +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example makes a [Container] react to being entered by a mouse +// pointer, showing a count of the number of entries and exits. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/widgets.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int _enterCounter = 0; + int _exitCounter = 0; + double x = 0.0; + double y = 0.0; + + void _incrementEnter(PointerEvent details) { + setState(() { + _enterCounter++; + }); + } + + void _incrementExit(PointerEvent details) { + setState(() { + _exitCounter++; + }); + } + + void _updateLocation(PointerEvent details) { + setState(() { + x = details.position.dx; + y = details.position.dy; + }); + } + + @override + Widget build(BuildContext context) { + return ConstrainedBox( + constraints: BoxConstraints.tight(const Size(300.0, 200.0)), + child: MouseRegion( + onEnter: _incrementEnter, + onHover: _updateLocation, + onExit: _incrementExit, + child: Container( + color: Colors.lightBlueAccent, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have entered or exited this box this many times:'), + Text( + '$_enterCounter Entries\n$_exitCounter Exits', + style: Theme.of(context).textTheme.headline4, + ), + Text( + 'The cursor is here: (${x.toStringAsFixed(2)}, ${y.toStringAsFixed(2)})', + ), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart b/examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart new file mode 100644 index 0000000000..b9304987b6 --- /dev/null +++ b/examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart @@ -0,0 +1,86 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MouseRegion.onExit +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example shows a blue rectangular that turns yellow when +// hovered. Since the hover state is completely contained within a widget +// that unconditionally creates the `MouseRegion`, you can ignore the +// aforementioned restriction. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool hovered = false; + + @override + Widget build(BuildContext context) { + return Container( + height: 100, + width: 100, + decoration: BoxDecoration(color: hovered ? Colors.yellow : Colors.blue), + child: MouseRegion( + onEnter: (_) { + setState(() { + hovered = true; + }); + }, + onExit: (_) { + setState(() { + hovered = false; + }); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart b/examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart new file mode 100644 index 0000000000..35cdbebe6f --- /dev/null +++ b/examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart @@ -0,0 +1,167 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MouseRegion.onExit +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example shows a widget that hides its content one second +// after being hovered, and also exposes the enter and exit callbacks. +// Because the widget conditionally creates the `MouseRegion`, and leaks the +// hover state, it needs to take the restriction into consideration. In this +// case, since it has access to the event that triggers the disappearance of +// the `MouseRegion`, it simply trigger the exit callback during that event +// as well. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// A region that hides its content one second after being hovered. +class MyTimedButton extends StatefulWidget { + const MyTimedButton( + {Key? key, required this.onEnterButton, required this.onExitButton}) + : super(key: key); + + final VoidCallback onEnterButton; + final VoidCallback onExitButton; + + @override + State createState() => _MyTimedButton(); +} + +class _MyTimedButton extends State { + bool regionIsHidden = false; + bool hovered = false; + + Future startCountdown() async { + await Future.delayed(const Duration(seconds: 1)); + hideButton(); + } + + void hideButton() { + setState(() { + regionIsHidden = true; + }); + // This statement is necessary. + if (hovered) { + widget.onExitButton(); + } + } + + @override + Widget build(BuildContext context) { + return SizedBox( + width: 100, + height: 100, + child: MouseRegion( + child: regionIsHidden + ? null + : MouseRegion( + onEnter: (_) { + widget.onEnterButton(); + setState(() { + hovered = true; + }); + startCountdown(); + }, + onExit: (_) { + setState(() { + hovered = false; + }); + widget.onExitButton(); + }, + child: Container(color: Colors.red), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Key key = UniqueKey(); + bool hovering = false; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + ElevatedButton( + onPressed: () { + setState(() { + key = UniqueKey(); + }); + }, + child: const Text('Refresh'), + ), + if (hovering) const Text('Hovering'), + if (!hovering) const Text('Not hovering'), + MyTimedButton( + key: key, + onEnterButton: () { + setState(() { + hovering = true; + }); + }, + onExitButton: () { + setState(() { + hovering = false; + }); + }, + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/offstage.0.dart b/examples/api/lib/widgets/basic/offstage.0.dart new file mode 100644 index 0000000000..30ae69ce02 --- /dev/null +++ b/examples/api/lib/widgets/basic/offstage.0.dart @@ -0,0 +1,108 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Offstage +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [FlutterLogo] widget when the `_offstage` member field +// is false, and hides it without any room in the parent when it is true. When +// offstage, this app displays a button to get the logo size, which will be +// displayed in a [SnackBar]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final GlobalKey _key = GlobalKey(); + bool _offstage = true; + + Size _getFlutterLogoSize() { + final RenderBox renderLogo = + _key.currentContext!.findRenderObject()! as RenderBox; + return renderLogo.size; + } + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Offstage( + offstage: _offstage, + child: FlutterLogo( + key: _key, + size: 150.0, + ), + ), + Text('Flutter logo is offstage: $_offstage'), + ElevatedButton( + child: const Text('Toggle Offstage Value'), + onPressed: () { + setState(() { + _offstage = !_offstage; + }); + }, + ), + if (_offstage) + ElevatedButton( + child: const Text('Get Flutter Logo size'), + onPressed: () { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: + Text('Flutter Logo size is ${_getFlutterLogoSize()}'), + ), + ); + }), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/basic/physical_shape.0.dart b/examples/api/lib/widgets/basic/physical_shape.0.dart new file mode 100644 index 0000000000..60845b4411 --- /dev/null +++ b/examples/api/lib/widgets/basic/physical_shape.0.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for PhysicalShape +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to use a [PhysicalShape] on a centered [SizedBox] +// to clip it to a rounded rectangle using a [ShapeBorderClipper] and give it +// an orange color along with a shadow. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('PhysicalShape Sample'), + ), + body: Center( + child: PhysicalShape( + elevation: 5.0, + child: const SizedBox( + child: Center( + child: Text( + 'Hello, World!', + style: TextStyle( + color: Colors.white, + fontSize: 20.0, + ), + ), + ), + height: 200.0, + width: 200.0, + ), + clipper: ShapeBorderClipper( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10.0), + )), + color: Colors.orange, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/color_filter/color_filtered.0.dart b/examples/api/lib/widgets/color_filter/color_filtered.0.dart new file mode 100644 index 0000000000..75eb997124 --- /dev/null +++ b/examples/api/lib/widgets/color_filter/color_filtered.0.dart @@ -0,0 +1,79 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ColorFiltered +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// These two images have two [ColorFilter]s applied with different [BlendMode]s, +// one with red color and [BlendMode.modulate] another with a grey color and [BlendMode.saturation]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Column( + children: [ + ColorFiltered( + colorFilter: const ColorFilter.mode( + Colors.red, + BlendMode.modulate, + ), + child: Image.network( + 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'), + ), + ColorFiltered( + colorFilter: const ColorFilter.mode( + Colors.grey, + BlendMode.saturation, + ), + child: Image.network( + 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/dismissible/dismissible.0.dart b/examples/api/lib/widgets/dismissible/dismissible.0.dart new file mode 100644 index 0000000000..35231519f6 --- /dev/null +++ b/examples/api/lib/widgets/dismissible/dismissible.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Dismissible +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how you can use the [Dismissible] widget to +// remove list items using swipe gestures. Swipe any of the list +// tiles to the left or right to dismiss them from the [ListView]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + List items = List.generate(100, (int index) => index); + + @override + Widget build(BuildContext context) { + return ListView.builder( + itemCount: items.length, + padding: const EdgeInsets.symmetric(vertical: 16), + itemBuilder: (BuildContext context, int index) { + return Dismissible( + child: ListTile( + title: Text( + 'Item ${items[index]}', + ), + ), + background: Container( + color: Colors.green, + ), + key: ValueKey(items[index]), + onDismissed: (DismissDirection direction) { + setState(() { + items.removeAt(index); + }); + }, + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/drag_target/draggable.0.dart b/examples/api/lib/widgets/drag_target/draggable.0.dart new file mode 100644 index 0000000000..c5884af03a --- /dev/null +++ b/examples/api/lib/widgets/drag_target/draggable.0.dart @@ -0,0 +1,118 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Draggable +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example has a [Draggable] widget along with a [DragTarget] +// in a row demonstrating an incremented `acceptedData` integer value when +// you drag the element to the target. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int acceptedData = 0; + + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Draggable( + // Data is the value this Draggable stores. + data: 10, + child: Container( + height: 100.0, + width: 100.0, + color: Colors.lightGreenAccent, + child: const Center( + child: Text('Draggable'), + ), + ), + feedback: Container( + color: Colors.deepOrange, + height: 100, + width: 100, + child: const Icon(Icons.directions_run), + ), + childWhenDragging: Container( + height: 100.0, + width: 100.0, + color: Colors.pinkAccent, + child: const Center( + child: Text('Child When Dragging'), + ), + ), + ), + DragTarget( + builder: ( + BuildContext context, + List accepted, + List rejected, + ) { + return Container( + height: 100.0, + width: 100.0, + color: Colors.cyan, + child: Center( + child: Text('Value is updated to: $acceptedData'), + ), + ); + }, + onAccept: (int data) { + setState(() { + acceptedData += data; + }); + }, + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/editable_text/editable_text.on_changed.0.dart b/examples/api/lib/widgets/editable_text/editable_text.on_changed.0.dart new file mode 100644 index 0000000000..81d7d91cbd --- /dev/null +++ b/examples/api/lib/widgets/editable_text/editable_text.on_changed.0.dart @@ -0,0 +1,102 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for EditableText.onChanged +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how onChanged could be used to check the TextField's +// current value each time the user inserts or deletes a character. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final TextEditingController _controller = TextEditingController(); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('What number comes next in the sequence?'), + const Text('1, 1, 2, 3, 5, 8...?'), + TextField( + controller: _controller, + onChanged: (String value) async { + if (value != '13') { + return; + } + await showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('That is correct!'), + content: const Text('13 is the right answer.'), + actions: [ + TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: const Text('OK'), + ), + ], + ); + }, + ); + }, + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/editable_text/text_editing_controller.0.dart b/examples/api/lib/widgets/editable_text/text_editing_controller.0.dart new file mode 100644 index 0000000000..a8ff55f2d8 --- /dev/null +++ b/examples/api/lib/widgets/editable_text/text_editing_controller.0.dart @@ -0,0 +1,93 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TextEditingController +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example creates a [TextField] with a [TextEditingController] whose +// change listener forces the entered text to be lower case and keeps the +// cursor at the end of the input. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final TextEditingController _controller = TextEditingController(); + + @override + void initState() { + super.initState(); + _controller.addListener(() { + final String text = _controller.text.toLowerCase(); + _controller.value = _controller.value.copyWith( + text: text, + selection: + TextSelection(baseOffset: text.length, extentOffset: text.length), + composing: TextRange.empty, + ); + }); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Container( + alignment: Alignment.center, + padding: const EdgeInsets.all(6), + child: TextFormField( + controller: _controller, + decoration: const InputDecoration(border: OutlineInputBorder()), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_manager/focus_node.0.dart b/examples/api/lib/widgets/focus_manager/focus_node.0.dart new file mode 100644 index 0000000000..a0dd6bb146 --- /dev/null +++ b/examples/api/lib/widgets/focus_manager/focus_node.0.dart @@ -0,0 +1,164 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FocusNode +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how a FocusNode should be managed if not using the +// [Focus] or [FocusScope] widgets. See the [Focus] widget for a similar +// example using [Focus] and [FocusScope] widgets. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class ColorfulButton extends StatefulWidget { + const ColorfulButton({Key? key}) : super(key: key); + + @override + State createState() => _ColorfulButtonState(); +} + +class _ColorfulButtonState extends State { + late FocusNode _node; + bool _focused = false; + late FocusAttachment _nodeAttachment; + Color _color = Colors.white; + + @override + void initState() { + super.initState(); + _node = FocusNode(debugLabel: 'Button'); + _node.addListener(_handleFocusChange); + _nodeAttachment = _node.attach(context, onKey: _handleKeyPress); + } + + void _handleFocusChange() { + if (_node.hasFocus != _focused) { + setState(() { + _focused = _node.hasFocus; + }); + } + } + + KeyEventResult _handleKeyPress(FocusNode node, RawKeyEvent event) { + if (event is RawKeyDownEvent) { + print('Focus node ${node.debugLabel} got key event: ${event.logicalKey}'); + if (event.logicalKey == LogicalKeyboardKey.keyR) { + print('Changing color to red.'); + setState(() { + _color = Colors.red; + }); + return KeyEventResult.handled; + } else if (event.logicalKey == LogicalKeyboardKey.keyG) { + print('Changing color to green.'); + setState(() { + _color = Colors.green; + }); + return KeyEventResult.handled; + } else if (event.logicalKey == LogicalKeyboardKey.keyB) { + print('Changing color to blue.'); + setState(() { + _color = Colors.blue; + }); + return KeyEventResult.handled; + } + } + return KeyEventResult.ignored; + } + + @override + void dispose() { + _node.removeListener(_handleFocusChange); + // The attachment will automatically be detached in dispose(). + _node.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + _nodeAttachment.reparent(); + return GestureDetector( + onTap: () { + if (_focused) { + _node.unfocus(); + } else { + _node.requestFocus(); + } + }, + child: Center( + child: Container( + width: 400, + height: 100, + color: _focused ? _color : Colors.white, + alignment: Alignment.center, + child: + Text(_focused ? "I'm in color! Press R,G,B!" : 'Press to focus'), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + final TextTheme textTheme = Theme.of(context).textTheme; + return DefaultTextStyle( + style: textTheme.headline4!, + child: const ColorfulButton(), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart b/examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart new file mode 100644 index 0000000000..17b230dbd6 --- /dev/null +++ b/examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart @@ -0,0 +1,133 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FocusNode.unfocus +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows the difference between the different [UnfocusDisposition] +// values for [unfocus]. +// +// Try setting focus on the four text fields by selecting them, and then +// select "UNFOCUS" to see what happens when the current +// [FocusManager.primaryFocus] is unfocused. +// +// Try pressing the TAB key after unfocusing to see what the next widget +// chosen is. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/foundation.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + UnfocusDisposition disposition = UnfocusDisposition.scope; + + @override + Widget build(BuildContext context) { + return Material( + child: Container( + color: Colors.white, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Wrap( + children: List.generate(4, (int index) { + return const SizedBox( + width: 200, + child: Padding( + padding: EdgeInsets.all(8.0), + child: TextField( + decoration: InputDecoration(border: OutlineInputBorder()), + ), + ), + ); + }), + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ...List.generate(UnfocusDisposition.values.length, + (int index) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + Radio( + groupValue: disposition, + onChanged: (UnfocusDisposition? value) { + setState(() { + if (value != null) { + disposition = value; + } + }); + }, + value: UnfocusDisposition.values[index], + ), + Text(describeEnum(UnfocusDisposition.values[index])), + ], + ); + }), + OutlinedButton( + child: const Text('UNFOCUS'), + onPressed: () { + setState(() { + primaryFocus!.unfocus(disposition: disposition); + }); + }, + ), + ], + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_scope/focus.0.dart b/examples/api/lib/widgets/focus_scope/focus.0.dart new file mode 100644 index 0000000000..3625b12b63 --- /dev/null +++ b/examples/api/lib/widgets/focus_scope/focus.0.dart @@ -0,0 +1,137 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Focus +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to manage focus using the [Focus] and [FocusScope] +// widgets. See [FocusNode] for a similar example that doesn't use [Focus] or +// [FocusScope]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Color _color = Colors.white; + + KeyEventResult _handleKeyPress(FocusNode node, RawKeyEvent event) { + if (event is RawKeyDownEvent) { + print('Focus node ${node.debugLabel} got key event: ${event.logicalKey}'); + if (event.logicalKey == LogicalKeyboardKey.keyR) { + print('Changing color to red.'); + setState(() { + _color = Colors.red; + }); + return KeyEventResult.handled; + } else if (event.logicalKey == LogicalKeyboardKey.keyG) { + print('Changing color to green.'); + setState(() { + _color = Colors.green; + }); + return KeyEventResult.handled; + } else if (event.logicalKey == LogicalKeyboardKey.keyB) { + print('Changing color to blue.'); + setState(() { + _color = Colors.blue; + }); + return KeyEventResult.handled; + } + } + return KeyEventResult.ignored; + } + + @override + Widget build(BuildContext context) { + final TextTheme textTheme = Theme.of(context).textTheme; + return FocusScope( + debugLabel: 'Scope', + autofocus: true, + child: DefaultTextStyle( + style: textTheme.headline4!, + child: Focus( + onKey: _handleKeyPress, + debugLabel: 'Button', + child: Builder( + builder: (BuildContext context) { + final FocusNode focusNode = Focus.of(context); + final bool hasFocus = focusNode.hasFocus; + return GestureDetector( + onTap: () { + if (hasFocus) { + focusNode.unfocus(); + } else { + focusNode.requestFocus(); + } + }, + child: Center( + child: Container( + width: 400, + height: 100, + alignment: Alignment.center, + color: hasFocus ? _color : Colors.white, + child: Text(hasFocus + ? "I'm in color! Press R,G,B!" + : 'Press to focus'), + ), + ), + ); + }, + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_scope/focus.1.dart b/examples/api/lib/widgets/focus_scope/focus.1.dart new file mode 100644 index 0000000000..e2a22f1838 --- /dev/null +++ b/examples/api/lib/widgets/focus_scope/focus.1.dart @@ -0,0 +1,110 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Focus +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to wrap another widget in a [Focus] widget to make it +// focusable. It wraps a [Container], and changes the container's color when it +// is set as the [FocusManager.primaryFocus]. +// +// If you also want to handle mouse hover and/or keyboard actions on a widget, +// consider using a [FocusableActionDetector], which combines several different +// widgets to provide those capabilities. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class FocusableText extends StatelessWidget { + const FocusableText( + this.data, { + Key? key, + required this.autofocus, + }) : super(key: key); + + /// The string to display as the text for this widget. + final String data; + + /// Whether or not to focus this widget initially if nothing else is focused. + final bool autofocus; + + @override + Widget build(BuildContext context) { + return Focus( + autofocus: autofocus, + child: Builder(builder: (BuildContext context) { + // The contents of this Builder are being made focusable. It is inside + // of a Builder because the builder provides the correct context + // variable for Focus.of() to be able to find the Focus widget that is + // the Builder's parent. Without the builder, the context variable used + // would be the one given the FocusableText build function, and that + // would start looking for a Focus widget ancestor of the FocusableText + // instead of finding the one inside of its build function. + return Container( + padding: const EdgeInsets.all(8.0), + // Change the color based on whether or not this Container has focus. + color: Focus.of(context).hasPrimaryFocus ? Colors.black12 : null, + child: Text(data), + ); + }), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + body: ListView.builder( + itemBuilder: (BuildContext context, int index) => FocusableText( + 'Item $index', + autofocus: index == 0, + ), + itemCount: 50, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_scope/focus.2.dart b/examples/api/lib/widgets/focus_scope/focus.2.dart new file mode 100644 index 0000000000..0dee82bdd1 --- /dev/null +++ b/examples/api/lib/widgets/focus_scope/focus.2.dart @@ -0,0 +1,115 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Focus +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to focus a newly-created widget immediately after it +// is created. +// +// The focus node will not actually be given the focus until after the frame in +// which it has requested focus is drawn, so it is OK to call +// [FocusNode.requestFocus] on a node which is not yet in the focus tree. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int focusedChild = 0; + List children = []; + List childFocusNodes = []; + + @override + void initState() { + super.initState(); + // Add the first child. + _addChild(); + } + + @override + void dispose() { + super.dispose(); + for (final FocusNode node in childFocusNodes) { + node.dispose(); + } + } + + void _addChild() { + // Calling requestFocus here creates a deferred request for focus, since the + // node is not yet part of the focus tree. + childFocusNodes + .add(FocusNode(debugLabel: 'Child ${children.length}')..requestFocus()); + + children.add(Padding( + padding: const EdgeInsets.all(2.0), + child: ActionChip( + focusNode: childFocusNodes.last, + label: Text('CHILD ${children.length}'), + onPressed: () {}, + ), + )); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Wrap( + children: children, + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: () { + setState(() { + focusedChild = children.length; + _addChild(); + }); + }, + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_scope/focus_scope.0.dart b/examples/api/lib/widgets/focus_scope/focus_scope.0.dart new file mode 100644 index 0000000000..9c1d79be3c --- /dev/null +++ b/examples/api/lib/widgets/focus_scope/focus_scope.0.dart @@ -0,0 +1,196 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FocusScope +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example demonstrates using a [FocusScope] to restrict focus to a particular +// portion of the app. In this case, restricting focus to the visible part of a +// Stack. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +/// A demonstration pane. +/// +/// This is just a separate widget to simplify the example. +class Pane extends StatelessWidget { + const Pane({ + Key? key, + required this.focusNode, + this.onPressed, + required this.backgroundColor, + required this.icon, + this.child, + }) : super(key: key); + + final FocusNode focusNode; + final VoidCallback? onPressed; + final Color backgroundColor; + final Widget icon; + final Widget? child; + + @override + Widget build(BuildContext context) { + return Material( + color: backgroundColor, + child: Stack( + fit: StackFit.expand, + children: [ + Center( + child: child, + ), + Align( + alignment: Alignment.topLeft, + child: IconButton( + autofocus: true, + focusNode: focusNode, + onPressed: onPressed, + icon: icon, + ), + ), + ], + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool backdropIsVisible = false; + FocusNode backdropNode = FocusNode(debugLabel: 'Close Backdrop Button'); + FocusNode foregroundNode = FocusNode(debugLabel: 'Option Button'); + + @override + void dispose() { + super.dispose(); + backdropNode.dispose(); + foregroundNode.dispose(); + } + + Widget _buildStack(BuildContext context, BoxConstraints constraints) { + final Size stackSize = constraints.biggest; + return Stack( + fit: StackFit.expand, + // The backdrop is behind the front widget in the Stack, but the widgets + // would still be active and traversable without the FocusScope. + children: [ + // TRY THIS: Try removing this FocusScope entirely to see how it affects + // the behavior. Without this FocusScope, the "ANOTHER BUTTON TO FOCUS" + // button, and the IconButton in the backdrop Pane would be focusable + // even when the backdrop wasn't visible. + FocusScope( + // TRY THIS: Try commenting out this line. Notice that the focus + // starts on the backdrop and is stuck there? It seems like the app is + // non-responsive, but it actually isn't. This line makes sure that + // this focus scope and its children can't be focused when they're not + // visible. It might help to make the background color of the + // foreground pane semi-transparent to see it clearly. + canRequestFocus: backdropIsVisible, + child: Pane( + icon: const Icon(Icons.close), + focusNode: backdropNode, + backgroundColor: Colors.lightBlue, + onPressed: () => setState(() => backdropIsVisible = false), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // This button would be not visible, but still focusable from + // the foreground pane without the FocusScope. + ElevatedButton( + onPressed: () => print('You pressed the other button!'), + child: const Text('ANOTHER BUTTON TO FOCUS'), + ), + DefaultTextStyle( + style: Theme.of(context).textTheme.headline2!, + child: const Text('BACKDROP')), + ], + ), + ), + ), + AnimatedPositioned( + curve: Curves.easeInOut, + duration: const Duration(milliseconds: 300), + top: backdropIsVisible ? stackSize.height * 0.9 : 0.0, + width: stackSize.width, + height: stackSize.height, + onEnd: () { + if (backdropIsVisible) { + backdropNode.requestFocus(); + } else { + foregroundNode.requestFocus(); + } + }, + child: Pane( + icon: const Icon(Icons.menu), + focusNode: foregroundNode, + // TRY THIS: Try changing this to Colors.green.withOpacity(0.8) to see for + // yourself that the hidden components do/don't get focus. + backgroundColor: Colors.green, + onPressed: backdropIsVisible + ? null + : () => setState(() => backdropIsVisible = true), + child: DefaultTextStyle( + style: Theme.of(context).textTheme.headline2!, + child: const Text('FOREGROUND')), + ), + ), + ], + ); + } + + @override + Widget build(BuildContext context) { + // Use a LayoutBuilder so that we can base the size of the stack on the size + // of its parent. + return LayoutBuilder(builder: _buildStack); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart b/examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart new file mode 100644 index 0000000000..f9a3b384d2 --- /dev/null +++ b/examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart @@ -0,0 +1,221 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FocusTraversalGroup +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows three rows of buttons, each grouped by a +// [FocusTraversalGroup], each with different traversal order policies. Use tab +// traversal to see the order they are traversed in. The first row follows a +// numerical order, the second follows a lexical order (ordered to traverse +// right to left), and the third ignores the numerical order assigned to it and +// traverses in widget order. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +/// A button wrapper that adds either a numerical or lexical order, depending on +/// the type of T. +class OrderedButton extends StatefulWidget { + const OrderedButton({ + Key? key, + required this.name, + this.canRequestFocus = true, + this.autofocus = false, + required this.order, + }) : super(key: key); + + final String name; + final bool canRequestFocus; + final bool autofocus; + final T order; + + @override + State> createState() => _OrderedButtonState(); +} + +class _OrderedButtonState extends State> { + late FocusNode focusNode; + + @override + void initState() { + super.initState(); + focusNode = FocusNode( + debugLabel: widget.name, + canRequestFocus: widget.canRequestFocus, + ); + } + + @override + void dispose() { + focusNode.dispose(); + super.dispose(); + } + + @override + void didUpdateWidget(OrderedButton oldWidget) { + super.didUpdateWidget(oldWidget); + focusNode.canRequestFocus = widget.canRequestFocus; + } + + void _handleOnPressed() { + focusNode.requestFocus(); + print('Button ${widget.name} pressed.'); + debugDumpFocusTree(); + } + + @override + Widget build(BuildContext context) { + FocusOrder order; + if (widget.order is num) { + order = NumericFocusOrder((widget.order as num).toDouble()); + } else { + order = LexicalFocusOrder(widget.order.toString()); + } + + Color? overlayColor(Set states) { + if (states.contains(MaterialState.focused)) { + return Colors.red; + } + if (states.contains(MaterialState.hovered)) { + return Colors.blue; + } + return null; // defer to the default overlayColor + } + + Color? foregroundColor(Set states) { + if (states.contains(MaterialState.focused) || + states.contains(MaterialState.hovered)) { + return Colors.white; + } + return null; // defer to the default foregroundColor + } + + return FocusTraversalOrder( + order: order, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: OutlinedButton( + focusNode: focusNode, + autofocus: widget.autofocus, + style: ButtonStyle( + overlayColor: + MaterialStateProperty.resolveWith(overlayColor), + foregroundColor: + MaterialStateProperty.resolveWith(foregroundColor), + ), + onPressed: () => _handleOnPressed(), + child: Text(widget.name), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: FocusTraversalGroup( + policy: OrderedTraversalPolicy(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // A group that is ordered with a numerical order, from left to right. + FocusTraversalGroup( + policy: OrderedTraversalPolicy(), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: List.generate(3, (int index) { + return OrderedButton( + name: 'num: $index', + // TRY THIS: change this to "3 - index" and see how the order changes. + order: index, + ); + }), + ), + ), + // A group that is ordered with a lexical order, from right to left. + FocusTraversalGroup( + policy: OrderedTraversalPolicy(), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: List.generate(3, (int index) { + // Order as "C" "B", "A". + final String order = + String.fromCharCode('A'.codeUnitAt(0) + (2 - index)); + return OrderedButton( + name: 'String: $order', + order: order, + ); + }), + ), + ), + // A group that orders in widget order, regardless of what the order is set to. + FocusTraversalGroup( + // Note that because this is NOT an OrderedTraversalPolicy, the + // assigned order of these OrderedButtons is ignored, and they + // are traversed in widget order. TRY THIS: change this to + // "OrderedTraversalPolicy()" and see that it now follows the + // numeric order set on them instead of the widget order. + policy: WidgetOrderTraversalPolicy(), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: List.generate(3, (int index) { + return OrderedButton( + name: 'ignored num: ${3 - index}', + order: 3 - index, + ); + }), + ), + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart b/examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart new file mode 100644 index 0000000000..2b24e00254 --- /dev/null +++ b/examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for OrderedTraversalPolicy +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to assign a traversal order to a widget. In the +// example, the focus order goes from bottom right (the "One" button) to top +// left (the "Six" button). + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class DemoButton extends StatelessWidget { + const DemoButton({ + Key? key, + required this.name, + this.autofocus = false, + required this.order, + }) : super(key: key); + + final String name; + final bool autofocus; + final double order; + + void _handleOnPressed() { + print('Button $name pressed.'); + debugDumpFocusTree(); + } + + @override + Widget build(BuildContext context) { + return FocusTraversalOrder( + order: NumericFocusOrder(order), + child: TextButton( + autofocus: autofocus, + onPressed: () => _handleOnPressed(), + child: Text(name), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return FocusTraversalGroup( + policy: OrderedTraversalPolicy(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + DemoButton(name: 'Six', order: 6), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + DemoButton(name: 'Five', order: 5), + DemoButton(name: 'Four', order: 4), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + DemoButton(name: 'Three', order: 3), + DemoButton(name: 'Two', order: 2), + DemoButton(name: 'One', order: 1, autofocus: true), + ], + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/form/form.0.dart b/examples/api/lib/widgets/form/form.0.dart new file mode 100644 index 0000000000..1b3caf9993 --- /dev/null +++ b/examples/api/lib/widgets/form/form.0.dart @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Form +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [Form] with one [TextFormField] to enter an email +// address and an [ElevatedButton] to submit the form. A [GlobalKey] is used here +// to identify the [Form] and validate input. +// +// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/form.png) + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final GlobalKey _formKey = GlobalKey(); + + @override + Widget build(BuildContext context) { + return Form( + key: _formKey, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextFormField( + decoration: const InputDecoration( + hintText: 'Enter your email', + ), + validator: (String? value) { + if (value == null || value.isEmpty) { + return 'Please enter some text'; + } + return null; + }, + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 16.0), + child: ElevatedButton( + onPressed: () { + // Validate will return true if the form is valid, or false if + // the form is invalid. + if (_formKey.currentState!.validate()) { + // Process data. + } + }, + child: const Text('Submit'), + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/framework/build_owner.0.dart b/examples/api/lib/widgets/framework/build_owner.0.dart new file mode 100644 index 0000000000..b7d467dd49 --- /dev/null +++ b/examples/api/lib/widgets/framework/build_owner.0.dart @@ -0,0 +1,74 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for BuildOwner +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to build an off-screen widget tree used to measure +// the layout size of the rendered tree. For some use cases, the simpler +// [Offstage] widget may be a better alternative to this approach. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/rendering.dart'; +import 'package:flutter/widgets.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() { + WidgetsFlutterBinding.ensureInitialized(); + print(measureWidget(const SizedBox(width: 640, height: 480))); +} + +Size measureWidget(Widget widget) { + final PipelineOwner pipelineOwner = PipelineOwner(); + final MeasurementView rootView = pipelineOwner.rootNode = MeasurementView(); + final BuildOwner buildOwner = BuildOwner(focusManager: FocusManager()); + final RenderObjectToWidgetElement element = + RenderObjectToWidgetAdapter( + container: rootView, + debugShortDescription: '[root]', + child: widget, + ).attachToRenderTree(buildOwner); + try { + rootView.scheduleInitialLayout(); + pipelineOwner.flushLayout(); + return rootView.size; + } finally { + // Clean up. + element.update(RenderObjectToWidgetAdapter(container: rootView)); + buildOwner.finalizeTree(); + } +} + +class MeasurementView extends RenderBox + with RenderObjectWithChildMixin { + @override + void performLayout() { + assert(child != null); + child!.layout(const BoxConstraints(), parentUsesSize: true); + size = child!.size; + } + + @override + void debugAssertDoesMeetConstraints() => true; +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/framework/error_widget.0.dart b/examples/api/lib/widgets/framework/error_widget.0.dart new file mode 100644 index 0000000000..0ba5f18f68 --- /dev/null +++ b/examples/api/lib/widgets/framework/error_widget.0.dart @@ -0,0 +1,57 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ErrorWidget +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +void main() { + ErrorWidget.builder = (FlutterErrorDetails details) { + bool inDebug = false; + assert(() { + inDebug = true; + return true; + }()); + // In debug mode, use the normal error widget which shows + // the error message: + if (inDebug) { + return ErrorWidget(details.exception); + } + // In release builds, show a yellow-on-blue message instead: + return Container( + alignment: Alignment.center, + child: const Text( + 'Error!', + style: TextStyle(color: Colors.yellow), + textDirection: TextDirection.ltr, + ), + ); + }; + // Here we would normally runApp() the root widget, but to demonstrate + // the error handling we artificially fail: + return runApp(Builder( + builder: (BuildContext context) { + throw 'oh no, an error'; + }, + )); +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/gesture_detector/gesture_detector.0.dart b/examples/api/lib/widgets/gesture_detector/gesture_detector.0.dart new file mode 100644 index 0000000000..c2c75172ca --- /dev/null +++ b/examples/api/lib/widgets/gesture_detector/gesture_detector.0.dart @@ -0,0 +1,95 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for GestureDetector +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example contains a black light bulb wrapped in a [GestureDetector]. It +// turns the light bulb yellow when the "TURN LIGHT ON" button is tapped by +// setting the `_lights` field, and off again when "TURN LIGHT OFF" is tapped. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool _lightIsOn = false; + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Container( + alignment: FractionalOffset.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.all(8.0), + child: Icon( + Icons.lightbulb_outline, + color: _lightIsOn ? Colors.yellow.shade600 : Colors.black, + size: 60, + ), + ), + GestureDetector( + onTap: () { + setState(() { + // Toggle light when tapped. + _lightIsOn = !_lightIsOn; + }); + }, + child: Container( + color: Colors.yellow.shade600, + padding: const EdgeInsets.all(8), + // Change button text when light changes state. + child: Text(_lightIsOn ? 'TURN LIGHT OFF' : 'TURN LIGHT ON'), + ), + ), + ], + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/gesture_detector/gesture_detector.1.dart b/examples/api/lib/widgets/gesture_detector/gesture_detector.1.dart new file mode 100644 index 0000000000..06dd3e9f0c --- /dev/null +++ b/examples/api/lib/widgets/gesture_detector/gesture_detector.1.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for GestureDetector +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example uses a [Container] that wraps a [GestureDetector] widget which +// detects a tap. +// +// Since the [GestureDetector] does not have a child, it takes on the size of its +// parent, making the entire area of the surrounding [Container] clickable. When +// tapped, the [Container] turns yellow by setting the `_color` field. When +// tapped again, it goes back to white. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Color _color = Colors.white; + + @override + Widget build(BuildContext context) { + return Container( + color: _color, + height: 200.0, + width: 200.0, + child: GestureDetector( + onTap: () { + setState(() { + _color == Colors.yellow + ? _color = Colors.white + : _color = Colors.yellow; + }); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/heroes/hero.0.dart b/examples/api/lib/widgets/heroes/hero.0.dart new file mode 100644 index 0000000000..9e9ca4d386 --- /dev/null +++ b/examples/api/lib/widgets/heroes/hero.0.dart @@ -0,0 +1,108 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Hero +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [Hero] used within a [ListTile]. +// +// Tapping on the Hero-wrapped rectangle triggers a hero +// animation as a new [MaterialPageRoute] is pushed. Both the size +// and location of the rectangle animates. +// +// Both widgets use the same [Hero.tag]. +// +// The Hero widget uses the matching tags to identify and execute this +// animation. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + height: 20.0, + ), + ListTile( + leading: Hero( + tag: 'hero-rectangle', + child: _blueRectangle(const Size(50, 50)), + ), + onTap: () => _gotoDetailsPage(context), + title: + const Text('Tap on the icon to view hero animation transition.'), + ), + ], + ); + } + + Widget _blueRectangle(Size size) { + return Container( + width: size.width, + height: size.height, + color: Colors.blue, + ); + } + + void _gotoDetailsPage(BuildContext context) { + Navigator.of(context).push(MaterialPageRoute( + builder: (BuildContext context) => Scaffold( + appBar: AppBar( + title: const Text('second Page'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Hero( + tag: 'hero-rectangle', + child: _blueRectangle(const Size(200, 200)), + ), + ], + ), + ), + ), + )); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/image/image.error_builder.0.dart b/examples/api/lib/widgets/image/image.error_builder.0.dart new file mode 100644 index 0000000000..338d051b18 --- /dev/null +++ b/examples/api/lib/widgets/image/image.error_builder.0.dart @@ -0,0 +1,74 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Image.errorBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following sample uses [errorBuilder] to show a '😢' in place of the +// image that fails to load, and prints the error to the console. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return DecoratedBox( + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(), + borderRadius: BorderRadius.circular(20), + ), + child: Image.network( + 'https://example.does.not.exist/image.jpg', + errorBuilder: + (BuildContext context, Object exception, StackTrace? stackTrace) { + // Appropriate logging or analytics, e.g. + // myAnalytics.recordError( + // 'An error occurred loading "https://example.does.not.exist/image.jpg"', + // exception, + // stackTrace, + // ); + return const Text('😢'); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/image/image.frame_builder.0.dart b/examples/api/lib/widgets/image/image.frame_builder.0.dart new file mode 100644 index 0000000000..c9b65691f2 --- /dev/null +++ b/examples/api/lib/widgets/image/image.frame_builder.0.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Image.frameBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following sample demonstrates how to use this builder to implement an +// image that fades in once it's been loaded. +// +// This sample contains a limited subset of the functionality that the +// [FadeInImage] widget provides out of the box. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return DecoratedBox( + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(), + borderRadius: BorderRadius.circular(20), + ), + child: Image.network( + 'https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg', + frameBuilder: (BuildContext context, Widget child, int? frame, + bool wasSynchronouslyLoaded) { + if (wasSynchronouslyLoaded) { + return child; + } + return AnimatedOpacity( + child: child, + opacity: frame == null ? 0 : 1, + duration: const Duration(seconds: 1), + curve: Curves.easeOut, + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/image/image.loading_builder.0.dart b/examples/api/lib/widgets/image/image.loading_builder.0.dart new file mode 100644 index 0000000000..ef828b8e29 --- /dev/null +++ b/examples/api/lib/widgets/image/image.loading_builder.0.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Image.loadingBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following sample uses [loadingBuilder] to show a +// [CircularProgressIndicator] while an image loads over the network. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return DecoratedBox( + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(), + borderRadius: BorderRadius.circular(20), + ), + child: Image.network( + 'https://example.com/image.jpg', + loadingBuilder: (BuildContext context, Widget child, + ImageChunkEvent? loadingProgress) { + if (loadingProgress == null) { + return child; + } + return Center( + child: CircularProgressIndicator( + value: loadingProgress.expectedTotalBytes != null + ? loadingProgress.cumulativeBytesLoaded / + loadingProgress.expectedTotalBytes! + : null, + ), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/implicit_animations/animated_align.0.dart b/examples/api/lib/widgets/implicit_animations/animated_align.0.dart new file mode 100644 index 0000000000..12f5527321 --- /dev/null +++ b/examples/api/lib/widgets/implicit_animations/animated_align.0.dart @@ -0,0 +1,85 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedAlign +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [AnimatedAlign] widget, using a [curve] of +// [Curves.fastOutSlowIn]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool selected = false; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () { + setState(() { + selected = !selected; + }); + }, + child: Center( + child: Container( + width: 250.0, + height: 250.0, + color: Colors.red, + child: AnimatedAlign( + alignment: selected ? Alignment.topRight : Alignment.bottomLeft, + duration: const Duration(seconds: 1), + curve: Curves.fastOutSlowIn, + child: const FlutterLogo(size: 50.0), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/implicit_animations/animated_container.0.dart b/examples/api/lib/widgets/implicit_animations/animated_container.0.dart new file mode 100644 index 0000000000..a089ee1dfb --- /dev/null +++ b/examples/api/lib/widgets/implicit_animations/animated_container.0.dart @@ -0,0 +1,85 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedContainer +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example (depicted above) transitions an AnimatedContainer +// between two states. It adjusts the `height`, `width`, `color`, and +// [alignment] properties when tapped. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool selected = false; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () { + setState(() { + selected = !selected; + }); + }, + child: Center( + child: AnimatedContainer( + width: selected ? 200.0 : 100.0, + height: selected ? 100.0 : 200.0, + color: selected ? Colors.red : Colors.blue, + alignment: + selected ? Alignment.center : AlignmentDirectional.topCenter, + duration: const Duration(seconds: 2), + curve: Curves.fastOutSlowIn, + child: const FlutterLogo(size: 75), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/implicit_animations/animated_padding.0.dart b/examples/api/lib/widgets/implicit_animations/animated_padding.0.dart new file mode 100644 index 0000000000..e85e667305 --- /dev/null +++ b/examples/api/lib/widgets/implicit_animations/animated_padding.0.dart @@ -0,0 +1,91 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedPadding +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [AnimatedPadding] widget, using a [curve] of +// [Curves.easeInOut]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + double padValue = 0.0; + void _updatePadding(double value) { + setState(() { + padValue = value; + }); + } + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + AnimatedPadding( + padding: EdgeInsets.all(padValue), + duration: const Duration(seconds: 2), + curve: Curves.easeInOut, + child: Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.height / 5, + color: Colors.blue, + ), + ), + Text('Padding: $padValue'), + ElevatedButton( + child: const Text('Change padding'), + onPressed: () { + _updatePadding(padValue == 0.0 ? 100.0 : 0.0); + }), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/implicit_animations/animated_positioned.0.dart b/examples/api/lib/widgets/implicit_animations/animated_positioned.0.dart new file mode 100644 index 0000000000..087e5b5f8e --- /dev/null +++ b/examples/api/lib/widgets/implicit_animations/animated_positioned.0.dart @@ -0,0 +1,94 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedPositioned +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example transitions an AnimatedPositioned +// between two states. It adjusts the `height`, `width`, and +// [Positioned] properties when tapped. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool selected = false; + + @override + Widget build(BuildContext context) { + return SizedBox( + width: 200, + height: 350, + child: Stack( + children: [ + AnimatedPositioned( + width: selected ? 200.0 : 50.0, + height: selected ? 50.0 : 200.0, + top: selected ? 50.0 : 150.0, + duration: const Duration(seconds: 2), + curve: Curves.fastOutSlowIn, + child: GestureDetector( + onTap: () { + setState(() { + selected = !selected; + }); + }, + child: Container( + color: Colors.blue, + child: const Center(child: Text('Tap me')), + ), + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/implicit_animations/animated_slide.0.dart b/examples/api/lib/widgets/implicit_animations/animated_slide.0.dart new file mode 100644 index 0000000000..f4242f77b0 --- /dev/null +++ b/examples/api/lib/widgets/implicit_animations/animated_slide.0.dart @@ -0,0 +1,95 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedSlide +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This code defines a widget that uses [AnimatedSlide] to translate a [FlutterLogo] +// up or down by the amount of it's height with each press of the corresponding button. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Offset offset = Offset.zero; + + void _slideUp() { + setState(() => offset -= const Offset(0, 1)); + } + + void _slideDown() { + setState(() => offset += const Offset(0, 1)); + } + + @override + Widget build(BuildContext context) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + ElevatedButton( + child: const Text('Slide up'), + onPressed: _slideUp, + ), + ElevatedButton( + child: const Text('Slide down'), + onPressed: _slideDown, + ), + Padding( + padding: const EdgeInsets.all(50), + child: AnimatedSlide( + offset: offset, + duration: const Duration(milliseconds: 500), + curve: Curves.easeInOut, + child: const FlutterLogo(), + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/implicit_animations/sliver_animated_opacity.0.dart b/examples/api/lib/widgets/implicit_animations/sliver_animated_opacity.0.dart new file mode 100644 index 0000000000..d601f5c642 --- /dev/null +++ b/examples/api/lib/widgets/implicit_animations/sliver_animated_opacity.0.dart @@ -0,0 +1,94 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverAnimatedOpacity +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Creates a [CustomScrollView] with a [SliverFixedExtentList] and a +// [FloatingActionButton]. Pressing the button animates the lists' opacity. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class _MyStatefulWidgetState extends State + with SingleTickerProviderStateMixin { + bool _visible = true; + + @override + Widget build(BuildContext context) { + return CustomScrollView(slivers: [ + SliverAnimatedOpacity( + opacity: _visible ? 1.0 : 0.0, + duration: const Duration(milliseconds: 500), + sliver: SliverFixedExtentList( + itemExtent: 100.0, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Container( + color: index.isEven ? Colors.indigo[200] : Colors.orange[200], + ); + }, + childCount: 5, + ), + ), + ), + SliverToBoxAdapter( + child: FloatingActionButton( + onPressed: () { + setState(() { + _visible = !_visible; + }); + }, + tooltip: 'Toggle opacity', + child: const Icon(Icons.flip), + )), + ]); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/inherited_notifier/inherited_notifier.0.dart b/examples/api/lib/widgets/inherited_notifier/inherited_notifier.0.dart new file mode 100644 index 0000000000..145634ddd4 --- /dev/null +++ b/examples/api/lib/widgets/inherited_notifier/inherited_notifier.0.dart @@ -0,0 +1,148 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InheritedNotifier +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows three spinning squares that use the value of the notifier +// on an ancestor [InheritedNotifier] (`SpinModel`) to give them their +// rotation. The [InheritedNotifier] doesn't need to know about the children, +// and the `notifier` argument doesn't need to be an animation controller, it +// can be anything that implements [Listenable] (like a [ChangeNotifier]). +// +// The `SpinModel` class could just as easily listen to another object (say, a +// separate object that keeps the value of an input or data model value) that +// is a [Listenable], and get the value from that. The descendants also don't +// need to have an instance of the [InheritedNotifier] in order to use it, they +// just need to know that there is one in their ancestry. This can help with +// decoupling widgets from their models. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//******************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-dartImports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'dart:math' as math; + +//* ▲▲▲▲▲▲▲▲ code-dartImports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class SpinModel extends InheritedNotifier { + const SpinModel({ + Key? key, + AnimationController? notifier, + required Widget child, + }) : super(key: key, notifier: notifier, child: child); + + static double of(BuildContext context) { + return context + .dependOnInheritedWidgetOfExactType()! + .notifier! + .value; + } +} + +class Spinner extends StatelessWidget { + const Spinner({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Transform.rotate( + angle: SpinModel.of(context) * 2.0 * math.pi, + child: Container( + width: 100, + height: 100, + color: Colors.green, + child: const Center( + child: Text('Whee!'), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late AnimationController _controller; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + duration: const Duration(seconds: 10), + vsync: this, + )..repeat(); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SpinModel( + notifier: _controller, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: const [ + Spinner(), + Spinner(), + Spinner(), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/inherited_theme/inherited_theme.0.dart b/examples/api/lib/widgets/inherited_theme/inherited_theme.0.dart new file mode 100644 index 0000000000..174902f8cf --- /dev/null +++ b/examples/api/lib/widgets/inherited_theme/inherited_theme.0.dart @@ -0,0 +1,105 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InheritedTheme +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example demonstrates how `InheritedTheme.capture()` can be used +// to wrap the contents of a new route with the inherited themes that +// are present when the route was built - but are not present when route +// is actually shown. +// +// If the same code is run without `InheritedTheme.capture(), the +// new route's Text widget will inherit the "something must be wrong" +// fallback text style, rather than the default text style defined in MyApp. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() { + runApp(const MyApp()); +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class MyAppBody extends StatelessWidget { + const MyAppBody({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final NavigatorState navigator = Navigator.of(context); + // This InheritedTheme.capture() saves references to themes that are + // found above the context provided to this widget's build method + // excluding themes are found above the navigator. Those themes do + // not have to be captured, because they will already be visible from + // the new route pushed onto said navigator. + // Themes are captured outside of the route's builder because when the + // builder executes, the context may not be valid anymore. + final CapturedThemes themes = + InheritedTheme.capture(from: context, to: navigator.context); + return GestureDetector( + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext _) { + // Wrap the actual child of the route in the previously + // captured themes. + return themes.wrap( + Container( + alignment: Alignment.center, + color: Colors.white, + child: const Text('Hello World'), + ), + ); + }, + ), + ); + }, + child: const Center(child: Text('Tap Here')), + ); + } +} + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const MaterialApp( + home: Scaffold( + // Override the DefaultTextStyle defined by the Scaffold. + // Descendant widgets will inherit this big blue text style. + body: DefaultTextStyle( + style: TextStyle(fontSize: 48, color: Colors.blue), + child: MyAppBody(), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/interactive_viewer/interactive_viewer.0.dart b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.0.dart new file mode 100644 index 0000000000..06261a64e6 --- /dev/null +++ b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.0.dart @@ -0,0 +1,73 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InteractiveViewer +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a simple Container that can be panned and zoomed. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Center( + child: InteractiveViewer( + boundaryMargin: const EdgeInsets.all(20.0), + minScale: 0.1, + maxScale: 1.6, + child: Container( + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [Colors.orange, Colors.red], + stops: [0.0, 1.0], + ), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/interactive_viewer/interactive_viewer.builder.0.dart b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.builder.0.dart new file mode 100644 index 0000000000..27ee0676ea --- /dev/null +++ b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.builder.0.dart @@ -0,0 +1,208 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InteractiveViewer.builder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to use builder to create a [Table] whose cell +// contents are only built when they are visible. Built and remove cells are +// logged in the console for illustration. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:vector_math/vector_math_64.dart' show Quad, Vector3; + +void main() => runApp(const IVBuilderExampleApp()); + +class IVBuilderExampleApp extends StatelessWidget { + const IVBuilderExampleApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('IV Builder Example'), + ), + body: _IVBuilderExample(), + ), + ); + } +} + +class _IVBuilderExample extends StatefulWidget { + @override + _IVBuilderExampleState createState() => _IVBuilderExampleState(); +} + +class _IVBuilderExampleState extends State<_IVBuilderExample> { + final TransformationController _transformationController = + TransformationController(); + + static const double _cellWidth = 200.0; + static const double _cellHeight = 26.0; + + // Returns true iff the given cell is currently visible. Caches viewport + // calculations. + late Quad _cachedViewport; + late int _firstVisibleRow; + late int _firstVisibleColumn; + late int _lastVisibleRow; + late int _lastVisibleColumn; + bool _isCellVisible(int row, int column, Quad viewport) { + if (viewport != _cachedViewport) { + final Rect aabb = _axisAlignedBoundingBox(viewport); + _cachedViewport = viewport; + _firstVisibleRow = (aabb.top / _cellHeight).floor(); + _firstVisibleColumn = (aabb.left / _cellWidth).floor(); + _lastVisibleRow = (aabb.bottom / _cellHeight).floor(); + _lastVisibleColumn = (aabb.right / _cellWidth).floor(); + } + return row >= _firstVisibleRow && + row <= _lastVisibleRow && + column >= _firstVisibleColumn && + column <= _lastVisibleColumn; + } + + // Returns the axis aligned bounding box for the given Quad, which might not + // be axis aligned. + Rect _axisAlignedBoundingBox(Quad quad) { + double? xMin; + double? xMax; + double? yMin; + double? yMax; + for (final Vector3 point in [ + quad.point0, + quad.point1, + quad.point2, + quad.point3 + ]) { + if (xMin == null || point.x < xMin) { + xMin = point.x; + } + if (xMax == null || point.x > xMax) { + xMax = point.x; + } + if (yMin == null || point.y < yMin) { + yMin = point.y; + } + if (yMax == null || point.y > yMax) { + yMax = point.y; + } + } + return Rect.fromLTRB(xMin!, yMin!, xMax!, yMax!); + } + + void _onChangeTransformation() { + setState(() {}); + } + + @override + void initState() { + super.initState(); + _transformationController.addListener(_onChangeTransformation); + } + + @override + void dispose() { + _transformationController.removeListener(_onChangeTransformation); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Center( + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return InteractiveViewer.builder( + alignPanAxis: true, + scaleEnabled: false, + transformationController: _transformationController, + builder: (BuildContext context, Quad viewport) { + // A simple extension of Table that builds cells. + return _TableBuilder( + rowCount: 60, + columnCount: 6, + cellWidth: _cellWidth, + builder: (BuildContext context, int row, int column) { + if (!_isCellVisible(row, column, viewport)) { + print('removing cell ($row, $column)'); + return Container(height: _cellHeight); + } + print('building cell ($row, $column)'); + return Container( + height: _cellHeight, + color: row % 2 + column % 2 == 1 + ? Colors.white + : Colors.grey.withOpacity(0.1), + child: Align( + alignment: Alignment.centerLeft, + child: Text('$row x $column'), + ), + ); + }); + }, + ); + }, + ), + ); + } +} + +typedef _CellBuilder = Widget Function( + BuildContext context, int row, int column); + +class _TableBuilder extends StatelessWidget { + const _TableBuilder({ + required this.rowCount, + required this.columnCount, + required this.cellWidth, + required this.builder, + }) : assert(rowCount > 0), + assert(columnCount > 0); + + final int rowCount; + final int columnCount; + final double cellWidth; + final _CellBuilder builder; + + @override + Widget build(BuildContext context) { + return Table( + // ignore: prefer_const_literals_to_create_immutables + columnWidths: { + for (int column = 0; column < columnCount; column++) + column: FixedColumnWidth(cellWidth), + }, + // ignore: prefer_const_literals_to_create_immutables + children: [ + for (int row = 0; row < rowCount; row++) + // ignore: prefer_const_constructors + TableRow( + // ignore: prefer_const_literals_to_create_immutables + children: [ + for (int column = 0; column < columnCount; column++) + builder(context, row, column), + ], + ), + ], + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/widgets/interactive_viewer/interactive_viewer.constrained.0.dart b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.constrained.0.dart new file mode 100644 index 0000000000..eb8e0027df --- /dev/null +++ b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.constrained.0.dart @@ -0,0 +1,91 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InteractiveViewer.constrained +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how to create a pannable table. Because the table is +// larger than the entire screen, setting `constrained` to false is necessary +// to allow it to be drawn to its full size. The parts of the table that +// exceed the screen size can then be panned into view. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + const int _rowCount = 48; + const int _columnCount = 6; + + return InteractiveViewer( + alignPanAxis: true, + constrained: false, + scaleEnabled: false, + child: Table( + columnWidths: { + for (int column = 0; column < _columnCount; column += 1) + column: const FixedColumnWidth(200.0), + }, + children: [ + for (int row = 0; row < _rowCount; row += 1) + TableRow( + children: [ + for (int column = 0; column < _columnCount; column += 1) + Container( + height: 26, + color: row % 2 + column % 2 == 1 + ? Colors.white + : Colors.grey.withOpacity(0.1), + child: Align( + alignment: Alignment.centerLeft, + child: Text('$row x $column'), + ), + ), + ], + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/interactive_viewer/interactive_viewer.transformation_controller.0.dart b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.transformation_controller.0.dart new file mode 100644 index 0000000000..9f9a18dac4 --- /dev/null +++ b/examples/api/lib/widgets/interactive_viewer/interactive_viewer.transformation_controller.0.dart @@ -0,0 +1,151 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for InteractiveViewer.transformationController +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows how transformationController can be used to animate the +// transformation back to its starting position. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final TransformationController _transformationController = + TransformationController(); + Animation? _animationReset; + late final AnimationController _controllerReset; + + void _onAnimateReset() { + _transformationController.value = _animationReset!.value; + if (!_controllerReset.isAnimating) { + _animationReset!.removeListener(_onAnimateReset); + _animationReset = null; + _controllerReset.reset(); + } + } + + void _animateResetInitialize() { + _controllerReset.reset(); + _animationReset = Matrix4Tween( + begin: _transformationController.value, + end: Matrix4.identity(), + ).animate(_controllerReset); + _animationReset!.addListener(_onAnimateReset); + _controllerReset.forward(); + } + +// Stop a running reset to home transform animation. + void _animateResetStop() { + _controllerReset.stop(); + _animationReset?.removeListener(_onAnimateReset); + _animationReset = null; + _controllerReset.reset(); + } + + void _onInteractionStart(ScaleStartDetails details) { + // If the user tries to cause a transformation while the reset animation is + // running, cancel the reset animation. + if (_controllerReset.status == AnimationStatus.forward) { + _animateResetStop(); + } + } + + @override + void initState() { + super.initState(); + _controllerReset = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 400), + ); + } + + @override + void dispose() { + _controllerReset.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Theme.of(context).colorScheme.primary, + appBar: AppBar( + automaticallyImplyLeading: false, + title: const Text('Controller demo'), + ), + body: Center( + child: InteractiveViewer( + boundaryMargin: const EdgeInsets.all(double.infinity), + transformationController: _transformationController, + minScale: 0.1, + maxScale: 1.0, + onInteractionStart: _onInteractionStart, + child: Container( + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [Colors.orange, Colors.red], + stops: [0.0, 1.0], + ), + ), + ), + ), + ), + persistentFooterButtons: [ + IconButton( + onPressed: _animateResetInitialize, + tooltip: 'Reset', + color: Theme.of(context).colorScheme.surface, + icon: const Icon(Icons.replay), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/layout_builder/layout_builder.0.dart b/examples/api/lib/widgets/layout_builder/layout_builder.0.dart new file mode 100644 index 0000000000..03cceff7d1 --- /dev/null +++ b/examples/api/lib/widgets/layout_builder/layout_builder.0.dart @@ -0,0 +1,96 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for LayoutBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example uses a [LayoutBuilder] to build a different widget depending on the available width. Resize the +// DartPad window to see [LayoutBuilder] in action! + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('LayoutBuilder Example')), + body: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + if (constraints.maxWidth > 600) { + return _buildWideContainers(); + } else { + return _buildNormalContainer(); + } + }, + ), + ); + } + + Widget _buildNormalContainer() { + return Center( + child: Container( + height: 100.0, + width: 100.0, + color: Colors.red, + ), + ); + } + + Widget _buildWideContainers() { + return Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Container( + height: 100.0, + width: 100.0, + color: Colors.red, + ), + Container( + height: 100.0, + width: 100.0, + color: Colors.yellow, + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/media_query/media_query_data.system_gesture_insets.0.dart b/examples/api/lib/widgets/media_query/media_query_data.system_gesture_insets.0.dart new file mode 100644 index 0000000000..fec9c60b63 --- /dev/null +++ b/examples/api/lib/widgets/media_query/media_query_data.system_gesture_insets.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for MediaQueryData.systemGestureInsets +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// For apps that might be deployed on Android Q devices with full gesture +// navigation enabled, use [systemGestureInsets] with [Padding] +// to avoid having the left and right edges of the [Slider] from appearing +// within the area reserved for system gesture navigation. +// +// By default, [Slider]s expand to fill the available width. So, we pad the +// left and right sides. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + double _currentValue = 0.2; + + @override + Widget build(BuildContext context) { + final EdgeInsets systemGestureInsets = + MediaQuery.of(context).systemGestureInsets; + return Scaffold( + appBar: + AppBar(title: const Text('Pad Slider to avoid systemGestureInsets')), + body: Padding( + padding: EdgeInsets.only( + // only left and right padding are needed here + left: systemGestureInsets.left, + right: systemGestureInsets.right, + ), + child: Slider( + value: _currentValue, + onChanged: (double newValue) { + setState(() { + _currentValue = newValue; + }); + }, + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/navigator/navigator.0.dart b/examples/api/lib/widgets/navigator/navigator.0.dart new file mode 100644 index 0000000000..9e8af243ea --- /dev/null +++ b/examples/api/lib/widgets/navigator/navigator.0.dart @@ -0,0 +1,168 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Navigator +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example demonstrates how a nested [Navigator] can be used to +// present a standalone user registration journey. +// +// Even though this example uses two [Navigator]s to demonstrate nested +// [Navigator]s, a similar result is possible using only a single [Navigator]. +// +// Run this example with `flutter run --route=/signup` to start it with +// the signup flow instead of on the home page. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() => runApp(const MyApp()); + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Code Sample for Navigator', + // MaterialApp contains our top-level Navigator + initialRoute: '/', + routes: { + '/': (BuildContext context) => const HomePage(), + '/signup': (BuildContext context) => const SignUpPage(), + }, + ); + } +} + +class HomePage extends StatelessWidget { + const HomePage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: Theme.of(context).textTheme.headline4!, + child: Container( + color: Colors.white, + alignment: Alignment.center, + child: const Text('Home Page'), + ), + ); + } +} + +class CollectPersonalInfoPage extends StatelessWidget { + const CollectPersonalInfoPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: Theme.of(context).textTheme.headline4!, + child: GestureDetector( + onTap: () { + // This moves from the personal info page to the credentials page, + // replacing this page with that one. + Navigator.of(context) + .pushReplacementNamed('signup/choose_credentials'); + }, + child: Container( + color: Colors.lightBlue, + alignment: Alignment.center, + child: const Text('Collect Personal Info Page'), + ), + ), + ); + } +} + +class ChooseCredentialsPage extends StatelessWidget { + const ChooseCredentialsPage({ + Key? key, + required this.onSignupComplete, + }) : super(key: key); + + final VoidCallback onSignupComplete; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: onSignupComplete, + child: DefaultTextStyle( + style: Theme.of(context).textTheme.headline4!, + child: Container( + color: Colors.pinkAccent, + alignment: Alignment.center, + child: const Text('Choose Credentials Page'), + ), + ), + ); + } +} + +class SignUpPage extends StatelessWidget { + const SignUpPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + // SignUpPage builds its own Navigator which ends up being a nested + // Navigator in our app. + return Navigator( + initialRoute: 'signup/personal_info', + onGenerateRoute: (RouteSettings settings) { + WidgetBuilder builder; + switch (settings.name) { + case 'signup/personal_info': + // Assume CollectPersonalInfoPage collects personal info and then + // navigates to 'signup/choose_credentials'. + builder = (BuildContext context) => const CollectPersonalInfoPage(); + break; + case 'signup/choose_credentials': + // Assume ChooseCredentialsPage collects new credentials and then + // invokes 'onSignupComplete()'. + builder = (BuildContext _) => ChooseCredentialsPage( + onSignupComplete: () { + // Referencing Navigator.of(context) from here refers to the + // top level Navigator because SignUpPage is above the + // nested Navigator that it created. Therefore, this pop() + // will pop the entire "sign up" journey and return to the + // "/" route, AKA HomePage. + Navigator.of(context).pop(); + }, + ); + break; + default: + throw Exception('Invalid route: ${settings.name}'); + } + return MaterialPageRoute(builder: builder, settings: settings); + }, + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/navigator/navigator.restorable_push.0.dart b/examples/api/lib/widgets/navigator/navigator.restorable_push.0.dart new file mode 100644 index 0000000000..573e275e03 --- /dev/null +++ b/examples/api/lib/widgets/navigator/navigator.restorable_push.0.dart @@ -0,0 +1,75 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Navigator.restorablePush +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage is as follows: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + static Route _myRouteBuilder(BuildContext context, Object? arguments) { + return MaterialPageRoute( + builder: (BuildContext context) => const MyStatefulWidget(), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => Navigator.restorablePush(context, _myRouteBuilder), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/navigator/navigator.restorable_push_and_remove_until.0.dart b/examples/api/lib/widgets/navigator/navigator.restorable_push_and_remove_until.0.dart new file mode 100644 index 0000000000..a8575bffe9 --- /dev/null +++ b/examples/api/lib/widgets/navigator/navigator.restorable_push_and_remove_until.0.dart @@ -0,0 +1,79 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Navigator.restorablePushAndRemoveUntil +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage is as follows: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + static Route _myRouteBuilder(BuildContext context, Object? arguments) { + return MaterialPageRoute( + builder: (BuildContext context) => const MyStatefulWidget(), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => Navigator.restorablePushAndRemoveUntil( + context, + _myRouteBuilder, + ModalRoute.withName('/'), + ), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/navigator/navigator.restorable_push_replacement.0.dart b/examples/api/lib/widgets/navigator/navigator.restorable_push_replacement.0.dart new file mode 100644 index 0000000000..99e120421d --- /dev/null +++ b/examples/api/lib/widgets/navigator/navigator.restorable_push_replacement.0.dart @@ -0,0 +1,76 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Navigator.restorablePushReplacement +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage is as follows: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + static Route _myRouteBuilder(BuildContext context, Object? arguments) { + return MaterialPageRoute( + builder: (BuildContext context) => const MyStatefulWidget(), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => + Navigator.restorablePushReplacement(context, _myRouteBuilder), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/navigator/navigator_state.restorable_push.0.dart b/examples/api/lib/widgets/navigator/navigator_state.restorable_push.0.dart new file mode 100644 index 0000000000..c5de28ba77 --- /dev/null +++ b/examples/api/lib/widgets/navigator/navigator_state.restorable_push.0.dart @@ -0,0 +1,75 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NavigatorState.restorablePush +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage is as follows: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + static Route _myRouteBuilder(BuildContext context, Object? arguments) { + return MaterialPageRoute( + builder: (BuildContext context) => const MyStatefulWidget(), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => Navigator.of(context).restorablePush(_myRouteBuilder), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart b/examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart new file mode 100644 index 0000000000..f2e6b9267f --- /dev/null +++ b/examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NavigatorState.restorablePushAndRemoveUntil +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage is as follows: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + static Route _myRouteBuilder(BuildContext context, Object? arguments) { + return MaterialPageRoute( + builder: (BuildContext context) => const MyStatefulWidget(), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => Navigator.of(context).restorablePushAndRemoveUntil( + _myRouteBuilder, + ModalRoute.withName('/'), + ), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/navigator/navigator_state.restorable_push_replacement.0.dart b/examples/api/lib/widgets/navigator/navigator_state.restorable_push_replacement.0.dart new file mode 100644 index 0000000000..9d1bdf524e --- /dev/null +++ b/examples/api/lib/widgets/navigator/navigator_state.restorable_push_replacement.0.dart @@ -0,0 +1,77 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NavigatorState.restorablePushReplacement +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Typical usage is as follows: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + static Route _myRouteBuilder(BuildContext context, Object? arguments) { + return MaterialPageRoute( + builder: (BuildContext context) => const MyStatefulWidget(), + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Sample Code'), + ), + floatingActionButton: FloatingActionButton( + onPressed: () => Navigator.of(context).restorablePushReplacement( + _myRouteBuilder, + ), + tooltip: 'Increment Counter', + child: const Icon(Icons.add), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/navigator/restorable_route_future.0.dart b/examples/api/lib/widgets/navigator/restorable_route_future.0.dart new file mode 100644 index 0000000000..7d952eda15 --- /dev/null +++ b/examples/api/lib/widgets/navigator/restorable_route_future.0.dart @@ -0,0 +1,195 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RestorableRouteFuture +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example uses a [RestorableRouteFuture] in the `_MyHomeState` to push a +// new `MyCounter` route and to retrieve its return value. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() => runApp(const MyApp()); + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + restorationScopeId: 'app', + home: Scaffold( + appBar: AppBar(title: const Text('RestorableRouteFuture Example')), + body: const MyHome(), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class MyHome extends StatefulWidget { + const MyHome({Key? key}) : super(key: key); + + @override + State createState() => _MyHomeState(); +} + +class _MyHomeState extends State with RestorationMixin { + final RestorableInt _lastCount = RestorableInt(0); + late RestorableRouteFuture _counterRoute; + + @override + String get restorationId => 'home'; + + @override + void initState() { + super.initState(); + _counterRoute = RestorableRouteFuture( + onPresent: (NavigatorState navigator, Object? arguments) { + // Defines what route should be shown (and how it should be added + // to the navigator) when `RestorableRouteFuture.present` is called. + return navigator.restorablePush( + _counterRouteBuilder, + arguments: arguments, + ); + }, onComplete: (int count) { + // Defines what should happen with the return value when the route + // completes. + setState(() { + _lastCount.value = count; + }); + }); + } + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + // Register the `RestorableRouteFuture` with the state restoration framework. + registerForRestoration(_counterRoute, 'route'); + registerForRestoration(_lastCount, 'count'); + } + + @override + void dispose() { + super.dispose(); + _lastCount.dispose(); + _counterRoute.dispose(); + } + + // A static `RestorableRouteBuilder` that can re-create the route during + // state restoration. + static Route _counterRouteBuilder( + BuildContext context, Object? arguments) { + return MaterialPageRoute( + builder: (BuildContext context) => MyCounter( + title: arguments!.toString(), + ), + ); + } + + @override + Widget build(BuildContext context) { + return Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text('Last count: ${_lastCount.value}'), + ElevatedButton( + onPressed: () { + // Show the route defined by the `RestorableRouteFuture`. + _counterRoute.present('Awesome Counter'); + }, + child: const Text('Open Counter'), + ), + ], + ), + ); + } +} + +// Widget for the route pushed by the `RestorableRouteFuture`. +class MyCounter extends StatefulWidget { + const MyCounter({Key? key, required this.title}) : super(key: key); + + final String title; + + @override + State createState() => _MyCounterState(); +} + +class _MyCounterState extends State with RestorationMixin { + final RestorableInt _count = RestorableInt(0); + + @override + String get restorationId => 'counter'; + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + registerForRestoration(_count, 'count'); + } + + @override + void dispose() { + super.dispose(); + _count.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + leading: BackButton( + onPressed: () { + // Return the current count of the counter from this route. + Navigator.of(context).pop(_count.value); + }, + ), + ), + body: Center( + child: Text('Count: ${_count.value}'), + ), + floatingActionButton: FloatingActionButton( + child: const Icon(Icons.add), + onPressed: () { + setState(() { + _count.value++; + }); + }, + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/navigator/transition_delegate.0.dart b/examples/api/lib/widgets/navigator/transition_delegate.0.dart new file mode 100644 index 0000000000..40bb9a5b12 --- /dev/null +++ b/examples/api/lib/widgets/navigator/transition_delegate.0.dart @@ -0,0 +1,69 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TransitionDelegate +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following example demonstrates how to implement a subclass that always +// removes or adds routes without animated transitions and puts the removed +// routes at the top of the list. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/widgets.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class NoAnimationTransitionDelegate extends TransitionDelegate { + @override + Iterable resolve({ + required List newPageRouteHistory, + required Map + locationToExitingPageRoute, + required Map> + pageRouteToPagelessRoutes, + }) { + final List results = []; + + for (final RouteTransitionRecord pageRoute in newPageRouteHistory) { + if (pageRoute.isWaitingForEnteringDecision) { + pageRoute.markForAdd(); + } + results.add(pageRoute); + } + for (final RouteTransitionRecord exitingPageRoute + in locationToExitingPageRoute.values) { + if (exitingPageRoute.isWaitingForExitingDecision) { + exitingPageRoute.markForRemove(); + final List? pagelessRoutes = + pageRouteToPagelessRoutes[exitingPageRoute]; + if (pagelessRoutes != null) { + for (final RouteTransitionRecord pagelessRoute in pagelessRoutes) { + pagelessRoute.markForRemove(); + } + } + } + results.add(exitingPageRoute); + } + return results; + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.0.dart b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.0.dart new file mode 100644 index 0000000000..ce4ae4cc1a --- /dev/null +++ b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.0.dart @@ -0,0 +1,166 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NestedScrollView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [NestedScrollView] whose header is the combination of a +// [TabBar] in a [SliverAppBar] and whose body is a [TabBarView]. It uses a +// [SliverOverlapAbsorber]/[SliverOverlapInjector] pair to make the inner lists +// align correctly, and it uses [SafeArea] to avoid any horizontal disturbances +// (e.g. the "notch" on iOS when the phone is horizontal). In addition, +// [PageStorageKey]s are used to remember the scroll position of each tab's +// list. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + final List _tabs = ['Tab 1', 'Tab 2']; + return DefaultTabController( + length: _tabs.length, // This is the number of tabs. + child: Scaffold( + body: NestedScrollView( + headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { + // These are the slivers that show up in the "outer" scroll view. + return [ + SliverOverlapAbsorber( + // This widget takes the overlapping behavior of the SliverAppBar, + // and redirects it to the SliverOverlapInjector below. If it is + // missing, then it is possible for the nested "inner" scroll view + // below to end up under the SliverAppBar even when the inner + // scroll view thinks it has not been scrolled. + // This is not necessary if the "headerSliverBuilder" only builds + // widgets that do not overlap the next sliver. + handle: + NestedScrollView.sliverOverlapAbsorberHandleFor(context), + sliver: SliverAppBar( + title: + const Text('Books'), // This is the title in the app bar. + pinned: true, + expandedHeight: 150.0, + // The "forceElevated" property causes the SliverAppBar to show + // a shadow. The "innerBoxIsScrolled" parameter is true when the + // inner scroll view is scrolled beyond its "zero" point, i.e. + // when it appears to be scrolled below the SliverAppBar. + // Without this, there are cases where the shadow would appear + // or not appear inappropriately, because the SliverAppBar is + // not actually aware of the precise position of the inner + // scroll views. + forceElevated: innerBoxIsScrolled, + bottom: TabBar( + // These are the widgets to put in each tab in the tab bar. + tabs: _tabs.map((String name) => Tab(text: name)).toList(), + ), + ), + ), + ]; + }, + body: TabBarView( + // These are the contents of the tab views, below the tabs. + children: _tabs.map((String name) { + return SafeArea( + top: false, + bottom: false, + child: Builder( + // This Builder is needed to provide a BuildContext that is + // "inside" the NestedScrollView, so that + // sliverOverlapAbsorberHandleFor() can find the + // NestedScrollView. + builder: (BuildContext context) { + return CustomScrollView( + // The "controller" and "primary" members should be left + // unset, so that the NestedScrollView can control this + // inner scroll view. + // If the "controller" property is set, then this scroll + // view will not be associated with the NestedScrollView. + // The PageStorageKey should be unique to this ScrollView; + // it allows the list to remember its scroll position when + // the tab view is not on the screen. + key: PageStorageKey(name), + slivers: [ + SliverOverlapInjector( + // This is the flip side of the SliverOverlapAbsorber + // above. + handle: + NestedScrollView.sliverOverlapAbsorberHandleFor( + context), + ), + SliverPadding( + padding: const EdgeInsets.all(8.0), + // In this example, the inner scroll view has + // fixed-height list items, hence the use of + // SliverFixedExtentList. However, one could use any + // sliver widget here, e.g. SliverList or SliverGrid. + sliver: SliverFixedExtentList( + // The items in this example are fixed to 48 pixels + // high. This matches the Material Design spec for + // ListTile widgets. + itemExtent: 48.0, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + // This builder is called for each child. + // In this example, we just number each list item. + return ListTile( + title: Text('Item $index'), + ); + }, + // The childCount of the SliverChildBuilderDelegate + // specifies how many children this inner list + // has. In this example, each tab has a list of + // exactly 30 items, but this is arbitrary. + childCount: 30, + ), + ), + ), + ], + ); + }, + ), + ); + }).toList(), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.1.dart b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.1.dart new file mode 100644 index 0000000000..8e982d1dce --- /dev/null +++ b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.1.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NestedScrollView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This simple example shows a [NestedScrollView] whose header contains a +// floating [SliverAppBar]. By using the [floatHeaderSlivers] property, the +// floating behavior is coordinated between the outer and inner [Scrollable]s, +// so it behaves as it would in a single scrollable. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + body: NestedScrollView( + // Setting floatHeaderSlivers to true is required in order to float + // the outer slivers over the inner scrollable. + floatHeaderSlivers: true, + headerSliverBuilder: + (BuildContext context, bool innerBoxIsScrolled) { + return [ + SliverAppBar( + title: const Text('Floating Nested SliverAppBar'), + floating: true, + expandedHeight: 200.0, + forceElevated: innerBoxIsScrolled, + ), + ]; + }, + body: ListView.builder( + padding: const EdgeInsets.all(8), + itemCount: 30, + itemBuilder: (BuildContext context, int index) { + return SizedBox( + height: 50, + child: Center(child: Text('Item $index')), + ); + }))); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.2.dart b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.2.dart new file mode 100644 index 0000000000..da5a1dc21c --- /dev/null +++ b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.2.dart @@ -0,0 +1,94 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NestedScrollView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This simple example shows a [NestedScrollView] whose header contains a +// snapping, floating [SliverAppBar]. _Without_ setting any additional flags, +// e.g [NestedScrollView.floatHeaderSlivers], the [SliverAppBar] will animate +// in and out without floating. The [SliverOverlapAbsorber] and +// [SliverOverlapInjector] maintain the proper alignment between the two +// separate scroll views. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + body: NestedScrollView(headerSliverBuilder: + (BuildContext context, bool innerBoxIsScrolled) { + return [ + SliverOverlapAbsorber( + handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), + sliver: SliverAppBar( + title: const Text('Snapping Nested SliverAppBar'), + floating: true, + snap: true, + expandedHeight: 200.0, + forceElevated: innerBoxIsScrolled, + ), + ) + ]; + }, body: Builder(builder: (BuildContext context) { + return CustomScrollView( + // The "controller" and "primary" members should be left + // unset, so that the NestedScrollView can control this + // inner scroll view. + // If the "controller" property is set, then this scroll + // view will not be associated with the NestedScrollView. + slivers: [ + SliverOverlapInjector( + handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)), + SliverFixedExtentList( + itemExtent: 48.0, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => + ListTile(title: Text('Item $index')), + childCount: 30, + ), + ), + ], + ); + }))); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view_state.0.dart b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view_state.0.dart new file mode 100644 index 0000000000..434342a172 --- /dev/null +++ b/examples/api/lib/widgets/nested_scroll_view/nested_scroll_view_state.0.dart @@ -0,0 +1,81 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for NestedScrollViewState +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// [NestedScrollViewState] can be obtained using a [GlobalKey]. +// Using the following setup, you can access the inner scroll controller +// using `globalKey.currentState.innerController`. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +final GlobalKey globalKey = GlobalKey(); + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return NestedScrollView( + key: globalKey, + headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { + return const [ + SliverAppBar( + title: Text('NestedScrollViewState Demo!'), + ), + ]; + }, + body: const CustomScrollView( + // Body slivers go here! + ), + ); + } + + ScrollController get innerController { + return globalKey.currentState!.innerController; + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/notification_listener/notification.0.dart b/examples/api/lib/widgets/notification_listener/notification.0.dart new file mode 100644 index 0000000000..02ea516f66 --- /dev/null +++ b/examples/api/lib/widgets/notification_listener/notification.0.dart @@ -0,0 +1,116 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Notification +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows a [NotificationListener] widget +// that listens for [ScrollNotification] notifications. When a scroll +// event occurs in the [NestedScrollView], +// this widget is notified. The events could be either a +// [ScrollStartNotification]or[ScrollEndNotification]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + const List _tabs = ['Months', 'Days']; + const List _months = [ + 'January', + 'February', + 'March', + ]; + const List _days = [ + 'Sunday', + 'Monday', + 'Tuesday', + ]; + return DefaultTabController( + length: _tabs.length, + child: Scaffold( + // Listens to the scroll events and returns the current position. + body: NotificationListener( + onNotification: (ScrollNotification scrollNotification) { + if (scrollNotification is ScrollStartNotification) { + print('Scrolling has started'); + } else if (scrollNotification is ScrollEndNotification) { + print('Scrolling has ended'); + } + // Return true to cancel the notification bubbling. + return true; + }, + child: NestedScrollView( + headerSliverBuilder: + (BuildContext context, bool innerBoxIsScrolled) { + return [ + SliverAppBar( + title: const Text('Flutter Code Sample'), + pinned: true, + floating: true, + bottom: TabBar( + tabs: _tabs.map((String name) => Tab(text: name)).toList(), + ), + ), + ]; + }, + body: TabBarView( + children: [ + ListView.builder( + itemCount: _months.length, + itemBuilder: (BuildContext context, int index) { + return ListTile(title: Text(_months[index])); + }, + ), + ListView.builder( + itemCount: _days.length, + itemBuilder: (BuildContext context, int index) { + return ListTile(title: Text(_days[index])); + }, + ), + ], + ), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/overflow_bar/overflow_bar.0.dart b/examples/api/lib/widgets/overflow_bar/overflow_bar.0.dart new file mode 100644 index 0000000000..e210d23c8e --- /dev/null +++ b/examples/api/lib/widgets/overflow_bar/overflow_bar.0.dart @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for OverflowBar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example defines a simple approximation of a dialog +// layout, where the layout of the dialog's action buttons are +// defined by an [OverflowBar]. The content is wrapped in a +// [SingleChildScrollView], so that if overflow occurs, the +// action buttons will still be accessible by scrolling, +// no matter how much vertical space is available. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatelessWidget(), + ), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Container( + alignment: Alignment.center, + padding: const EdgeInsets.all(16), + color: Colors.black.withOpacity(0.15), + child: Material( + color: Colors.white, + elevation: 24, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(4))), + child: Padding( + padding: const EdgeInsets.all(8), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const SizedBox(height: 128, child: Placeholder()), + Align( + alignment: AlignmentDirectional.centerEnd, + child: OverflowBar( + spacing: 8, + overflowAlignment: OverflowBarAlignment.end, + children: [ + TextButton(child: const Text('Cancel'), onPressed: () {}), + TextButton( + child: const Text('Really Really Cancel'), + onPressed: () {}), + OutlinedButton(child: const Text('OK'), onPressed: () {}), + ], + ), + ), + ], + ), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.0.dart b/examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.0.dart new file mode 100644 index 0000000000..04da096776 --- /dev/null +++ b/examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.0.dart @@ -0,0 +1,82 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for GlowingOverscrollIndicator +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example demonstrates how to use a [NotificationListener] to manipulate +// the placement of a [GlowingOverscrollIndicator] when building a +// [CustomScrollView]. Drag the scrollable to see the bounds of the overscroll +// indicator. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + final double leadingPaintOffset = + MediaQuery.of(context).padding.top + AppBar().preferredSize.height; + return NotificationListener( + onNotification: (OverscrollIndicatorNotification notification) { + if (notification.leading) { + notification.paintOffset = leadingPaintOffset; + } + return false; + }, + child: CustomScrollView( + slivers: [ + const SliverAppBar(title: Text('Custom PaintOffset')), + SliverToBoxAdapter( + child: Container( + color: Colors.amberAccent, + height: 100, + child: const Center(child: Text('Glow all day!')), + ), + ), + const SliverFillRemaining(child: FlutterLogo()), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.1.dart b/examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.1.dart new file mode 100644 index 0000000000..a9edb9ecef --- /dev/null +++ b/examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.1.dart @@ -0,0 +1,78 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for GlowingOverscrollIndicator +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example demonstrates how to use a [NestedScrollView] to manipulate the +// placement of a [GlowingOverscrollIndicator] when building a +// [CustomScrollView]. Drag the scrollable to see the bounds of the overscroll +// indicator. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return NestedScrollView( + headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { + return const [ + SliverAppBar(title: Text('Custom NestedScrollViews')), + ]; + }, + body: CustomScrollView( + slivers: [ + SliverToBoxAdapter( + child: Container( + color: Colors.amberAccent, + height: 100, + child: const Center(child: Text('Glow all day!')), + ), + ), + const SliverFillRemaining(child: FlutterLogo()), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/page_storage/page_storage.0.dart b/examples/api/lib/widgets/page_storage/page_storage.0.dart new file mode 100644 index 0000000000..d25dbb4298 --- /dev/null +++ b/examples/api/lib/widgets/page_storage/page_storage.0.dart @@ -0,0 +1,125 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for PageStorage +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how to explicitly use a [PageStorage] to +// store the states of its children pages. Each page includes a scrollable +// list, whose position is preserved when switching between the tabs thanks to +// the help of [PageStorageKey]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +void main() => runApp(const MyApp()); + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return const MaterialApp( + home: MyHomePage(), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({Key? key}) : super(key: key); + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + final List pages = const [ + ColorBoxPage( + key: PageStorageKey('pageOne'), + ), + ColorBoxPage( + key: PageStorageKey('pageTwo'), + ) + ]; + int currentTab = 0; + final PageStorageBucket _bucket = PageStorageBucket(); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Persistence Example'), + ), + body: PageStorage( + child: pages[currentTab], + bucket: _bucket, + ), + bottomNavigationBar: BottomNavigationBar( + currentIndex: currentTab, + onTap: (int index) { + setState(() { + currentTab = index; + }); + }, + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.home), + label: 'page 1', + ), + BottomNavigationBarItem( + icon: Icon(Icons.settings), + label: 'page2', + ), + ], + ), + ); + } +} + +class ColorBoxPage extends StatelessWidget { + const ColorBoxPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return ListView.builder( + itemExtent: 250.0, + itemBuilder: (BuildContext context, int index) => Container( + padding: const EdgeInsets.all(10.0), + child: Material( + color: index.isEven ? Colors.cyan : Colors.deepOrange, + child: Center( + child: Text(index.toString()), + ), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/page_view/page_view.0.dart b/examples/api/lib/widgets/page_view/page_view.0.dart new file mode 100644 index 0000000000..a4e0038cdc --- /dev/null +++ b/examples/api/lib/widgets/page_view/page_view.0.dart @@ -0,0 +1,75 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for PageView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here is an example of [PageView]. It creates a centered [Text] in each of the three pages +// which scroll horizontally. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + final PageController controller = PageController(initialPage: 0); + return PageView( + /// [PageView.scrollDirection] defaults to [Axis.horizontal]. + /// Use [Axis.vertical] to scroll vertically. + scrollDirection: Axis.horizontal, + controller: controller, + children: const [ + Center( + child: Text('First Page'), + ), + Center( + child: Text('Second Page'), + ), + Center( + child: Text('Third Page'), + ) + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/preferred_size/preferred_size.0.dart b/examples/api/lib/widgets/preferred_size/preferred_size.0.dart new file mode 100644 index 0000000000..123dfc1b2a --- /dev/null +++ b/examples/api/lib/widgets/preferred_size/preferred_size.0.dart @@ -0,0 +1,119 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for PreferredSize +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a custom widget, similar to an [AppBar], which uses a +// [PreferredSize] widget, with its height set to 80 logical pixels. +// Changing the [PreferredSize] can be used to change the height +// of the custom app bar. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class AppBarContent extends StatelessWidget { + const AppBarContent({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Row( + children: [ + const Text( + 'PreferredSize Sample', + style: TextStyle(color: Colors.white), + ), + const Spacer(), + IconButton( + icon: const Icon( + Icons.search, + size: 20, + ), + color: Colors.white, + onPressed: () {}, + ), + IconButton( + icon: const Icon( + Icons.more_vert, + size: 20, + ), + color: Colors.white, + onPressed: () {}, + ), + ], + ), + ), + ], + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + appBar: PreferredSize( + preferredSize: const Size.fromHeight(80.0), + child: Container( + decoration: const BoxDecoration( + gradient: LinearGradient( + colors: [Colors.blue, Colors.pink], + ), + ), + child: const AppBarContent(), + ), + ), + body: const Center( + child: Text('Content'), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/restoration_properties/restorable_value.0.dart b/examples/api/lib/widgets/restoration_properties/restorable_value.0.dart new file mode 100644 index 0000000000..2547b17575 --- /dev/null +++ b/examples/api/lib/widgets/restoration_properties/restorable_value.0.dart @@ -0,0 +1,102 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_restoration.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RestorableValue +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// A [StatefulWidget] that has a restorable [int] property. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return WidgetsApp( + title: 'Flutter Code Sample', + home: const Center( + child: MyStatefulWidget(restorationId: 'main'), + ), + color: const Color(0xffffffff), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key, this.restorationId}) : super(key: key); + + final String? restorationId; + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// RestorationProperty objects can be used because of RestorationMixin. +class _MyStatefulWidgetState extends State + with RestorationMixin { + // In this example, the restoration ID for the mixin is passed in through + // the [StatefulWidget]'s constructor. + @override + String? get restorationId => widget.restorationId; + +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + // The current value of the answer is stored in a [RestorableProperty]. + // During state restoration it is automatically restored to its old value. + // If no restoration data is available to restore the answer from, it is + // initialized to the specified default value, in this case 42. + final RestorableInt _answer = RestorableInt(42); + + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + // All restorable properties must be registered with the mixin. After + // registration, the answer either has its old value restored or is + // initialized to its default value. + registerForRestoration(_answer, 'answer'); + } + + void _incrementAnswer() { + setState(() { + // The current value of the property can be accessed and modified via + // the value getter and setter. + _answer.value += 1; + }); + } + + @override + void dispose() { + // Properties must be disposed when no longer used. + _answer.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return OutlinedButton( + child: Text('${_answer.value}'), + onPressed: _incrementAnswer, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/routes/show_general_dialog.0.dart b/examples/api/lib/widgets/routes/show_general_dialog.0.dart new file mode 100644 index 0000000000..5214a43b81 --- /dev/null +++ b/examples/api/lib/widgets/routes/show_general_dialog.0.dart @@ -0,0 +1,82 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_restoration_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for showGeneralDialog +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample demonstrates how to create a restorable dialog. This is +// accomplished by enabling state restoration by specifying +// [WidgetsApp.restorationScopeId] and using [Navigator.restorablePush] to +// push [RawDialogRoute] when the button is tapped. +// +// {@macro flutter.widgets.RestorationManager} + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + restorationScopeId: 'app', + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: OutlinedButton( + onPressed: () { + Navigator.of(context).restorablePush(_dialogBuilder); + }, + child: const Text('Open Dialog'), + ), + ), + ); + } + + static Route _dialogBuilder( + BuildContext context, Object? arguments) { + return RawDialogRoute( + pageBuilder: ( + BuildContext context, + Animation animation, + Animation secondaryAnimation, + ) { + return const AlertDialog(title: Text('Alert!')); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart b/examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart new file mode 100644 index 0000000000..27bde4c7fe --- /dev/null +++ b/examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart @@ -0,0 +1,80 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/freeform.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScrollMetricsNotification +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows how a [ScrollMetricsNotification] is dispatched when +// the `windowSize` is changed. Press the floating action button to increase +// the scrollable window's size. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//************************************************************************* +//* ▼▼▼▼▼▼▼▼ code-main ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/material.dart'; + +void main() => runApp(const ScrollMetricsDemo()); + +class ScrollMetricsDemo extends StatefulWidget { + const ScrollMetricsDemo({Key? key}) : super(key: key); + + @override + State createState() => ScrollMetricsDemoState(); +} + +class ScrollMetricsDemoState extends State { + double windowSize = 200.0; + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('ScrollMetrics Demo'), + ), + floatingActionButton: FloatingActionButton( + child: const Icon(Icons.add), + onPressed: () => setState(() { + windowSize += 10.0; + }), + ), + body: NotificationListener( + onNotification: (ScrollMetricsNotification notification) { + ScaffoldMessenger.of(notification.context).showSnackBar( + const SnackBar( + content: Text('Scroll metrics changed!'), + ), + ); + return false; + }, + child: Scrollbar( + isAlwaysShown: true, + child: SizedBox( + height: windowSize, + width: double.infinity, + child: const SingleChildScrollView( + child: FlutterLogo( + size: 300.0, + ), + ), + ), + ), + ), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-main ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//************************************************************************* diff --git a/examples/api/lib/widgets/scroll_view/custom_scroll_view.1.dart b/examples/api/lib/widgets/scroll_view/custom_scroll_view.1.dart new file mode 100644 index 0000000000..827328b117 --- /dev/null +++ b/examples/api/lib/widgets/scroll_view/custom_scroll_view.1.dart @@ -0,0 +1,116 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CustomScrollView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// By default, if items are inserted at the "top" of a scrolling container like +// [ListView] or [CustomScrollView], the top item and all of the items below it +// are scrolled downwards. In some applications, it's preferable to have the +// top of the list just grow upwards, without changing the scroll position. +// This example demonstrates how to do that with a [CustomScrollView] with +// two [SliverList] children, and the [CustomScrollView.center] set to the key +// of the bottom SliverList. The top one SliverList will grow upwards, and the +// bottom SliverList will grow downwards. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + List top = []; + List bottom = [0]; + + @override + Widget build(BuildContext context) { + const Key centerKey = ValueKey('bottom-sliver-list'); + return Scaffold( + appBar: AppBar( + title: const Text('Press on the plus to add items above and below'), + leading: IconButton( + icon: const Icon(Icons.add), + onPressed: () { + setState(() { + top.add(-top.length - 1); + bottom.add(bottom.length); + }); + }, + ), + ), + body: CustomScrollView( + center: centerKey, + slivers: [ + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Container( + alignment: Alignment.center, + color: Colors.blue[200 + top[index] % 4 * 100], + height: 100 + top[index] % 4 * 20.0, + child: Text('Item: ${top[index]}'), + ); + }, + childCount: top.length, + ), + ), + SliverList( + key: centerKey, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Container( + alignment: Alignment.center, + color: Colors.blue[200 + bottom[index] % 4 * 100], + height: 100 + bottom[index] % 4 * 20.0, + child: Text('Item: ${bottom[index]}'), + ); + }, + childCount: bottom.length, + ), + ), + ], + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart b/examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart new file mode 100644 index 0000000000..f6c497d1c7 --- /dev/null +++ b/examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart @@ -0,0 +1,121 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RawScrollbar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows an app with two scrollables in the same route. Since by +// default, there is one [PrimaryScrollController] per route, and they both have a +// scroll direction of [Axis.vertical], they would both try to attach to that +// controller. The [Scrollbar] cannot support multiple positions attached to +// the same controller, so one [ListView], and its [Scrollbar] have been +// provided a unique [ScrollController]. +// +// Alternatively, a new PrimaryScrollController could be created above one of +// the [ListView]s. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final ScrollController _firstController = ScrollController(); + + @override + Widget build(BuildContext context) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return Row( + children: [ + SizedBox( + width: constraints.maxWidth / 2, + // Only one scroll position can be attached to the + // PrimaryScrollController if using Scrollbars. Providing a + // unique scroll controller to this scroll view prevents it + // from attaching to the PrimaryScrollController. + child: Scrollbar( + isAlwaysShown: true, + controller: _firstController, + child: ListView.builder( + controller: _firstController, + itemCount: 100, + itemBuilder: (BuildContext context, int index) { + return Padding( + padding: const EdgeInsets.all(8.0), + child: Text('Scrollable 1 : Index $index'), + ); + }), + )), + SizedBox( + width: constraints.maxWidth / 2, + // This vertical scroll view has not been provided a + // ScrollController, so it is using the + // PrimaryScrollController. + child: Scrollbar( + isAlwaysShown: true, + child: ListView.builder( + itemCount: 100, + itemBuilder: (BuildContext context, int index) { + return Container( + height: 50, + color: index.isEven + ? Colors.amberAccent + : Colors.blueAccent, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text('Scrollable 2 : Index $index'), + )); + }), + )), + ], + ); + }); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/scrollbar/raw_scrollbar.1.dart b/examples/api/lib/widgets/scrollbar/raw_scrollbar.1.dart new file mode 100644 index 0000000000..08b2bda958 --- /dev/null +++ b/examples/api/lib/widgets/scrollbar/raw_scrollbar.1.dart @@ -0,0 +1,72 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RawScrollbar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a [RawScrollbar] that executes a fade animation as +// scrolling occurs. The RawScrollbar will fade into view as the user scrolls, +// and fade out when scrolling stops. The [GridView] uses the +// [PrimaryScrollController] since it has an [Axis.vertical] scroll direction +// and has not been provided a [ScrollController]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return RawScrollbar( + child: GridView.builder( + itemCount: 120, + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), + itemBuilder: (BuildContext context, int index) { + return Center( + child: Text('item $index'), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart b/examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart new file mode 100644 index 0000000000..e9b8ec96ff --- /dev/null +++ b/examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RawScrollbar +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// When `isAlwaysShown` is true, the scrollbar thumb will remain visible without +// the fade animation. This requires that a [ScrollController] is provided to +// `controller` for both the [RawScrollbar] and the [GridView]. +// Alternatively, the [PrimaryScrollController] can be used automatically so long +// as it is attached to the singular [ScrollPosition] associated with the GridView. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatefulWidget(), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final ScrollController _controllerOne = ScrollController(); + + @override + Widget build(BuildContext context) { + return RawScrollbar( + controller: _controllerOne, + isAlwaysShown: true, + child: GridView.builder( + controller: _controllerOne, + itemCount: 120, + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), + itemBuilder: (BuildContext context, int index) { + return Center( + child: Text('item $index'), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/shortcuts/character_activator.0.dart b/examples/api/lib/widgets/shortcuts/character_activator.0.dart new file mode 100644 index 0000000000..392d988fad --- /dev/null +++ b/examples/api/lib/widgets/shortcuts/character_activator.0.dart @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for CharacterActivator +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In the following example, when a key combination results in a question mark, +// the counter is increased: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class HelpMenuIntent extends Intent { + const HelpMenuIntent(); +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + @override + Widget build(BuildContext context) { + return Shortcuts( + shortcuts: const { + CharacterActivator('?'): HelpMenuIntent(), + }, + child: Actions( + actions: >{ + HelpMenuIntent: CallbackAction( + onInvoke: (HelpMenuIntent intent) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Keep calm and carry on!')), + ); + return null; + }, + ), + }, + child: Focus( + autofocus: true, + child: Column( + children: const [ + Text('Press question mark for help'), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/shortcuts/logical_key_set.0.dart b/examples/api/lib/widgets/shortcuts/logical_key_set.0.dart new file mode 100644 index 0000000000..fe5103a701 --- /dev/null +++ b/examples/api/lib/widgets/shortcuts/logical_key_set.0.dart @@ -0,0 +1,116 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for LogicalKeySet +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In the following example, the counter is increased when the following key +// sequences are pressed: +// +// * Control left, then C. +// * Control right, then C. +// * C, then Control left. +// +// But not when: +// +// * Control left, then A, then C. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class IncrementIntent extends Intent { + const IncrementIntent(); +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int count = 0; + + @override + Widget build(BuildContext context) { + return Shortcuts( + shortcuts: { + LogicalKeySet(LogicalKeyboardKey.keyC, LogicalKeyboardKey.controlLeft): + const IncrementIntent(), + }, + child: Actions( + actions: >{ + IncrementIntent: CallbackAction( + onInvoke: (IncrementIntent intent) => setState(() { + count = count + 1; + }), + ), + }, + child: Focus( + autofocus: true, + child: Column( + children: [ + const Text('Add to the counter by pressing Ctrl+C'), + Text('count: $count'), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/shortcuts/shortcuts.0.dart b/examples/api/lib/widgets/shortcuts/shortcuts.0.dart new file mode 100644 index 0000000000..f8448e22df --- /dev/null +++ b/examples/api/lib/widgets/shortcuts/shortcuts.0.dart @@ -0,0 +1,124 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Shortcuts +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Here, we will use the [Shortcuts] and [Actions] widgets to add and subtract +// from a counter. When the child widget has keyboard focus, and a user presses +// the keys that have been defined in [Shortcuts], the action that is bound +// to the appropriate [Intent] for the key is invoked. +// +// It also shows the use of a [CallbackAction] to avoid creating a new [Action] +// subclass. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class IncrementIntent extends Intent { + const IncrementIntent(); +} + +class DecrementIntent extends Intent { + const DecrementIntent(); +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int count = 0; + + @override + Widget build(BuildContext context) { + return Shortcuts( + shortcuts: { + LogicalKeySet(LogicalKeyboardKey.arrowUp): const IncrementIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowDown): const DecrementIntent(), + }, + child: Actions( + actions: >{ + IncrementIntent: CallbackAction( + onInvoke: (IncrementIntent intent) => setState(() { + count = count + 1; + }), + ), + DecrementIntent: CallbackAction( + onInvoke: (DecrementIntent intent) => setState(() { + count = count - 1; + }), + ), + }, + child: Focus( + autofocus: true, + child: Column( + children: [ + const Text('Add to the counter by pressing the up arrow key'), + const Text( + 'Subtract from the counter by pressing the down arrow key'), + Text('count: $count'), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/shortcuts/shortcuts.1.dart b/examples/api/lib/widgets/shortcuts/shortcuts.1.dart new file mode 100644 index 0000000000..a556b2a935 --- /dev/null +++ b/examples/api/lib/widgets/shortcuts/shortcuts.1.dart @@ -0,0 +1,164 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Shortcuts +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This slightly more complicated, but more flexible, example creates a custom +// [Action] subclass to increment and decrement within a widget (a [Column]) +// that has keyboard focus. When the user presses the up and down arrow keys, +// the counter will increment and decrement a data model using the custom +// actions. +// +// One thing that this demonstrates is passing arguments to the [Intent] to be +// carried to the [Action]. This shows how actions can get data either from +// their own construction (like the `model` in this example), or from the +// intent passed to them when invoked (like the increment `amount` in this +// example). + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class Model with ChangeNotifier { + int count = 0; + void incrementBy(int amount) { + count += amount; + notifyListeners(); + } + + void decrementBy(int amount) { + count -= amount; + notifyListeners(); + } +} + +class IncrementIntent extends Intent { + const IncrementIntent(this.amount); + + final int amount; +} + +class DecrementIntent extends Intent { + const DecrementIntent(this.amount); + + final int amount; +} + +class IncrementAction extends Action { + IncrementAction(this.model); + + final Model model; + + @override + void invoke(covariant IncrementIntent intent) { + model.incrementBy(intent.amount); + } +} + +class DecrementAction extends Action { + DecrementAction(this.model); + + final Model model; + + @override + void invoke(covariant DecrementIntent intent) { + model.decrementBy(intent.amount); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Model model = Model(); + + @override + Widget build(BuildContext context) { + return Shortcuts( + shortcuts: { + LogicalKeySet(LogicalKeyboardKey.arrowUp): const IncrementIntent(2), + LogicalKeySet(LogicalKeyboardKey.arrowDown): const DecrementIntent(2), + }, + child: Actions( + actions: >{ + IncrementIntent: IncrementAction(model), + DecrementIntent: DecrementAction(model), + }, + child: Focus( + autofocus: true, + child: Column( + children: [ + const Text('Add to the counter by pressing the up arrow key'), + const Text( + 'Subtract from the counter by pressing the down arrow key'), + AnimatedBuilder( + animation: model, + builder: (BuildContext context, Widget? child) { + return Text('count: ${model.count}'); + }, + ), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart b/examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart new file mode 100644 index 0000000000..f1ad6626b4 --- /dev/null +++ b/examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart @@ -0,0 +1,107 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SingleActivator.SingleActivator +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In the following example, the shortcut `Control + C` increases the counter: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; +//**************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-imports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'package:flutter/services.dart'; + +//* ▲▲▲▲▲▲▲▲ code-imports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//**************************************************************************** + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class IncrementIntent extends Intent { + const IncrementIntent(); +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + int count = 0; + + @override + Widget build(BuildContext context) { + return Shortcuts( + shortcuts: const { + SingleActivator(LogicalKeyboardKey.keyC, control: true): + IncrementIntent(), + }, + child: Actions( + actions: >{ + IncrementIntent: CallbackAction( + onInvoke: (IncrementIntent intent) => setState(() { + count = count + 1; + }), + ), + }, + child: Focus( + autofocus: true, + child: Column( + children: [ + const Text('Add to the counter by pressing Ctrl+C'), + Text('count: $count'), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.0.dart b/examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.0.dart new file mode 100644 index 0000000000..2dbb01a5d3 --- /dev/null +++ b/examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.0.dart @@ -0,0 +1,92 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SingleChildScrollView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this example, the children are spaced out equally, unless there's no more +// room, in which case they stack vertically and scroll. +// +// When using this technique, [Expanded] and [Flexible] are not useful, because +// in both cases the "available space" is infinite (since this is in a viewport). +// The next section describes a technique for providing a maximum height constraint. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return DefaultTextStyle( + style: Theme.of(context).textTheme.bodyText2!, + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints viewportConstraints) { + return SingleChildScrollView( + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: viewportConstraints.maxHeight, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Container( + // A fixed-height child. + color: const Color(0xffeeee00), // Yellow + height: 120.0, + alignment: Alignment.center, + child: const Text('Fixed Height Content'), + ), + Container( + // Another fixed-height child. + color: const Color(0xff008000), // Green + height: 120.0, + alignment: Alignment.center, + child: const Text('Fixed Height Content'), + ), + ], + ), + ), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.1.dart b/examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.1.dart new file mode 100644 index 0000000000..5c7d43700f --- /dev/null +++ b/examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.1.dart @@ -0,0 +1,91 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SingleChildScrollView +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this example, the column becomes either as big as viewport, or as big as +// the contents, whichever is biggest. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return DefaultTextStyle( + style: Theme.of(context).textTheme.bodyText2!, + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints viewportConstraints) { + return SingleChildScrollView( + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: viewportConstraints.maxHeight, + ), + child: IntrinsicHeight( + child: Column( + children: [ + Container( + // A fixed-height child. + color: const Color(0xffeeee00), // Yellow + height: 120.0, + alignment: Alignment.center, + child: const Text('Fixed Height Content'), + ), + Expanded( + // A flexible child that will grow to fit the viewport but + // still be at least as big as necessary to fit its contents. + child: Container( + color: const Color(0xffee0000), // Red + height: 120.0, + alignment: Alignment.center, + child: const Text('Flexible Content'), + ), + ), + ], + ), + ), + ), + ); + }, + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.0.dart b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.0.dart new file mode 100644 index 0000000000..5ed1739090 --- /dev/null +++ b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.0.dart @@ -0,0 +1,79 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverFillRemaining +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this sample the [SliverFillRemaining] sizes its [child] to fill the +// remaining extent of the viewport in both axes. The icon is centered in the +// sliver, and would be in any computed extent for the sliver. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return CustomScrollView( + slivers: [ + SliverToBoxAdapter( + child: Container( + color: Colors.amber[300], + height: 150.0, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + child: Container( + color: Colors.blue[100], + child: Icon( + Icons.sentiment_very_satisfied, + size: 75, + color: Colors.blue[900], + ), + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.1.dart b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.1.dart new file mode 100644 index 0000000000..5c0f481725 --- /dev/null +++ b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.1.dart @@ -0,0 +1,83 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverFillRemaining +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this sample the [SliverFillRemaining] defers to the size of its [child] +// because the child's extent exceeds that of the remaining extent of the +// viewport's main axis. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return CustomScrollView( + slivers: [ + SliverFixedExtentList( + itemExtent: 100.0, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Container( + color: index.isEven ? Colors.amber[200] : Colors.blue[200], + ); + }, + childCount: 3, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + child: Container( + color: Colors.orange[300], + child: const Padding( + padding: EdgeInsets.all(50.0), + child: FlutterLogo(size: 100), + ), + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.2.dart b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.2.dart new file mode 100644 index 0000000000..b0b9b920b5 --- /dev/null +++ b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.2.dart @@ -0,0 +1,84 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverFillRemaining +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this sample the [SliverFillRemaining] defers to the size of its [child] +// because the [SliverConstraints.precedingScrollExtent] has gone +// beyond that of the viewport's main axis. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return CustomScrollView( + slivers: [ + SliverFixedExtentList( + itemExtent: 130.0, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Container( + color: index.isEven ? Colors.indigo[200] : Colors.orange[200], + ); + }, + childCount: 5, + ), + ), + const SliverFillRemaining( + hasScrollBody: false, + child: Padding( + padding: EdgeInsets.all(50.0), + child: Icon( + Icons.pan_tool, + size: 60, + color: Colors.blueGrey, + ), + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.3.dart b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.3.dart new file mode 100644 index 0000000000..a01414edb6 --- /dev/null +++ b/examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.3.dart @@ -0,0 +1,104 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverFillRemaining +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// In this sample the [SliverFillRemaining]'s child stretches to fill the +// overscroll area when [fillOverscroll] is true. This sample also features a +// button that is pinned to the bottom of the sliver, regardless of size or +// overscroll behavior. Try switching [fillOverscroll] to see the difference. +// +// This sample only shows the overscroll behavior on devices that support +// overscroll. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return CustomScrollView( + // The ScrollPhysics are overridden here to illustrate the functionality + // of fillOverscroll on all devices this sample may be run on. + // fillOverscroll only changes the behavior of your layout when applied + // to Scrollables that allow for overscroll. BouncingScrollPhysics are + // one example, which are provided by default on the iOS platform. + // BouncingScrollPhysics is combined with AlwaysScrollableScrollPhysics + // to allow for the overscroll, regardless of the depth of the + // scrollable. + physics: + const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), + slivers: [ + SliverToBoxAdapter( + child: Container( + color: Colors.tealAccent[700], + height: 150.0, + ), + ), + SliverFillRemaining( + hasScrollBody: false, + // Switch for different overscroll behavior in your layout. + // If your ScrollPhysics do not allow for overscroll, setting + // fillOverscroll to true will have no effect. + fillOverscroll: true, + child: Container( + color: Colors.teal[100], + child: Align( + alignment: Alignment.bottomCenter, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: ElevatedButton( + onPressed: () { + /* Place your onPressed code here! */ + }, + child: const Text('Bottom Pinned Button!'), + ), + ), + ), + ), + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/table/table.0.dart b/examples/api/lib/widgets/table/table.0.dart new file mode 100644 index 0000000000..622e005277 --- /dev/null +++ b/examples/api/lib/widgets/table/table.0.dart @@ -0,0 +1,110 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateless_widget_scaffold.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for Table +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This sample shows a `Table` with borders, multiple types of column widths and different vertical cell alignments. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const MyStatelessWidget(), + ), + ); + } +} + +/// This is the stateless widget that the main application instantiates. +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + Widget build(BuildContext context) { + return Table( + border: TableBorder.all(), + columnWidths: const { + 0: IntrinsicColumnWidth(), + 1: FlexColumnWidth(), + 2: FixedColumnWidth(64), + }, + defaultVerticalAlignment: TableCellVerticalAlignment.middle, + children: [ + TableRow( + children: [ + Container( + height: 32, + color: Colors.green, + ), + TableCell( + verticalAlignment: TableCellVerticalAlignment.top, + child: Container( + height: 32, + width: 32, + color: Colors.red, + ), + ), + Container( + height: 64, + color: Colors.blue, + ), + ], + ), + TableRow( + decoration: const BoxDecoration( + color: Colors.grey, + ), + children: [ + Container( + height: 64, + width: 128, + color: Colors.purple, + ), + Container( + height: 32, + color: Colors.yellow, + ), + Center( + child: Container( + height: 32, + width: 32, + color: Colors.orange, + ), + ), + ], + ), + ], + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/align_transition.0.dart b/examples/api/lib/widgets/transitions/align_transition.0.dart new file mode 100644 index 0000000000..0391f4322b --- /dev/null +++ b/examples/api/lib/widgets/transitions/align_transition.0.dart @@ -0,0 +1,93 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AlignTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [AlignTransition] as seen in the video +// above: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Using `late final` for [lazy initialization](https://dart.dev/null-safety/understanding-null-safety#lazy-initialization). + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + late final Animation _animation = Tween( + begin: Alignment.bottomLeft, + end: Alignment.center, + ).animate( + CurvedAnimation( + parent: _controller, + curve: Curves.decelerate, + ), + ); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: AlignTransition( + alignment: _animation, + child: const Padding( + padding: EdgeInsets.all(8), + child: FlutterLogo(size: 150.0), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/animated_builder.0.dart b/examples/api/lib/widgets/transitions/animated_builder.0.dart new file mode 100644 index 0000000000..efdc13d42b --- /dev/null +++ b/examples/api/lib/widgets/transitions/animated_builder.0.dart @@ -0,0 +1,99 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This code defines a widget that spins a green square continually. It is +// built with an [AnimatedBuilder] and makes use of the [child] feature to +// avoid having to rebuild the [Container] each time. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//******************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-dartImports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'dart:math' as math; + +//* ▲▲▲▲▲▲▲▲ code-dartImports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 10), + vsync: this, + )..repeat(); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: _controller, + child: Container( + width: 200.0, + height: 200.0, + color: Colors.green, + child: const Center( + child: Text('Whee!'), + ), + ), + builder: (BuildContext context, Widget? child) { + return Transform.rotate( + angle: _controller.value * 2.0 * math.pi, + child: child, + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/animated_widget.0.dart b/examples/api/lib/widgets/transitions/animated_widget.0.dart new file mode 100644 index 0000000000..928e7f7aed --- /dev/null +++ b/examples/api/lib/widgets/transitions/animated_widget.0.dart @@ -0,0 +1,105 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for AnimatedWidget +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This code defines a widget called `Spinner` that spins a green square +// continually. It is built with an [AnimatedWidget]. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +//******************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-dartImports ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +import 'dart:math' as math; + +//* ▲▲▲▲▲▲▲▲ code-dartImports ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +//***************************************************************************** +//* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class SpinningContainer extends AnimatedWidget { + const SpinningContainer({ + Key? key, + required AnimationController controller, + }) : super(key: key, listenable: controller); + + Animation get _progress => listenable as Animation; + + @override + Widget build(BuildContext context) { + return Transform.rotate( + angle: _progress.value * 2.0 * math.pi, + child: Container(width: 200.0, height: 200.0, color: Colors.green), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//***************************************************************************** + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 10), + vsync: this, + )..repeat(); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SpinningContainer(controller: _controller); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/decorated_box_transition.0.dart b/examples/api/lib/widgets/transitions/decorated_box_transition.0.dart new file mode 100644 index 0000000000..6c4f5b6d8c --- /dev/null +++ b/examples/api/lib/widgets/transitions/decorated_box_transition.0.dart @@ -0,0 +1,113 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DecoratedBoxTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [DecoratedBoxTransition] as seen in the video +// above: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + final DecorationTween decorationTween = DecorationTween( + begin: BoxDecoration( + color: const Color(0xFFFFFFFF), + border: Border.all(style: BorderStyle.none), + borderRadius: BorderRadius.circular(60.0), + shape: BoxShape.rectangle, + boxShadow: const [ + BoxShadow( + color: Color(0x66666666), + blurRadius: 10.0, + spreadRadius: 3.0, + offset: Offset(0, 6.0), + ) + ], + ), + end: BoxDecoration( + color: const Color(0xFFFFFFFF), + border: Border.all( + style: BorderStyle.none, + ), + borderRadius: BorderRadius.zero, + // No shadow. + ), + ); + + late final AnimationController _controller = AnimationController( + vsync: this, + duration: const Duration(seconds: 3), + )..repeat(reverse: true); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: Center( + child: DecoratedBoxTransition( + position: DecorationPosition.background, + decoration: decorationTween.animate(_controller), + child: Container( + width: 200, + height: 200, + padding: const EdgeInsets.all(10), + child: const FlutterLogo(), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/default_text_style_transition.0.dart b/examples/api/lib/widgets/transitions/default_text_style_transition.0.dart new file mode 100644 index 0000000000..2b5fa03145 --- /dev/null +++ b/examples/api/lib/widgets/transitions/default_text_style_transition.0.dart @@ -0,0 +1,97 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for DefaultTextStyleTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [DefaultTextStyleTransition] that shows +// a transition between thick blue font and thin red font. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late AnimationController _controller; + late TextStyleTween _styleTween; + late CurvedAnimation _curvedAnimation; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + _styleTween = TextStyleTween( + begin: const TextStyle( + fontSize: 50, color: Colors.blue, fontWeight: FontWeight.w900), + end: const TextStyle( + fontSize: 50, color: Colors.red, fontWeight: FontWeight.w100), + ); + _curvedAnimation = CurvedAnimation( + parent: _controller, + curve: Curves.elasticInOut, + ); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Center( + child: DefaultTextStyleTransition( + style: _styleTween.animate(_curvedAnimation), + child: const Text('Flutter'), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/fade_transition.0.dart b/examples/api/lib/widgets/transitions/fade_transition.0.dart new file mode 100644 index 0000000000..8e70c225ca --- /dev/null +++ b/examples/api/lib/widgets/transitions/fade_transition.0.dart @@ -0,0 +1,84 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for FadeTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [FadeTransition] using +// the Flutter logo: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + late final Animation _animation = CurvedAnimation( + parent: _controller, + curve: Curves.easeIn, + ); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: FadeTransition( + opacity: _animation, + child: const Padding(padding: EdgeInsets.all(8), child: FlutterLogo()), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/positioned_transition.0.dart b/examples/api/lib/widgets/transitions/positioned_transition.0.dart new file mode 100644 index 0000000000..766896847d --- /dev/null +++ b/examples/api/lib/widgets/transitions/positioned_transition.0.dart @@ -0,0 +1,100 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for PositionedTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [PositionedTransition] as seen in the video +// above: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + const double smallLogo = 100; + const double bigLogo = 200; + + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final Size biggest = constraints.biggest; + return Stack( + children: [ + PositionedTransition( + rect: RelativeRectTween( + begin: RelativeRect.fromSize( + const Rect.fromLTWH(0, 0, smallLogo, smallLogo), biggest), + end: RelativeRect.fromSize( + Rect.fromLTWH(biggest.width - bigLogo, + biggest.height - bigLogo, bigLogo, bigLogo), + biggest), + ).animate(CurvedAnimation( + parent: _controller, + curve: Curves.elasticInOut, + )), + child: const Padding( + padding: EdgeInsets.all(8), child: FlutterLogo()), + ), + ], + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/relative_positioned_transition.0.dart b/examples/api/lib/widgets/transitions/relative_positioned_transition.0.dart new file mode 100644 index 0000000000..fa74a67590 --- /dev/null +++ b/examples/api/lib/widgets/transitions/relative_positioned_transition.0.dart @@ -0,0 +1,98 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RelativePositionedTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [RelativePositionedTransition] as seen in the video +// above: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + const double smallLogo = 100; + const double bigLogo = 200; + + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + final Size biggest = constraints.biggest; + return Stack( + children: [ + RelativePositionedTransition( + size: biggest, + rect: RectTween( + begin: const Rect.fromLTWH(0, 0, bigLogo, bigLogo), + end: Rect.fromLTWH(biggest.width - smallLogo, + biggest.height - smallLogo, smallLogo, smallLogo), + ).animate(CurvedAnimation( + parent: _controller, + curve: Curves.elasticInOut, + )) as Animation, + child: const Padding( + padding: EdgeInsets.all(8), child: FlutterLogo()), + ), + ], + ); + }, + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/rotation_transition.0.dart b/examples/api/lib/widgets/transitions/rotation_transition.0.dart new file mode 100644 index 0000000000..1c22fd64c7 --- /dev/null +++ b/examples/api/lib/widgets/transitions/rotation_transition.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for RotationTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [RotationTransition] as seen in the video +// above: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + late final Animation _animation = CurvedAnimation( + parent: _controller, + curve: Curves.elasticOut, + ); + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: RotationTransition( + turns: _animation, + child: const Padding( + padding: EdgeInsets.all(8.0), + child: FlutterLogo(size: 150.0), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/scale_transition.0.dart b/examples/api/lib/widgets/transitions/scale_transition.0.dart new file mode 100644 index 0000000000..789a3489aa --- /dev/null +++ b/examples/api/lib/widgets/transitions/scale_transition.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for ScaleTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [ScaleTransition] as seen in the video +// above: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + late final Animation _animation = CurvedAnimation( + parent: _controller, + curve: Curves.fastOutSlowIn, + ); + + @override + void dispose() { + super.dispose(); + _controller.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: ScaleTransition( + scale: _animation, + child: const Padding( + padding: EdgeInsets.all(8.0), + child: FlutterLogo(size: 150.0), + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/size_transition.0.dart b/examples/api/lib/widgets/transitions/size_transition.0.dart new file mode 100644 index 0000000000..dc21bfa7ba --- /dev/null +++ b/examples/api/lib/widgets/transitions/size_transition.0.dart @@ -0,0 +1,88 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material_ticker.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SizeTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This code defines a widget that uses [SizeTransition] to change the size +// of [FlutterLogo] continually. It is built with a [Scaffold] +// where the internal widget has space to change its size. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +/// AnimationControllers can be created with `vsync: this` because of TickerProviderStateMixin. +class _MyStatefulWidgetState extends State + with TickerProviderStateMixin { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 3), + vsync: this, + )..repeat(); + late final Animation _animation = CurvedAnimation( + parent: _controller, + curve: Curves.fastOutSlowIn, + ); + + @override + void dispose() { + super.dispose(); + _controller.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: SizeTransition( + sizeFactor: _animation, + axis: Axis.horizontal, + axisAlignment: -1, + child: const Center( + child: FlutterLogo(size: 200.0), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/transitions/slide_transition.0.dart b/examples/api/lib/widgets/transitions/slide_transition.0.dart new file mode 100644 index 0000000000..a36758afa1 --- /dev/null +++ b/examples/api/lib/widgets/transitions/slide_transition.0.dart @@ -0,0 +1,90 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SlideTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// The following code implements the [SlideTransition] as seen in the video +// above: + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class _MyStatefulWidgetState extends State + with SingleTickerProviderStateMixin { + late final AnimationController _controller = AnimationController( + duration: const Duration(seconds: 2), + vsync: this, + )..repeat(reverse: true); + late final Animation _offsetAnimation = Tween( + begin: Offset.zero, + end: const Offset(1.5, 0.0), + ).animate(CurvedAnimation( + parent: _controller, + curve: Curves.elasticIn, + )); + + @override + void dispose() { + super.dispose(); + _controller.dispose(); + } + + @override + Widget build(BuildContext context) { + return SlideTransition( + position: _offsetAnimation, + child: const Padding( + padding: EdgeInsets.all(8.0), + child: FlutterLogo(size: 150.0), + ), + ); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/transitions/sliver_fade_transition.0.dart b/examples/api/lib/widgets/transitions/sliver_fade_transition.0.dart new file mode 100644 index 0000000000..825c046cb1 --- /dev/null +++ b/examples/api/lib/widgets/transitions/sliver_fade_transition.0.dart @@ -0,0 +1,103 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for SliverFadeTransition +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// Creates a [CustomScrollView] with a [SliverFixedExtentList] that uses a +// [SliverFadeTransition] to fade the list in and out. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +class _MyStatefulWidgetState extends State + with SingleTickerProviderStateMixin { + late final AnimationController controller = AnimationController( + duration: const Duration(milliseconds: 1000), + vsync: this, + ); + late final Animation animation = CurvedAnimation( + parent: controller, + curve: Curves.easeIn, + ); + + @override + void initState() { + super.initState(); + animation.addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.completed) { + controller.reverse(); + } else if (status == AnimationStatus.dismissed) { + controller.forward(); + } + }); + controller.forward(); + } + + @override + Widget build(BuildContext context) { + return CustomScrollView(slivers: [ + SliverFadeTransition( + opacity: animation, + sliver: SliverFixedExtentList( + itemExtent: 100.0, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return Container( + color: index.isEven ? Colors.indigo[200] : Colors.orange[200], + ); + }, + childCount: 5, + ), + ), + ) + ]); + } +} + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** diff --git a/examples/api/lib/widgets/tween_animation_builder/tween_animation_builder.0.dart b/examples/api/lib/widgets/tween_animation_builder/tween_animation_builder.0.dart new file mode 100644 index 0000000000..189a87b20b --- /dev/null +++ b/examples/api/lib/widgets/tween_animation_builder/tween_animation_builder.0.dart @@ -0,0 +1,86 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_scaffold_center.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for TweenAnimationBuilder +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// This example shows an [IconButton] that "zooms" in when the widget first +// builds (its size smoothly increases from 0 to 24) and whenever the button +// is pressed, it smoothly changes its size to the new target value of either +// 48 or 24. + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: _title, + home: Scaffold( + appBar: AppBar(title: const Text(_title)), + body: const Center( + child: MyStatefulWidget(), + ), + ), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + double targetValue = 24.0; + + @override + Widget build(BuildContext context) { + return TweenAnimationBuilder( + tween: Tween(begin: 0, end: targetValue), + duration: const Duration(seconds: 1), + builder: (BuildContext context, double size, Widget? child) { + return IconButton( + iconSize: size, + color: Colors.blue, + icon: child!, + onPressed: () { + setState(() { + targetValue = targetValue == 24.0 ? 48.0 : 24.0; + }); + }, + ); + }, + child: const Icon(Icons.aspect_ratio), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/lib/widgets/will_pop_scope/will_pop_scope.1.dart b/examples/api/lib/widgets/will_pop_scope/will_pop_scope.1.dart new file mode 100644 index 0000000000..b3a79229f4 --- /dev/null +++ b/examples/api/lib/widgets/will_pop_scope/will_pop_scope.1.dart @@ -0,0 +1,103 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Template: dev/snippets/config/templates/stateful_widget_material.tmpl +// +// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring +// of samples, and may be ignored if you are just exploring the sample. + +// Flutter code sample for WillPopScope +// +//*************************************************************************** +//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + +// + +//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//*************************************************************************** + +import 'package:flutter/material.dart'; + +void main() => runApp(const MyApp()); + +/// This is the main application widget. +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const MaterialApp( + title: _title, + home: MyStatefulWidget(), + ); + } +} + +/// This is the stateful widget that the main application instantiates. +class MyStatefulWidget extends StatefulWidget { + const MyStatefulWidget({Key? key}) : super(key: key); + + @override + State createState() => _MyStatefulWidgetState(); +} + +/// This is the private State class that goes with MyStatefulWidget. +class _MyStatefulWidgetState extends State { +//******************************************************************** +//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) + + bool shouldPop = true; + @override + Widget build(BuildContext context) { + return WillPopScope( + onWillPop: () async { + return shouldPop; + }, + child: Scaffold( + appBar: AppBar( + title: const Text('Flutter WillPopScope demo'), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + OutlinedButton( + child: const Text('Push'), + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return const MyStatefulWidget(); + }, + ), + ); + }, + ), + OutlinedButton( + child: Text('shouldPop: $shouldPop'), + onPressed: () { + setState( + () { + shouldPop = !shouldPop; + }, + ); + }, + ), + const Text('Push to a new screen, then tap on shouldPop ' + 'button to toggle its value. Press the back ' + 'button in the appBar to check its behaviour ' + 'for different values of shouldPop'), + ], + ), + ), + ), + ); + } + +//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) +//******************************************************************** + +} diff --git a/examples/api/linux/.gitignore b/examples/api/linux/.gitignore new file mode 100644 index 0000000000..d3896c9844 --- /dev/null +++ b/examples/api/linux/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/examples/api/linux/CMakeLists.txt b/examples/api/linux/CMakeLists.txt new file mode 100644 index 0000000000..fe6a257544 --- /dev/null +++ b/examples/api/linux/CMakeLists.txt @@ -0,0 +1,116 @@ +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) + +set(BINARY_NAME "dartpad_curve2_d_0") +set(APPLICATION_ID "dev.flutter.dartpad_curve2_d_0") + +cmake_policy(SET CMP0063 NEW) + +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Root filesystem for cross-building. +if(FLUTTER_TARGET_PLATFORM_SYSROOT) + set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +# Configure build options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") + +# Flutter library and tool build rules. +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") + +# Application build +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) +apply_standard_settings(${BINARY_NAME}) +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) +add_dependencies(${BINARY_NAME} flutter_assemble) +# Only the install-generated bundle's copy of the executable will launch +# correctly, since the resources must in the right relative locations. To avoid +# people trying to run the unbundled copy, put it in a subdirectory instead of +# the default top-level location. +set_target_properties(${BINARY_NAME} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" +) + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/examples/api/linux/flutter/CMakeLists.txt b/examples/api/linux/flutter/CMakeLists.txt new file mode 100644 index 0000000000..33fd5801e7 --- /dev/null +++ b/examples/api/linux/flutter/CMakeLists.txt @@ -0,0 +1,87 @@ +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/examples/api/linux/flutter/generated_plugin_registrant.cc b/examples/api/linux/flutter/generated_plugin_registrant.cc new file mode 100644 index 0000000000..e71a16d23d --- /dev/null +++ b/examples/api/linux/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void fl_register_plugins(FlPluginRegistry* registry) { +} diff --git a/examples/api/linux/flutter/generated_plugin_registrant.h b/examples/api/linux/flutter/generated_plugin_registrant.h new file mode 100644 index 0000000000..b70b2b16d6 --- /dev/null +++ b/examples/api/linux/flutter/generated_plugin_registrant.h @@ -0,0 +1,19 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void fl_register_plugins(FlPluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/examples/api/linux/flutter/generated_plugins.cmake b/examples/api/linux/flutter/generated_plugins.cmake new file mode 100644 index 0000000000..51436ae8c9 --- /dev/null +++ b/examples/api/linux/flutter/generated_plugins.cmake @@ -0,0 +1,15 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) diff --git a/examples/api/linux/main.cc b/examples/api/linux/main.cc new file mode 100644 index 0000000000..e7c5c54370 --- /dev/null +++ b/examples/api/linux/main.cc @@ -0,0 +1,6 @@ +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/examples/api/linux/my_application.cc b/examples/api/linux/my_application.cc new file mode 100644 index 0000000000..520188d9b2 --- /dev/null +++ b/examples/api/linux/my_application.cc @@ -0,0 +1,104 @@ +#include "my_application.h" + +#include +#ifdef GDK_WINDOWING_X11 +#include +#endif + +#include "flutter/generated_plugin_registrant.h" + +struct _MyApplication { + GtkApplication parent_instance; + char** dart_entrypoint_arguments; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + MyApplication* self = MY_APPLICATION(application); + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + + // Use a header bar when running in GNOME as this is the common style used + // by applications and is the setup most users will be using (e.g. Ubuntu + // desktop). + // If running on X and not using GNOME then just use a traditional title bar + // in case the window manager does more exotic layout, e.g. tiling. + // If running on Wayland assume the header bar will work (may need changing + // if future cases occur). + gboolean use_header_bar = TRUE; +#ifdef GDK_WINDOWING_X11 + GdkScreen* screen = gtk_window_get_screen(window); + if (GDK_IS_X11_SCREEN(screen)) { + const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); + if (g_strcmp0(wm_name, "GNOME Shell") != 0) { + use_header_bar = FALSE; + } + } +#endif + if (use_header_bar) { + GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, "dartpad_curve2_d_0"); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + } else { + gtk_window_set_title(window, "dartpad_curve2_d_0"); + } + + gtk_window_set_default_size(window, 1280, 720); + gtk_widget_show(GTK_WIDGET(window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); + + FlView* view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +// Implements GApplication::local_command_line. +static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { + MyApplication* self = MY_APPLICATION(application); + // Strip out the first argument as it is the binary name. + self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); + + g_autoptr(GError) error = nullptr; + if (!g_application_register(application, nullptr, &error)) { + g_warning("Failed to register: %s", error->message); + *exit_status = 1; + return TRUE; + } + + g_application_activate(application); + *exit_status = 0; + + return TRUE; +} + +// Implements GObject::dispose. +static void my_application_dispose(GObject* object) { + MyApplication* self = MY_APPLICATION(object); + g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); + G_OBJECT_CLASS(my_application_parent_class)->dispose(object); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; + G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; + G_OBJECT_CLASS(klass)->dispose = my_application_dispose; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), + "application-id", APPLICATION_ID, + "flags", G_APPLICATION_NON_UNIQUE, + nullptr)); +} diff --git a/examples/api/linux/my_application.h b/examples/api/linux/my_application.h new file mode 100644 index 0000000000..8c66ec4854 --- /dev/null +++ b/examples/api/linux/my_application.h @@ -0,0 +1,22 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/examples/api/macos/.gitignore b/examples/api/macos/.gitignore new file mode 100644 index 0000000000..d2fd377230 --- /dev/null +++ b/examples/api/macos/.gitignore @@ -0,0 +1,6 @@ +# Flutter-related +**/Flutter/ephemeral/ +**/Pods/ + +# Xcode-related +**/xcuserdata/ diff --git a/examples/api/macos/Flutter/Flutter-Debug.xcconfig b/examples/api/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 0000000000..c2efd0b608 --- /dev/null +++ b/examples/api/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/examples/api/macos/Flutter/Flutter-Release.xcconfig b/examples/api/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 0000000000..c2efd0b608 --- /dev/null +++ b/examples/api/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/examples/api/macos/Runner.xcodeproj/project.pbxproj b/examples/api/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..8f9d77565e --- /dev/null +++ b/examples/api/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,572 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 51; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* dartpad_curve2_d_0.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "dartpad_curve2_d_0.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* dartpad_curve2_d_0.app */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* dartpad_curve2_d_0.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 0930; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/examples/api/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/api/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/examples/api/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/examples/api/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/examples/api/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000..90bb20c848 --- /dev/null +++ b/examples/api/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/api/macos/Runner.xcworkspace/contents.xcworkspacedata b/examples/api/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..1d526a16ed --- /dev/null +++ b/examples/api/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/examples/api/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/api/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/examples/api/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/examples/api/macos/Runner/AppDelegate.swift b/examples/api/macos/Runner/AppDelegate.swift new file mode 100644 index 0000000000..d080d41951 --- /dev/null +++ b/examples/api/macos/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Cocoa +import FlutterMacOS + +@NSApplicationMain +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } +} diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..a2ec33f19f --- /dev/null +++ b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_16.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_64.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_128.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_1024.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png new file mode 100644 index 0000000000..3c4935a7ca Binary files /dev/null and b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png differ diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png new file mode 100644 index 0000000000..ed4cc16421 Binary files /dev/null and b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png differ diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png new file mode 100644 index 0000000000..483be61389 Binary files /dev/null and b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png differ diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png new file mode 100644 index 0000000000..bcbf36df2f Binary files /dev/null and b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png differ diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png new file mode 100644 index 0000000000..9c0a652864 Binary files /dev/null and b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png differ diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png new file mode 100644 index 0000000000..e71a726136 Binary files /dev/null and b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png differ diff --git a/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png new file mode 100644 index 0000000000..8a31fe2dd3 Binary files /dev/null and b/examples/api/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png differ diff --git a/examples/api/macos/Runner/Base.lproj/MainMenu.xib b/examples/api/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 0000000000..537341abf9 --- /dev/null +++ b/examples/api/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,339 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/api/macos/Runner/Configs/AppInfo.xcconfig b/examples/api/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 0000000000..b1c901a3ea --- /dev/null +++ b/examples/api/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = dartpad_curve2_d_0 + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.dartpadCurve2D0 + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2021 dev.flutter. All rights reserved. diff --git a/examples/api/macos/Runner/Configs/Debug.xcconfig b/examples/api/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 0000000000..36b0fd9464 --- /dev/null +++ b/examples/api/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/examples/api/macos/Runner/Configs/Release.xcconfig b/examples/api/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 0000000000..dff4f49561 --- /dev/null +++ b/examples/api/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/examples/api/macos/Runner/Configs/Warnings.xcconfig b/examples/api/macos/Runner/Configs/Warnings.xcconfig new file mode 100644 index 0000000000..42bcbf4780 --- /dev/null +++ b/examples/api/macos/Runner/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/examples/api/macos/Runner/DebugProfile.entitlements b/examples/api/macos/Runner/DebugProfile.entitlements new file mode 100644 index 0000000000..dddb8a30c8 --- /dev/null +++ b/examples/api/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/examples/api/macos/Runner/Info.plist b/examples/api/macos/Runner/Info.plist new file mode 100644 index 0000000000..4789daa6a4 --- /dev/null +++ b/examples/api/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/examples/api/macos/Runner/MainFlutterWindow.swift b/examples/api/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 0000000000..a97a96274e --- /dev/null +++ b/examples/api/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,19 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import Cocoa +import FlutterMacOS + +class MainFlutterWindow: NSWindow { + override func awakeFromNib() { + let flutterViewController = FlutterViewController.init() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + + super.awakeFromNib() + } +} diff --git a/examples/api/macos/Runner/Release.entitlements b/examples/api/macos/Runner/Release.entitlements new file mode 100644 index 0000000000..852fa1a472 --- /dev/null +++ b/examples/api/macos/Runner/Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/examples/api/pubspec.yaml b/examples/api/pubspec.yaml new file mode 100644 index 0000000000..b900c2093d --- /dev/null +++ b/examples/api/pubspec.yaml @@ -0,0 +1,40 @@ +name: flutter_api_samples +description: API code samples for the Flutter repo. +publish_to: 'none' + +version: 1.0.0 + +environment: + sdk: ">=2.14.0-383.0.dev <3.0.0" + flutter: ">=2.5.0-6.0.pre.30 <3.0.0" + +dependencies: + cupertino_icons: 1.0.3 + flutter: + sdk: flutter + flutter_test: + sdk: flutter + + async: 2.8.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + characters: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + charcode: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.15.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + matcher: 0.12.11 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + meta: 1.7.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + path: 1.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.8.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_api: 0.4.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + typed_data: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +flutter: + uses-material-design: true + +# PUBSPEC CHECKSUM: 98bd diff --git a/examples/api/web/favicon.png b/examples/api/web/favicon.png new file mode 100644 index 0000000000..8aaa46ac1a Binary files /dev/null and b/examples/api/web/favicon.png differ diff --git a/examples/api/web/icons/Icon-192.png b/examples/api/web/icons/Icon-192.png new file mode 100644 index 0000000000..b749bfef07 Binary files /dev/null and b/examples/api/web/icons/Icon-192.png differ diff --git a/examples/api/web/icons/Icon-512.png b/examples/api/web/icons/Icon-512.png new file mode 100644 index 0000000000..88cfd48dff Binary files /dev/null and b/examples/api/web/icons/Icon-512.png differ diff --git a/examples/api/web/index.html b/examples/api/web/index.html new file mode 100644 index 0000000000..fb72da87ff --- /dev/null +++ b/examples/api/web/index.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + dartpad_curve2_d_0 + + + + + + + diff --git a/examples/api/web/manifest.json b/examples/api/web/manifest.json new file mode 100644 index 0000000000..1ea6be8c84 --- /dev/null +++ b/examples/api/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "dartpad_curve2_d_0", + "short_name": "dartpad_curve2_d_0", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A temporary code sample for Curve2D", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/examples/api/windows/.gitignore b/examples/api/windows/.gitignore new file mode 100644 index 0000000000..d492d0d98c --- /dev/null +++ b/examples/api/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ephemeral/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/examples/api/windows/CMakeLists.txt b/examples/api/windows/CMakeLists.txt new file mode 100644 index 0000000000..7dfd4a7af1 --- /dev/null +++ b/examples/api/windows/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 3.15) +project(dartpad_curve2_d_0 LANGUAGES CXX) + +set(BINARY_NAME "dartpad_curve2_d_0") + +cmake_policy(SET CMP0063 NEW) + +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Configure build options. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() + +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") + +# Flutter library and tool build rules. +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build +add_subdirectory("runner") + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/examples/api/windows/flutter/CMakeLists.txt b/examples/api/windows/flutter/CMakeLists.txt new file mode 100644 index 0000000000..b02c5485c9 --- /dev/null +++ b/examples/api/windows/flutter/CMakeLists.txt @@ -0,0 +1,103 @@ +cmake_minimum_required(VERSION 3.15) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + windows-x64 $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/examples/api/windows/flutter/generated_plugin_registrant.cc b/examples/api/windows/flutter/generated_plugin_registrant.cc new file mode 100644 index 0000000000..8b6d4680af --- /dev/null +++ b/examples/api/windows/flutter/generated_plugin_registrant.cc @@ -0,0 +1,11 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + + +void RegisterPlugins(flutter::PluginRegistry* registry) { +} diff --git a/examples/api/windows/flutter/generated_plugin_registrant.h b/examples/api/windows/flutter/generated_plugin_registrant.h new file mode 100644 index 0000000000..056c9cb601 --- /dev/null +++ b/examples/api/windows/flutter/generated_plugin_registrant.h @@ -0,0 +1,19 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void RegisterPlugins(flutter::PluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/examples/api/windows/flutter/generated_plugins.cmake b/examples/api/windows/flutter/generated_plugins.cmake new file mode 100644 index 0000000000..4d10c25186 --- /dev/null +++ b/examples/api/windows/flutter/generated_plugins.cmake @@ -0,0 +1,15 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) diff --git a/examples/api/windows/runner/CMakeLists.txt b/examples/api/windows/runner/CMakeLists.txt new file mode 100644 index 0000000000..0b899a0bcf --- /dev/null +++ b/examples/api/windows/runner/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.15) +project(runner LANGUAGES CXX) + +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) +apply_standard_settings(${BINARY_NAME}) +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/examples/api/windows/runner/Runner.rc b/examples/api/windows/runner/Runner.rc new file mode 100644 index 0000000000..1ee9b96c7a --- /dev/null +++ b/examples/api/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +// IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#ifdef FLUTTER_BUILD_NUMBER +#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER +#else +#define VERSION_AS_NUMBER 1,0,0 +#endif + +#ifdef FLUTTER_BUILD_NAME +#define VERSION_AS_STRING #FLUTTER_BUILD_NAME +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "dev.flutter" "\0" + VALUE "FileDescription", "A temporary code sample for Curve2D" "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "dartpad_curve2_d_0" "\0" + VALUE "LegalCopyright", "Copyright (C) 2021 dev.flutter. All rights reserved." "\0" + VALUE "OriginalFilename", "dartpad_curve2_d_0.exe" "\0" + VALUE "ProductName", "dartpad_curve2_d_0" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/examples/api/windows/runner/flutter_window.cpp b/examples/api/windows/runner/flutter_window.cpp new file mode 100644 index 0000000000..b43b9095ea --- /dev/null +++ b/examples/api/windows/runner/flutter_window.cpp @@ -0,0 +1,61 @@ +#include "flutter_window.h" + +#include + +#include "flutter/generated_plugin_registrant.h" + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/examples/api/windows/runner/flutter_window.h b/examples/api/windows/runner/flutter_window.h new file mode 100644 index 0000000000..bbc5836c01 --- /dev/null +++ b/examples/api/windows/runner/flutter_window.h @@ -0,0 +1,37 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/examples/api/windows/runner/main.cpp b/examples/api/windows/runner/main.cpp new file mode 100644 index 0000000000..d05292510d --- /dev/null +++ b/examples/api/windows/runner/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.CreateAndShow(L"dartpad_curve2_d_0", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/examples/api/windows/runner/resource.h b/examples/api/windows/runner/resource.h new file mode 100644 index 0000000000..c245ff19cb --- /dev/null +++ b/examples/api/windows/runner/resource.h @@ -0,0 +1,20 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/examples/api/windows/runner/runner.exe.manifest b/examples/api/windows/runner/runner.exe.manifest new file mode 100644 index 0000000000..c977c4a425 --- /dev/null +++ b/examples/api/windows/runner/runner.exe.manifest @@ -0,0 +1,20 @@ + + + + + PerMonitorV2 + + + + + + + + + + + + + + + diff --git a/examples/api/windows/runner/utils.cpp b/examples/api/windows/runner/utils.cpp new file mode 100644 index 0000000000..d19bdbbcc3 --- /dev/null +++ b/examples/api/windows/runner/utils.cpp @@ -0,0 +1,64 @@ +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr); + if (target_length == 0) { + return std::string(); + } + std::string utf8_string; + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, utf8_string.data(), + target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/examples/api/windows/runner/utils.h b/examples/api/windows/runner/utils.h new file mode 100644 index 0000000000..54414c989b --- /dev/null +++ b/examples/api/windows/runner/utils.h @@ -0,0 +1,23 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/examples/api/windows/runner/win32_window.cpp b/examples/api/windows/runner/win32_window.cpp new file mode 100644 index 0000000000..c10f08dc7d --- /dev/null +++ b/examples/api/windows/runner/win32_window.cpp @@ -0,0 +1,245 @@ +#include "win32_window.h" + +#include + +#include "resource.h" + +namespace { + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + FreeLibrary(user32_module); + } +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + return OnCreate(); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} diff --git a/examples/api/windows/runner/win32_window.h b/examples/api/windows/runner/win32_window.h new file mode 100644 index 0000000000..1dab1777c4 --- /dev/null +++ b/examples/api/windows/runner/win32_window.h @@ -0,0 +1,102 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates and shows a win32 window with |title| and position and size using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size to will treat the width height passed in to this function + // as logical pixels and scale to appropriate for the default monitor. Returns + // true if the window was created successfully. + bool CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responsponds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/flutter/lib/src/animation/curves.dart b/packages/flutter/lib/src/animation/curves.dart index 13dcfbd04e..730e09b1d1 100644 --- a/packages/flutter/lib/src/animation/curves.dart +++ b/packages/flutter/lib/src/animation/curves.dart @@ -412,101 +412,7 @@ class ThreePointCubic extends Curve { /// This example shows how to use a [Curve2D] to modify the position of a widget /// so that it can follow an arbitrary path. /// -/// ```dart preamble -/// // This is the path that the child will follow. It's a CatmullRomSpline so -/// // that the coordinates can be specified that it must pass through. If the -/// // tension is set to 1.0, it will linearly interpolate between those points, -/// // instead of interpolating smoothly. -/// final CatmullRomSpline path = CatmullRomSpline( -/// const [ -/// Offset(0.05, 0.75), -/// Offset(0.18, 0.23), -/// Offset(0.32, 0.04), -/// Offset(0.73, 0.5), -/// Offset(0.42, 0.74), -/// Offset(0.73, 0.01), -/// Offset(0.93, 0.93), -/// Offset(0.05, 0.75), -/// ], -/// startHandle: const Offset(0.93, 0.93), -/// endHandle: const Offset(0.18, 0.23), -/// tension: 0.0, -/// ); -/// -/// class FollowCurve2D extends StatefulWidget { -/// const FollowCurve2D({ -/// Key? key, -/// required this.path, -/// this.curve = Curves.easeInOut, -/// required this.child, -/// this.duration = const Duration(seconds: 1), -/// }) : super(key: key); -/// -/// final Curve2D path; -/// final Curve curve; -/// final Duration duration; -/// final Widget child; -/// -/// @override -/// State createState() => _FollowCurve2DState(); -/// } -/// -/// class _FollowCurve2DState extends State with TickerProviderStateMixin { -/// // The animation controller for this animation. -/// late AnimationController controller; -/// // The animation that will be used to apply the widget's animation curve. -/// late Animation animation; -/// -/// @override -/// void initState() { -/// super.initState(); -/// controller = AnimationController(duration: widget.duration, vsync: this); -/// animation = CurvedAnimation(parent: controller, curve: widget.curve); -/// // Have the controller repeat indefinitely. If you want it to "bounce" back -/// // and forth, set the reverse parameter to true. -/// controller.repeat(reverse: false); -/// controller.addListener(() => setState(() {})); -/// } -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// // Always have to dispose of animation controllers when done. -/// controller.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// // Scale the path values to match the -1.0 to 1.0 domain of the Alignment widget. -/// final Offset position = widget.path.transform(animation.value) * 2.0 - const Offset(1.0, 1.0); -/// return Align( -/// alignment: Alignment(position.dx, position.dy), -/// child: widget.child, -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.white, -/// alignment: Alignment.center, -/// child: FollowCurve2D( -/// path: path, -/// curve: Curves.easeInOut, -/// duration: const Duration(seconds: 3), -/// child: CircleAvatar( -/// backgroundColor: Colors.yellow, -/// child: DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline6!, -/// child: const Text('B'), // Buzz, buzz! -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/animation/curves/curve2_d.0.dart ** /// {@end-tool} /// abstract class Curve2D extends ParametricCurve { diff --git a/packages/flutter/lib/src/cupertino/context_menu.dart b/packages/flutter/lib/src/cupertino/context_menu.dart index 81cb79fa02..0e2e8d322b 100644 --- a/packages/flutter/lib/src/cupertino/context_menu.dart +++ b/packages/flutter/lib/src/cupertino/context_menu.dart @@ -74,45 +74,10 @@ enum _ContextMenuLocation { /// Photos app on iOS. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This sample shows a very simple CupertinoContextMenu for an empty red /// 100x100 Container. Simply long press on it to open. /// -/// ```dart imports -/// import 'package:flutter/cupertino.dart'; -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: SizedBox( -/// width: 100, -/// height: 100, -/// child: CupertinoContextMenu( -/// child: Container( -/// color: Colors.red, -/// ), -/// actions: [ -/// CupertinoContextMenuAction( -/// child: const Text('Action one'), -/// onPressed: () { -/// Navigator.pop(context); -/// }, -/// ), -/// CupertinoContextMenuAction( -/// child: const Text('Action two'), -/// onPressed: () { -/// Navigator.pop(context); -/// }, -/// ), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index e0fccad006..9f16f579e7 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -187,27 +187,7 @@ bool _isTransitionable(BuildContext context) { /// Since [backgroundColor]'s opacity is not 1.0, there is a blur effect and /// content slides underneath. /// -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return CupertinoPageScaffold( -/// navigationBar: CupertinoNavigationBar( -/// // Try removing opacity to observe the lack of a blur effect and of sliding content. -/// backgroundColor: CupertinoColors.systemGrey.withOpacity(0.5), -/// middle: const Text('Sample Code'), -/// ), -/// child: Column( -/// children: [ -/// Container(height: 50, color: CupertinoColors.systemRed), -/// Container(height: 50, color: CupertinoColors.systemGreen), -/// Container(height: 50, color: CupertinoColors.systemBlue), -/// Container(height: 50, color: CupertinoColors.systemYellow), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/cupertino/nav_bar/cupertino_navigation_bar.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/cupertino/page_scaffold.dart b/packages/flutter/lib/src/cupertino/page_scaffold.dart index 5fa3e59b17..25fd92b599 100644 --- a/packages/flutter/lib/src/cupertino/page_scaffold.dart +++ b/packages/flutter/lib/src/cupertino/page_scaffold.dart @@ -23,31 +23,7 @@ import 'theme.dart'; /// The [CupertinoButton] is connected to a callback that increments a counter. /// The [backgroundColor] can be changed. /// -/// ```dart -/// int _count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return CupertinoPageScaffold( -/// // Uncomment to change the background color -/// // backgroundColor: CupertinoColors.systemPink, -/// navigationBar: const CupertinoNavigationBar( -/// middle: Text('Sample Code'), -/// ), -/// child: ListView( -/// children: [ -/// CupertinoButton( -/// onPressed: () => setState(() => _count++), -/// child: const Icon(CupertinoIcons.add), -/// ), -/// Center( -/// child: Text('You have pressed the button $_count times.'), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/cupertino/page_scaffold/cupertino_page_scaffold.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/cupertino/refresh.dart b/packages/flutter/lib/src/cupertino/refresh.dart index 29a69e0365..4712a88877 100644 --- a/packages/flutter/lib/src/cupertino/refresh.dart +++ b/packages/flutter/lib/src/cupertino/refresh.dart @@ -267,53 +267,11 @@ typedef RefreshCallback = Future Function(); /// content's sliver. /// /// {@tool dartpad --template=stateful_widget_cupertino} -/// /// When the user scrolls past [refreshTriggerPullDistance], /// this sample shows the default iOS pull to refresh indicator for 1 second and /// adds a new item to the top of the list view. /// -/// ```dart -/// List colors = [ -/// CupertinoColors.systemYellow, -/// CupertinoColors.systemOrange, -/// CupertinoColors.systemPink -/// ]; -/// List items = [ -/// Container(color: CupertinoColors.systemPink, height: 100.0), -/// Container(color: CupertinoColors.systemOrange, height: 100.0), -/// Container(color: CupertinoColors.systemYellow, height: 100.0), -/// ]; -/// -/// @override -/// Widget build(BuildContext context) { -/// return CupertinoApp( -/// home: CupertinoPageScaffold( -/// child: CustomScrollView( -/// physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), -/// slivers: [ -/// const CupertinoSliverNavigationBar(largeTitle: Text('Scroll down')), -/// CupertinoSliverRefreshControl( -/// refreshTriggerPullDistance: 100.0, -/// refreshIndicatorExtent: 60.0, -/// onRefresh: () async { -/// await Future.delayed(const Duration(milliseconds: 1000)); -/// setState(() { -/// items.insert(0, Container(color: colors[items.length % 3], height: 100.0)); -/// }); -/// }, -/// ), -/// SliverList( -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) => items[index], -/// childCount: items.length, -/// ), -/// ), -/// ], -/// ) -/// ) -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/cupertino/refresh/cupertino_sliver_refresh_control.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index 023d34952b..72c5dec0fa 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart @@ -1128,7 +1128,6 @@ class CupertinoModalPopupRoute extends PopupRoute { /// For more information about state restoration, see [RestorationManager]. /// /// {@tool sample --template=stateless_widget_restoration_cupertino} -/// /// This sample demonstrates how to create a restorable Cupertino modal route. /// This is accomplished by enabling state restoration by specifying /// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to @@ -1136,47 +1135,7 @@ class CupertinoModalPopupRoute extends PopupRoute { /// /// {@macro flutter.widgets.RestorationManager} /// -/// ```dart -/// Widget build(BuildContext context) { -/// return CupertinoPageScaffold( -/// navigationBar: const CupertinoNavigationBar( -/// middle: Text('Home'), -/// ), -/// child: Center(child: CupertinoButton( -/// onPressed: () { -/// Navigator.of(context).restorablePush(_modalBuilder); -/// }, -/// child: const Text('Open Modal'), -/// )), -/// ); -/// } -/// -/// static Route _modalBuilder(BuildContext context, Object? arguments) { -/// return CupertinoModalPopupRoute( -/// builder: (BuildContext context) { -/// return CupertinoActionSheet( -/// title: const Text('Title'), -/// message: const Text('Message'), -/// actions: [ -/// CupertinoActionSheetAction( -/// child: const Text('Action One'), -/// onPressed: () { -/// Navigator.pop(context); -/// }, -/// ), -/// CupertinoActionSheetAction( -/// child: const Text('Action Two'), -/// onPressed: () { -/// Navigator.pop(context); -/// }, -/// ), -/// ], -/// ); -/// }, -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/cupertino/route/show_cupertino_modal_popup.0.dart ** /// {@end-tool} /// /// See also: @@ -1269,7 +1228,6 @@ Widget _buildCupertinoDialogTransitions(BuildContext context, Animation /// For more information about state restoration, see [RestorationManager]. /// /// {@tool sample --template=stateless_widget_restoration_cupertino} -/// /// This sample demonstrates how to create a restorable Cupertino dialog. This is /// accomplished by enabling state restoration by specifying /// [CupertinoApp.restorationScopeId] and using [Navigator.restorablePush] to @@ -1277,38 +1235,7 @@ Widget _buildCupertinoDialogTransitions(BuildContext context, Animation /// /// {@macro flutter.widgets.RestorationManager} /// -/// ```dart -/// Widget build(BuildContext context) { -/// return CupertinoPageScaffold( -/// navigationBar: const CupertinoNavigationBar( -/// middle: Text('Home'), -/// ), -/// child: Center(child: CupertinoButton( -/// onPressed: () { -/// Navigator.of(context).restorablePush(_dialogBuilder); -/// }, -/// child: const Text('Open Dialog'), -/// )), -/// ); -/// } -/// -/// static Route _dialogBuilder(BuildContext context, Object? arguments) { -/// return CupertinoDialogRoute( -/// context: context, -/// builder: (BuildContext context) { -/// return const CupertinoAlertDialog( -/// title: Text('Title'), -/// content: Text('Content'), -/// actions: [ -/// CupertinoDialogAction(child: Text('Yes')), -/// CupertinoDialogAction(child: Text('No')), -/// ], -/// ); -/// }, -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/cupertino/route/show_cupertino_dialog.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/cupertino/scrollbar.dart b/packages/flutter/lib/src/cupertino/scrollbar.dart index 92478cb4e5..62f83c85ea 100644 --- a/packages/flutter/lib/src/cupertino/scrollbar.dart +++ b/packages/flutter/lib/src/cupertino/scrollbar.dart @@ -45,29 +45,7 @@ const double _kScrollbarCrossAxisMargin = 3.0; /// when it is dragged by the user. The `radius` of the scrollbar thumb corners will animate from 34 /// to the `radiusWhileDragging` of 0 when the scrollbar is being dragged by the user. /// -/// ```dart imports -/// import 'package:flutter/cupertino.dart'; -/// ``` -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return CupertinoScrollbar( -/// thickness: 6.0, -/// thicknessWhileDragging: 10.0, -/// radius: const Radius.circular(34.0), -/// radiusWhileDragging: Radius.zero, -/// child: ListView.builder( -/// itemCount: 120, -/// itemBuilder: (BuildContext context, int index) { -/// return Center( -/// child: Text('item $index'), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_scaffold} @@ -75,34 +53,7 @@ const double _kScrollbarCrossAxisMargin = 3.0; /// fade animation. This requires that a [ScrollController] is provided to controller, /// or that the [PrimaryScrollController] is available. /// -/// ```dart imports -/// import 'package:flutter/cupertino.dart'; -/// ``` -/// -/// ```dart -/// final ScrollController _controllerOne = ScrollController(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return CupertinoScrollbar( -/// thickness: 6.0, -/// thicknessWhileDragging: 10.0, -/// radius: const Radius.circular(34.0), -/// radiusWhileDragging: Radius.zero, -/// controller: _controllerOne, -/// isAlwaysShown: true, -/// child: ListView.builder( -/// controller: _controllerOne, -/// itemCount: 120, -/// itemBuilder: (BuildContext context, int index) { -/// return Center( -/// child: Text('item $index'), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/cupertino/scrollbar/cupertino_scrollbar.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/cupertino/text_form_field_row.dart b/packages/flutter/lib/src/cupertino/text_form_field_row.dart index dbab69686c..f2a41adade 100644 --- a/packages/flutter/lib/src/cupertino/text_form_field_row.dart +++ b/packages/flutter/lib/src/cupertino/text_form_field_row.dart @@ -74,40 +74,7 @@ import 'text_field.dart'; /// This example shows how to move the focus to the next field when the user /// presses the SPACE key. /// -/// ```dart imports -/// import 'package:flutter/cupertino.dart'; -/// ``` -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return CupertinoPageScaffold( -/// child: Center( -/// child: Form( -/// autovalidateMode: AutovalidateMode.always, -/// onChanged: () { -/// Form.of(primaryFocus!.context!)?.save(); -/// }, -/// child: CupertinoFormSection.insetGrouped( -/// header: const Text('SECTION 1'), -/// children: List.generate(5, (int index) { -/// return CupertinoTextFormFieldRow( -/// prefix: const Text('Enter text'), -/// placeholder: 'Enter text', -/// validator: (String? value) { -/// if (value == null || value.isEmpty) { -/// return 'Please enter a value'; -/// } -/// return null; -/// }, -/// ); -/// }), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/cupertino/text_form_field_row/cupertino_text_form_field_row.1.dart ** /// {@end-tool} class CupertinoTextFormFieldRow extends FormField { /// Creates a [CupertinoFormRow] containing a [FormField] that wraps diff --git a/packages/flutter/lib/src/gestures/pointer_signal_resolver.dart b/packages/flutter/lib/src/gestures/pointer_signal_resolver.dart index 0208060da3..b5a1dc8564 100644 --- a/packages/flutter/lib/src/gestures/pointer_signal_resolver.dart +++ b/packages/flutter/lib/src/gestures/pointer_signal_resolver.dart @@ -50,118 +50,7 @@ bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) { /// directly under the cursor will change color when the mouse wheel is /// triggered. /// -/// ```dart imports -/// import 'package:flutter/gestures.dart'; -/// ``` -/// -/// ```dart preamble -/// class ColorChanger extends StatefulWidget { -/// const ColorChanger({ -/// Key? key, -/// required this.initialColor, -/// required this.useResolver, -/// this.child, -/// }) : super(key: key); -/// -/// final HSVColor initialColor; -/// final bool useResolver; -/// final Widget? child; -/// -/// @override -/// State createState() => _ColorChangerState(); -/// } -/// -/// class _ColorChangerState extends State { -/// late HSVColor color; -/// -/// void rotateColor() { -/// setState(() { -/// color = color.withHue((color.hue + 3) % 360.0); -/// }); -/// } -/// -/// @override -/// void initState() { -/// super.initState(); -/// color = widget.initialColor; -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return DecoratedBox( -/// decoration: BoxDecoration( -/// border: const Border.fromBorderSide(BorderSide()), -/// color: color.toColor(), -/// ), -/// child: Listener( -/// onPointerSignal: (PointerSignalEvent event) { -/// if (widget.useResolver) { -/// GestureBinding.instance!.pointerSignalResolver.register(event, (PointerSignalEvent event) { -/// rotateColor(); -/// }); -/// } else { -/// rotateColor(); -/// } -/// }, -/// child: Stack( -/// fit: StackFit.expand, -/// children: [ -/// const AbsorbPointer(), -/// if (widget.child != null) widget.child!, -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// bool useResolver = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Material( -/// child: Stack( -/// fit: StackFit.expand, -/// children: [ -/// ColorChanger( -/// initialColor: const HSVColor.fromAHSV(0.2, 120.0, 1, 1), -/// useResolver: useResolver, -/// child: FractionallySizedBox( -/// widthFactor: 0.5, -/// heightFactor: 0.5, -/// child: ColorChanger( -/// initialColor: const HSVColor.fromAHSV(1, 60.0, 1, 1), -/// useResolver: useResolver, -/// ), -/// ), -/// ), -/// Align( -/// alignment: Alignment.topLeft, -/// child: Row( -/// crossAxisAlignment: CrossAxisAlignment.center, -/// children: [ -/// Switch( -/// value: useResolver, -/// onChanged: (bool value) { -/// setState(() { -/// useResolver = value; -/// }); -/// }, -/// ), -/// const Text( -/// 'Use the PointerSignalResolver?', -/// style: TextStyle(fontWeight: FontWeight.bold), -/// ), -/// ], -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/gestures/pointer_signal_resolver/pointer_signal_resolver.0.dart ** /// {@end-tool} class PointerSignalResolver { PointerSignalResolvedCallback? _firstRegisteredCallback; diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index 3129e97ebd..cbea1c9dc3 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -44,74 +44,10 @@ import 'theme.dart'; /// affordance to call [showAboutDialog] or (at least) [showLicensePage]. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This sample shows two ways to open [AboutDialog]. The first one /// uses an [AboutListTile], and the second uses the [showAboutDialog] function. /// -/// ```dart -/// Widget build(BuildContext context) { -/// final ThemeData theme = Theme.of(context); -/// final TextStyle textStyle = theme.textTheme.bodyText2!; -/// final List aboutBoxChildren = [ -/// const SizedBox(height: 24), -/// RichText( -/// text: TextSpan( -/// children: [ -/// TextSpan( -/// style: textStyle, -/// text: "Flutter is Google's UI toolkit for building beautiful, " -/// 'natively compiled applications for mobile, web, and desktop ' -/// 'from a single codebase. Learn more about Flutter at ' -/// ), -/// TextSpan( -/// style: textStyle.copyWith(color: theme.colorScheme.primary), -/// text: 'https://flutter.dev' -/// ), -/// TextSpan( -/// style: textStyle, -/// text: '.' -/// ), -/// ], -/// ), -/// ), -/// ]; -/// -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Show About Example'), -/// ), -/// drawer: Drawer( -/// child: SingleChildScrollView( -/// child: SafeArea( -/// child: AboutListTile( -/// icon: const Icon(Icons.info), -/// applicationIcon: const FlutterLogo(), -/// applicationName: 'Show About Example', -/// applicationVersion: 'August 2019', -/// applicationLegalese: '\u{a9} 2014 The Flutter Authors', -/// aboutBoxChildren: aboutBoxChildren, -/// ), -/// ), -/// ), -/// ), -/// body: Center( -/// child: ElevatedButton( -/// child: const Text('Show About Example'), -/// onPressed: () { -/// showAboutDialog( -/// context: context, -/// applicationIcon: const FlutterLogo(), -/// applicationName: 'Show About Example', -/// applicationVersion: 'August 2019', -/// applicationLegalese: '\u{a9} 2014 The Flutter Authors', -/// children: aboutBoxChildren, -/// ); -/// }, -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/about/about_list_tile.0.dart ** /// {@end-tool} class AboutListTile extends StatelessWidget { /// Creates a list tile for showing an about box. diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 24ae51ab9d..28e5f4c204 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -101,57 +101,10 @@ class _PreferredAppBarSize extends Size { /// stretching to start. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This sample shows an [AppBar] with two simple actions. The first action /// opens a [SnackBar], while the second action navigates to a new page. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('AppBar Demo'), -/// actions: [ -/// IconButton( -/// icon: const Icon(Icons.add_alert), -/// tooltip: 'Show Snackbar', -/// onPressed: () { -/// ScaffoldMessenger.of(context).showSnackBar( -/// const SnackBar(content: Text('This is a snackbar')) -/// ); -/// }, -/// ), -/// IconButton( -/// icon: const Icon(Icons.navigate_next), -/// tooltip: 'Go to the next page', -/// onPressed: () { -/// Navigator.push(context, MaterialPageRoute( -/// builder: (BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Next page'), -/// ), -/// body: const Center( -/// child: Text( -/// 'This is the next page', -/// style: TextStyle(fontSize: 24), -/// ), -/// ), -/// ); -/// }, -/// )); -/// }, -/// ), -/// ], -/// ), -/// body: const Center( -/// child: Text( -/// 'This is the home page', -/// style: TextStyle(fontSize: 24), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/app_bar/app_bar.0.dart ** /// {@end-tool} /// /// ## Troubleshooting @@ -173,29 +126,8 @@ class _PreferredAppBarSize extends Size { /// /// {@tool dartpad --template=stateless_widget_material} /// -/// ```dart -/// Widget build(BuildContext context) { -/// final ButtonStyle style = TextButton.styleFrom( -/// primary: Theme.of(context).colorScheme.onPrimary -/// ); -/// return Scaffold( -/// appBar: AppBar( -/// actions: [ -/// TextButton( -/// style: style, -/// onPressed: () {}, -/// child: const Text('Action 1'), -/// ), -/// TextButton( -/// style: style, -/// onPressed: () {}, -/// child: const Text('Action 2'), -/// ) -/// ], -/// ), -/// ); -/// } -/// ``` +/// +/// ** See code in examples/api/lib/material/app_bar/app_bar.1.dart ** /// {@end-tool} /// /// See also: @@ -1384,110 +1316,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { /// This sample shows a [SliverAppBar] and it's behavior when using the /// [pinned], [snap] and [floating] parameters. /// -/// ```dart -/// bool _pinned = true; -/// bool _snap = false; -/// bool _floating = false; -/// -/// // [SliverAppBar]s are typically used in [CustomScrollView.slivers], which in -/// // turn can be placed in a [Scaffold.body]. -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: CustomScrollView( -/// slivers: [ -/// SliverAppBar( -/// pinned: _pinned, -/// snap: _snap, -/// floating: _floating, -/// expandedHeight: 160.0, -/// flexibleSpace: const FlexibleSpaceBar( -/// title: Text('SliverAppBar'), -/// background: FlutterLogo(), -/// ), -/// ), -/// const SliverToBoxAdapter( -/// child: SizedBox( -/// height: 20, -/// child: Center( -/// child: Text('Scroll to see the SliverAppBar in effect.'), -/// ), -/// ), -/// ), -/// SliverList( -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// return Container( -/// color: index.isOdd ? Colors.white : Colors.black12, -/// height: 100.0, -/// child: Center( -/// child: Text('$index', textScaleFactor: 5), -/// ), -/// ); -/// }, -/// childCount: 20, -/// ), -/// ), -/// ], -/// ), -/// bottomNavigationBar: BottomAppBar( -/// child: Padding( -/// padding: const EdgeInsets.all(8), -/// child: OverflowBar( -/// overflowAlignment: OverflowBarAlignment.center, -/// children: [ -/// Row( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// const Text('pinned'), -/// Switch( -/// onChanged: (bool val) { -/// setState(() { -/// _pinned = val; -/// }); -/// }, -/// value: _pinned, -/// ), -/// ], -/// ), -/// Row( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// const Text('snap'), -/// Switch( -/// onChanged: (bool val) { -/// setState(() { -/// _snap = val; -/// // Snapping only applies when the app bar is floating. -/// _floating = _floating || _snap; -/// }); -/// }, -/// value: _snap, -/// ), -/// ], -/// ), -/// Row( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// const Text('floating'), -/// Switch( -/// onChanged: (bool val) { -/// setState(() { -/// _floating = val; -/// _snap = _snap && _floating; -/// }); -/// }, -/// value: _floating, -/// ), -/// ], -/// ), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/app_bar/sliver_app_bar.1.dart ** /// {@end-tool} /// /// ## Animated Examples diff --git a/packages/flutter/lib/src/material/autocomplete.dart b/packages/flutter/lib/src/material/autocomplete.dart index 19b0d5e7c2..44d270807c 100644 --- a/packages/flutter/lib/src/material/autocomplete.dart +++ b/packages/flutter/lib/src/material/autocomplete.dart @@ -16,144 +16,14 @@ import 'theme.dart'; /// This example shows how to create a very basic Autocomplete widget using the /// default UI. /// -/// ```dart main -/// import 'package:flutter/material.dart'; -/// -/// void main() => runApp(const AutocompleteExampleApp()); -/// -/// class AutocompleteExampleApp extends StatelessWidget { -/// const AutocompleteExampleApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('Autocomplete Basic'), -/// ), -/// body: const Center( -/// child: AutocompleteBasicExample(), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// class AutocompleteBasicExample extends StatelessWidget { -/// const AutocompleteBasicExample({Key? key}) : super(key: key); -/// -/// static const List _kOptions = [ -/// 'aardvark', -/// 'bobcat', -/// 'chameleon', -/// ]; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Autocomplete( -/// optionsBuilder: (TextEditingValue textEditingValue) { -/// if (textEditingValue.text == '') { -/// return const Iterable.empty(); -/// } -/// return _kOptions.where((String option) { -/// return option.contains(textEditingValue.text.toLowerCase()); -/// }); -/// }, -/// onSelected: (String selection) { -/// print('You just selected $selection'); -/// }, -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/material/autocomplete/autocomplete.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=freeform} /// This example shows how to create an Autocomplete widget with a custom type. /// Try searching with text from the name or email field. /// -/// ```dart main -/// import 'package:flutter/material.dart'; -/// -/// void main() => runApp(const AutocompleteExampleApp()); -/// -/// class AutocompleteExampleApp extends StatelessWidget { -/// const AutocompleteExampleApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('Autocomplete Basic User'), -/// ), -/// body: const Center( -/// child: AutocompleteBasicUserExample(), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// @immutable -/// class User { -/// const User({ -/// required this.email, -/// required this.name, -/// }); -/// -/// final String email; -/// final String name; -/// -/// @override -/// String toString() { -/// return '$name, $email'; -/// } -/// -/// @override -/// bool operator ==(Object other) { -/// if (other.runtimeType != runtimeType) { -/// return false; -/// } -/// return other is User -/// && other.name == name -/// && other.email == email; -/// } -/// -/// @override -/// int get hashCode => hashValues(email, name); -/// } -/// -/// class AutocompleteBasicUserExample extends StatelessWidget { -/// const AutocompleteBasicUserExample({Key? key}) : super(key: key); -/// -/// static const List _userOptions = [ -/// User(name: 'Alice', email: 'alice@example.com'), -/// User(name: 'Bob', email: 'bob@example.com'), -/// User(name: 'Charlie', email: 'charlie123@gmail.com'), -/// ]; -/// -/// static String _displayStringForOption(User option) => option.name; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Autocomplete( -/// displayStringForOption: _displayStringForOption, -/// optionsBuilder: (TextEditingValue textEditingValue) { -/// if (textEditingValue.text == '') { -/// return const Iterable.empty(); -/// } -/// return _userOptions.where((User option) { -/// return option.toString().contains(textEditingValue.text.toLowerCase()); -/// }); -/// }, -/// onSelected: (User selection) { -/// print('You just selected ${_displayStringForOption(selection)}'); -/// }, -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/material/autocomplete/autocomplete.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/banner.dart b/packages/flutter/lib/src/material/banner.dart index 61ddab2399..90bffc27ec 100644 --- a/packages/flutter/lib/src/material/banner.dart +++ b/packages/flutter/lib/src/material/banner.dart @@ -55,69 +55,16 @@ enum MaterialBannerClosedReason { /// interact with them at any time. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// Banners placed directly into the widget tree are static. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('The MaterialBanner is below'), -/// ), -/// body: const MaterialBanner( -/// padding: EdgeInsets.all(20), -/// content: Text('Hello, I am a Material Banner'), -/// leading: Icon(Icons.agriculture_outlined), -/// backgroundColor: Color(0xFFE0E0E0), -/// actions: [ -/// TextButton( -/// child: Text('OPEN'), -/// onPressed: null, -/// ), -/// TextButton( -/// child: Text('DISMISS'), -/// onPressed: null, -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/banner/material_banner.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_material} -/// /// MaterialBanner's can also be presented through a [ScaffoldMessenger]. /// Here is an example where ScaffoldMessengerState.showMaterialBanner() is used to show the MaterialBanner. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('The MaterialBanner is below'), -/// ), -/// body: Center( -/// child: ElevatedButton( -/// child: const Text('Show MaterialBanner'), -/// onPressed: () => ScaffoldMessenger.of(context).showMaterialBanner( -/// const MaterialBanner( -/// padding: EdgeInsets.all(20), -/// content: Text('Hello, I am a Material Banner'), -/// leading: Icon(Icons.agriculture_outlined), -/// backgroundColor: Colors.green, -/// actions: [ -/// TextButton( -/// child: Text('DISMISS'), -/// onPressed: null, -/// ), -/// ], -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/banner/material_banner.1.dart ** /// {@end-tool} /// /// The [actions] will be placed beside the [content] if there is only one. diff --git a/packages/flutter/lib/src/material/bottom_app_bar.dart b/packages/flutter/lib/src/material/bottom_app_bar.dart index 11e6f12819..3ed65de192 100644 --- a/packages/flutter/lib/src/material/bottom_app_bar.dart +++ b/packages/flutter/lib/src/material/bottom_app_bar.dart @@ -36,162 +36,8 @@ import 'theme.dart'; /// This example shows the [BottomAppBar], which can be configured to have a notch using the /// [BottomAppBar.shape] property. This also includes an optional [FloatingActionButton], which illustrates /// the [FloatingActionButtonLocation]s in relation to the [BottomAppBar]. -/// ```dart imports -/// import 'package:flutter/material.dart'; -/// ``` /// -/// ```dart -/// void main() { -/// runApp(const BottomAppBarDemo()); -/// } -/// -/// class BottomAppBarDemo extends StatefulWidget { -/// const BottomAppBarDemo({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _BottomAppBarDemoState(); -/// } -/// -/// class _BottomAppBarDemoState extends State { -/// bool _showFab = true; -/// bool _showNotch = true; -/// FloatingActionButtonLocation _fabLocation = FloatingActionButtonLocation.endDocked; -/// -/// void _onShowNotchChanged(bool value) { -/// setState(() { -/// _showNotch = value; -/// }); -/// } -/// -/// void _onShowFabChanged(bool value) { -/// setState(() { -/// _showFab = value; -/// }); -/// } -/// -/// void _onFabLocationChanged(FloatingActionButtonLocation? value) { -/// setState(() { -/// _fabLocation = value ?? FloatingActionButtonLocation.endDocked; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// automaticallyImplyLeading: false, -/// title: const Text('Bottom App Bar Demo'), -/// ), -/// body: ListView( -/// padding: const EdgeInsets.only(bottom: 88), -/// children: [ -/// SwitchListTile( -/// title: const Text( -/// 'Floating Action Button', -/// ), -/// value: _showFab, -/// onChanged: _onShowFabChanged, -/// ), -/// SwitchListTile( -/// title: const Text('Notch'), -/// value: _showNotch, -/// onChanged: _onShowNotchChanged, -/// ), -/// const Padding( -/// padding: EdgeInsets.all(16), -/// child: Text('Floating action button position'), -/// ), -/// RadioListTile( -/// title: const Text('Docked - End'), -/// value: FloatingActionButtonLocation.endDocked, -/// groupValue: _fabLocation, -/// onChanged: _onFabLocationChanged, -/// ), -/// RadioListTile( -/// title: const Text('Docked - Center'), -/// value: FloatingActionButtonLocation.centerDocked, -/// groupValue: _fabLocation, -/// onChanged: _onFabLocationChanged, -/// ), -/// RadioListTile( -/// title: const Text('Floating - End'), -/// value: FloatingActionButtonLocation.endFloat, -/// groupValue: _fabLocation, -/// onChanged: _onFabLocationChanged, -/// ), -/// RadioListTile( -/// title: const Text('Floating - Center'), -/// value: FloatingActionButtonLocation.centerFloat, -/// groupValue: _fabLocation, -/// onChanged: _onFabLocationChanged, -/// ), -/// ], -/// ), -/// floatingActionButton: _showFab -/// ? FloatingActionButton( -/// onPressed: () {}, -/// child: const Icon(Icons.add), -/// tooltip: 'Create', -/// ) -/// : null, -/// floatingActionButtonLocation: _fabLocation, -/// bottomNavigationBar: _DemoBottomAppBar( -/// fabLocation: _fabLocation, -/// shape: _showNotch ? const CircularNotchedRectangle() : null, -/// ), -/// ), -/// ); -/// } -/// } -/// -/// class _DemoBottomAppBar extends StatelessWidget { -/// const _DemoBottomAppBar({ -/// this.fabLocation = FloatingActionButtonLocation.endDocked, -/// this.shape = const CircularNotchedRectangle(), -/// }); -/// -/// final FloatingActionButtonLocation fabLocation; -/// final NotchedShape? shape; -/// -/// static final List centerLocations = [ -/// FloatingActionButtonLocation.centerDocked, -/// FloatingActionButtonLocation.centerFloat, -/// ]; -/// -/// @override -/// Widget build(BuildContext context) { -/// return BottomAppBar( -/// shape: shape, -/// color: Colors.blue, -/// child: IconTheme( -/// data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary), -/// child: Row( -/// children: [ -/// IconButton( -/// tooltip: 'Open navigation menu', -/// icon: const Icon(Icons.menu), -/// onPressed: () {}, -/// ), -/// if (centerLocations.contains(fabLocation)) const Spacer(), -/// IconButton( -/// tooltip: 'Search', -/// icon: const Icon(Icons.search), -/// onPressed: () {}, -/// ), -/// IconButton( -/// tooltip: 'Favorite', -/// icon: const Icon(Icons.favorite), -/// onPressed: () {}, -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// -/// ``` +/// ** See code in examples/api/lib/material/bottom_app_bar/bottom_app_bar.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index bd8de425ef..95ceab736a 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -101,61 +101,7 @@ enum BottomNavigationBarLandscapeLayout { /// amber. The `_onItemTapped` function changes the selected item's index /// and displays a corresponding message in the center of the [Scaffold]. /// -/// ```dart -/// int _selectedIndex = 0; -/// static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold); -/// static const List _widgetOptions = [ -/// Text( -/// 'Index 0: Home', -/// style: optionStyle, -/// ), -/// Text( -/// 'Index 1: Business', -/// style: optionStyle, -/// ), -/// Text( -/// 'Index 2: School', -/// style: optionStyle, -/// ), -/// ]; -/// -/// void _onItemTapped(int index) { -/// setState(() { -/// _selectedIndex = index; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('BottomNavigationBar Sample'), -/// ), -/// body: Center( -/// child: _widgetOptions.elementAt(_selectedIndex), -/// ), -/// bottomNavigationBar: BottomNavigationBar( -/// items: const [ -/// BottomNavigationBarItem( -/// icon: Icon(Icons.home), -/// label: 'Home', -/// ), -/// BottomNavigationBarItem( -/// icon: Icon(Icons.business), -/// label: 'Business', -/// ), -/// BottomNavigationBarItem( -/// icon: Icon(Icons.school), -/// label: 'School', -/// ), -/// ], -/// currentIndex: _selectedIndex, -/// selectedItemColor: Colors.amber[800], -/// onTap: _onItemTapped, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material} @@ -169,74 +115,7 @@ enum BottomNavigationBarLandscapeLayout { /// selected item's index and displays a corresponding message in the center of /// the [Scaffold]. /// -/// -/// ```dart -/// int _selectedIndex = 0; -/// static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold); -/// static const List _widgetOptions = [ -/// Text( -/// 'Index 0: Home', -/// style: optionStyle, -/// ), -/// Text( -/// 'Index 1: Business', -/// style: optionStyle, -/// ), -/// Text( -/// 'Index 2: School', -/// style: optionStyle, -/// ), -/// Text( -/// 'Index 3: Settings', -/// style: optionStyle, -/// ), -/// ]; -/// -/// void _onItemTapped(int index) { -/// setState(() { -/// _selectedIndex = index; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('BottomNavigationBar Sample'), -/// ), -/// body: Center( -/// child: _widgetOptions.elementAt(_selectedIndex), -/// ), -/// bottomNavigationBar: BottomNavigationBar( -/// items: const [ -/// BottomNavigationBarItem( -/// icon: Icon(Icons.home), -/// label: 'Home', -/// backgroundColor: Colors.red, -/// ), -/// BottomNavigationBarItem( -/// icon: Icon(Icons.business), -/// label: 'Business', -/// backgroundColor: Colors.green, -/// ), -/// BottomNavigationBarItem( -/// icon: Icon(Icons.school), -/// label: 'School', -/// backgroundColor: Colors.purple, -/// ), -/// BottomNavigationBarItem( -/// icon: Icon(Icons.settings), -/// label: 'Settings', -/// backgroundColor: Colors.pink, -/// ), -/// ], -/// currentIndex: _selectedIndex, -/// selectedItemColor: Colors.amber[800], -/// onTap: _onItemTapped, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/bottom_navigation_bar/bottom_navigation_bar.1.dart ** /// {@end-tool} /// See also: /// diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index f42dfb09ef..164a812957 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -642,45 +642,12 @@ class _BottomSheetSuspendedCurve extends ParametricCurve { /// [Navigator.pop] when the modal bottom sheet was closed. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This example demonstrates how to use `showModalBottomSheet` to display a /// bottom sheet that obscures the content behind it when a user taps a button. /// It also demonstrates how to close the bottom sheet using the [Navigator] /// when a user taps on a button inside the bottom sheet. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Center( -/// child: ElevatedButton( -/// child: const Text('showModalBottomSheet'), -/// onPressed: () { -/// showModalBottomSheet( -/// context: context, -/// builder: (BuildContext context) { -/// return Container( -/// height: 200, -/// color: Colors.amber, -/// child: Center( -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// const Text('Modal BottomSheet'), -/// ElevatedButton( -/// child: const Text('Close BottomSheet'), -/// onPressed: () => Navigator.pop(context), -/// ) -/// ], -/// ), -/// ), -/// ); -/// }, -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart ** /// {@end-tool} /// See also: /// diff --git a/packages/flutter/lib/src/material/card.dart b/packages/flutter/lib/src/material/card.dart index 4931b34c44..753b7b6aa5 100644 --- a/packages/flutter/lib/src/material/card.dart +++ b/packages/flutter/lib/src/material/card.dart @@ -21,74 +21,21 @@ import 'theme.dart'; /// tickets or listening to the show.](https://flutter.github.io/assets-for-api-docs/assets/material/card.png) /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows creation of a [Card] widget that shows album information /// and two actions. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Center( -/// child: Card( -/// child: Column( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// const ListTile( -/// leading: Icon(Icons.album), -/// title: Text('The Enchanted Nightingale'), -/// subtitle: Text('Music by Julie Gable. Lyrics by Sidney Stein.'), -/// ), -/// Row( -/// mainAxisAlignment: MainAxisAlignment.end, -/// children: [ -/// TextButton( -/// child: const Text('BUY TICKETS'), -/// onPressed: () { /* ... */ }, -/// ), -/// const SizedBox(width: 8), -/// TextButton( -/// child: const Text('LISTEN'), -/// onPressed: () { /* ... */ }, -/// ), -/// const SizedBox(width: 8), -/// ], -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/card/card.0.dart ** /// {@end-tool} /// /// Sometimes the primary action area of a card is the card itself. Cards can be /// one large touch target that shows a detail screen when tapped. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows creation of a [Card] widget that can be tapped. When /// tapped this [Card]'s [InkWell] displays an "ink splash" that fills the /// entire card. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Center( -/// child: Card( -/// child: InkWell( -/// splashColor: Colors.blue.withAlpha(30), -/// onTap: () { -/// print('Card tapped.'); -/// }, -/// child: const SizedBox( -/// width: 300, -/// height: 100, -/// child: Text('A card that can be tapped'), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/material/card/card.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/checkbox.dart b/packages/flutter/lib/src/material/checkbox.dart index ddcd1a8fbb..6e76007ade 100644 --- a/packages/flutter/lib/src/material/checkbox.dart +++ b/packages/flutter/lib/src/material/checkbox.dart @@ -26,41 +26,13 @@ import 'toggleable.dart'; /// Requires one of its ancestors to be a [Material] widget. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// This example shows how you can override the default theme of /// of a [Checkbox] with a [MaterialStateProperty]. /// In this example, the checkbox's color will be `Colors.blue` when the [Checkbox] /// is being pressed, hovered, or focused. Otherwise, the checkbox's color will /// be `Colors.red`. /// -/// ```dart -/// bool isChecked = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// Color getColor(Set states) { -/// const Set interactiveStates = { -/// MaterialState.pressed, -/// MaterialState.hovered, -/// MaterialState.focused, -/// }; -/// if (states.any(interactiveStates.contains)) { -/// return Colors.blue; -/// } -/// return Colors.red; -/// } -/// return Checkbox( -/// checkColor: Colors.white, -/// fillColor: MaterialStateProperty.resolveWith(getColor), -/// value: isChecked, -/// onChanged: (bool? value) { -/// setState(() { -/// isChecked = value!; -/// }); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/checkbox/checkbox.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index c5ff79adc1..07fa6080c8 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -41,7 +41,6 @@ import 'theme_data.dart'; /// callback. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// ![CheckboxListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile.png) /// /// This widget shows a checkbox that, when checked, slows down all animations @@ -50,22 +49,7 @@ import 'theme_data.dart'; /// This sample requires that you also import 'package:flutter/scheduler.dart', /// so that you can reference [timeDilation]. /// -/// ```dart imports -/// import 'package:flutter/scheduler.dart' show timeDilation; -/// ``` -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return CheckboxListTile( -/// title: const Text('Animate Slowly'), -/// value: timeDilation != 1.0, -/// onChanged: (bool? value) { -/// setState(() { timeDilation = value! ? 10.0 : 1.0; }); -/// }, -/// secondary: const Icon(Icons.hourglass_empty), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.0.dart ** /// {@end-tool} /// /// ## Semantics in CheckboxListTile @@ -86,81 +70,13 @@ import 'theme_data.dart'; /// widget to accommodate similar use cases. /// /// {@tool sample --template=stateful_widget_scaffold_center} -/// /// ![Checkbox list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_semantics.png) /// /// Here is an example of a custom labeled checkbox widget, called /// LinkedLabelCheckbox, that includes an interactive [RichText] widget that /// handles tap gestures. /// -/// ```dart imports -/// import 'package:flutter/gestures.dart'; -/// ``` -/// ```dart preamble -/// class LinkedLabelCheckbox extends StatelessWidget { -/// const LinkedLabelCheckbox({ -/// Key? key, -/// required this.label, -/// required this.padding, -/// required this.value, -/// required this.onChanged, -/// }) : super(key: key); -/// -/// final String label; -/// final EdgeInsets padding; -/// final bool value; -/// final ValueChanged onChanged; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Padding( -/// padding: padding, -/// child: Row( -/// children: [ -/// Expanded( -/// child: RichText( -/// text: TextSpan( -/// text: label, -/// style: const TextStyle( -/// color: Colors.blueAccent, -/// decoration: TextDecoration.underline, -/// ), -/// recognizer: TapGestureRecognizer() -/// ..onTap = () { -/// print('Label has been tapped.'); -/// }, -/// ), -/// ), -/// ), -/// Checkbox( -/// value: value, -/// onChanged: (bool? newValue) { -/// onChanged(newValue!); -/// }, -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// ``` -/// ```dart -/// bool _isSelected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return LinkedLabelCheckbox( -/// label: 'Linked, tappable label text', -/// padding: const EdgeInsets.symmetric(horizontal: 20.0), -/// value: _isSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isSelected = newValue; -/// }); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.1.dart ** /// {@end-tool} /// /// ## CheckboxListTile isn't exactly what I want @@ -171,68 +87,12 @@ import 'theme_data.dart'; /// [InkWell]. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// ![Custom checkbox list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/checkbox_list_tile_custom.png) /// /// Here is an example of a custom LabeledCheckbox widget, but you can easily /// make your own configurable widget. /// -/// ```dart preamble -/// class LabeledCheckbox extends StatelessWidget { -/// const LabeledCheckbox({ -/// Key? key, -/// required this.label, -/// required this.padding, -/// required this.value, -/// required this.onChanged, -/// }) : super(key: key); -/// -/// final String label; -/// final EdgeInsets padding; -/// final bool value; -/// final ValueChanged onChanged; -/// -/// @override -/// Widget build(BuildContext context) { -/// return InkWell( -/// onTap: () { -/// onChanged(!value); -/// }, -/// child: Padding( -/// padding: padding, -/// child: Row( -/// children: [ -/// Expanded(child: Text(label)), -/// Checkbox( -/// value: value, -/// onChanged: (bool? newValue) { -/// onChanged(newValue!); -/// }, -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// ```dart -/// bool _isSelected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return LabeledCheckbox( -/// label: 'This is the label text', -/// padding: const EdgeInsets.symmetric(horizontal: 20.0), -/// value: _isSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isSelected = newValue; -/// }); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/checkbox_list_tile/checkbox_list_tile.2.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index cd38df433e..eb994a6c0a 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -219,66 +219,10 @@ abstract class DeletableChipAttributes { /// have to do something similar to the following sample: /// /// {@tool dartpad --template=stateful_widget_scaffold_center} - /// /// This sample shows how to use [onDeleted] to remove an entry when the /// delete button is tapped. /// - /// ```dart preamble - /// class Actor { - /// const Actor(this.name, this.initials); - /// final String name; - /// final String initials; - /// } - /// - /// class CastList extends StatefulWidget { - /// const CastList({Key? key}) : super(key: key); - /// - /// @override - /// State createState() => CastListState(); - /// } - /// - /// class CastListState extends State { - /// final List _cast = [ - /// const Actor('Aaron Burr', 'AB'), - /// const Actor('Alexander Hamilton', 'AH'), - /// const Actor('Eliza Hamilton', 'EH'), - /// const Actor('James Madison', 'JM'), - /// ]; - /// - /// Iterable get actorWidgets sync* { - /// for (final Actor actor in _cast) { - /// yield Padding( - /// padding: const EdgeInsets.all(4.0), - /// child: Chip( - /// avatar: CircleAvatar(child: Text(actor.initials)), - /// label: Text(actor.name), - /// onDeleted: () { - /// setState(() { - /// _cast.removeWhere((Actor entry) { - /// return entry.name == actor.name; - /// }); - /// }); - /// }, - /// ), - /// ); - /// } - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Wrap( - /// children: actorWidgets.toList(), - /// ); - /// } - /// } - /// ``` - /// - /// ```dart - /// @override - /// Widget build(BuildContext context) { - /// return const CastList(); - /// } - /// ``` + /// ** See code in examples/api/lib/material/chip/deletable_chip_attributes.on_deleted.0.dart ** /// {@end-tool} VoidCallback? get onDeleted; diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index 0bc190f2c1..7a796cbe9e 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart @@ -305,7 +305,6 @@ class DataCell { /// multiple pages. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to display a [DataTable] with three columns: name, age, and /// role. The columns are defined by three [DataColumn] objects. The table /// contains three rows of data for three example users, the data for which @@ -313,105 +312,15 @@ class DataCell { /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/data_table.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return DataTable( -/// columns: const [ -/// DataColumn( -/// label: Text( -/// 'Name', -/// style: TextStyle(fontStyle: FontStyle.italic), -/// ), -/// ), -/// DataColumn( -/// label: Text( -/// 'Age', -/// style: TextStyle(fontStyle: FontStyle.italic), -/// ), -/// ), -/// DataColumn( -/// label: Text( -/// 'Role', -/// style: TextStyle(fontStyle: FontStyle.italic), -/// ), -/// ), -/// ], -/// rows: const [ -/// DataRow( -/// cells: [ -/// DataCell(Text('Sarah')), -/// DataCell(Text('19')), -/// DataCell(Text('Student')), -/// ], -/// ), -/// DataRow( -/// cells: [ -/// DataCell(Text('Janine')), -/// DataCell(Text('43')), -/// DataCell(Text('Professor')), -/// ], -/// ), -/// DataRow( -/// cells: [ -/// DataCell(Text('William')), -/// DataCell(Text('27')), -/// DataCell(Text('Associate Professor')), -/// ], -/// ), -/// ], -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/material/data_table/data_table.0.dart ** /// {@end-tool} /// /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// This sample shows how to display a [DataTable] with alternate colors per /// row, and a custom color for when the row is selected. /// -/// ```dart -/// static const int numItems = 10; -/// List selected = List.generate(numItems, (int index) => false); -/// -/// @override -/// Widget build(BuildContext context) { -/// return SizedBox( -/// width: double.infinity, -/// child: DataTable( -/// columns: const [ -/// DataColumn( -/// label: Text('Number'), -/// ), -/// ], -/// rows: List.generate( -/// numItems, -/// (int index) => DataRow( -/// color: MaterialStateProperty.resolveWith((Set states) { -/// // All rows will have the same selected color. -/// if (states.contains(MaterialState.selected)) { -/// return Theme.of(context).colorScheme.primary.withOpacity(0.08); -/// } -/// // Even rows will have a grey color. -/// if (index.isEven) { -/// return Colors.grey.withOpacity(0.3); -/// } -/// return null; // Use default value for other states and odd rows. -/// }), -/// cells: [ DataCell(Text('Row $index')) ], -/// selected: selected[index], -/// onSelectChanged: (bool? value) { -/// setState(() { -/// selected[index] = value!; -/// }); -/// }, -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/data_table/data_table.1.dart ** /// {@end-tool} /// /// [DataTable] can be sorted on the basis of any column in [columns] in diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 71e0a8e880..35bf918599 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -114,75 +114,12 @@ const double _inputFormLandscapeHeight = 108.0; /// {@macro flutter.widgets.RestorationManager} /// /// {@tool sample --template=stateful_widget_restoration_material} -/// /// This sample demonstrates how to create a restorable Material date picker. /// This is accomplished by enabling state restoration by specifying /// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to /// push [DatePickerDialog] when the button is tapped. /// -/// ```dart -/// final RestorableDateTime _selectedDate = RestorableDateTime(DateTime(2021, 7, 25)); -/// late final RestorableRouteFuture _restorableDatePickerRouteFuture = RestorableRouteFuture( -/// onComplete: _selectDate, -/// onPresent: (NavigatorState navigator, Object? arguments) { -/// return navigator.restorablePush( -/// _datePickerRoute, -/// arguments: _selectedDate.value.millisecondsSinceEpoch, -/// ); -/// }, -/// ); -/// -/// static Route _datePickerRoute( -/// BuildContext context, -/// Object? arguments, -/// ) { -/// return DialogRoute( -/// context: context, -/// builder: (BuildContext context) { -/// return DatePickerDialog( -/// restorationId: 'date_picker_dialog', -/// initialEntryMode: DatePickerEntryMode.calendarOnly, -/// initialDate: DateTime.fromMillisecondsSinceEpoch(arguments! as int), -/// firstDate: DateTime(2021, 1, 1), -/// lastDate: DateTime(2022, 1, 1), -/// ); -/// }, -/// ); -/// } -/// -/// @override -/// void restoreState(RestorationBucket? oldBucket, bool initialRestore) { -/// registerForRestoration(_selectedDate, 'selected_date'); -/// registerForRestoration(_restorableDatePickerRouteFuture, 'date_picker_route_future'); -/// } -/// -/// void _selectDate(DateTime? newSelectedDate) { -/// if (newSelectedDate != null) { -/// setState(() { -/// _selectedDate.value = newSelectedDate; -/// ScaffoldMessenger.of(context).showSnackBar(SnackBar( -/// content: Text( -/// 'Selected: ${_selectedDate.value.day}/${_selectedDate.value.month}/${_selectedDate.value.year}'), -/// )); -/// }); -/// } -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: OutlinedButton( -/// onPressed: () { -/// _restorableDatePickerRouteFuture.present(); -/// }, -/// child: const Text('Open Date Picker'), -/// ), -/// ), -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/material/date_picker/show_date_picker.0.dart ** /// {@end-tool} /// /// See also: @@ -938,86 +875,12 @@ class _DatePickerHeader extends StatelessWidget { /// {@macro flutter.widgets.RestorationManager} /// /// {@tool sample --template=stateful_widget_restoration_material} -/// /// This sample demonstrates how to create a restorable Material date range picker. /// This is accomplished by enabling state restoration by specifying /// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to /// push [DateRangePickerDialog] when the button is tapped. /// -/// ```dart -/// final RestorableDateTimeN _startDate = RestorableDateTimeN(DateTime(2021, 1, 1)); -/// final RestorableDateTimeN _endDate = RestorableDateTimeN(DateTime(2021, 1, 5)); -/// late final RestorableRouteFuture _restorableDateRangePickerRouteFuture = RestorableRouteFuture( -/// onComplete: _selectDateRange, -/// onPresent: (NavigatorState navigator, Object? arguments) { -/// return navigator.restorablePush( -/// _dateRangePickerRoute, -/// arguments: { -/// 'initialStartDate': _startDate.value?.millisecondsSinceEpoch, -/// 'initialEndDate': _endDate.value?.millisecondsSinceEpoch, -/// } -/// ); -/// }, -/// ); -/// -/// void _selectDateRange(DateTimeRange? newSelectedDate) { -/// if (newSelectedDate != null) { -/// setState(() { -/// _startDate.value = newSelectedDate.start; -/// _endDate.value = newSelectedDate.end; -/// }); -/// } -/// } -/// -/// @override -/// void restoreState(RestorationBucket? oldBucket, bool initialRestore) { -/// registerForRestoration(_startDate, 'start_date'); -/// registerForRestoration(_endDate, 'end_date'); -/// registerForRestoration(_restorableDateRangePickerRouteFuture, 'date_picker_route_future'); -/// } -/// -/// static Route _dateRangePickerRoute( -/// BuildContext context, -/// Object? arguments, -/// ) { -/// return DialogRoute( -/// context: context, -/// builder: (BuildContext context) { -/// return DateRangePickerDialog( -/// restorationId: 'date_picker_dialog', -/// initialDateRange: _initialDateTimeRange(arguments! as Map), -/// firstDate: DateTime(2021, 1, 1), -/// currentDate: DateTime(2021, 1, 25), -/// lastDate: DateTime(2022, 1, 1), -/// ); -/// }, -/// ); -/// } -/// -/// static DateTimeRange? _initialDateTimeRange(Map arguments) { -/// if (arguments['initialStartDate'] != null && arguments['initialEndDate'] != null) { -/// return DateTimeRange( -/// start: DateTime.fromMillisecondsSinceEpoch(arguments['initialStartDate'] as int), -/// end: DateTime.fromMillisecondsSinceEpoch(arguments['initialEndDate'] as int), -/// ); -/// } -/// -/// return null; -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: OutlinedButton( -/// onPressed: () { _restorableDateRangePickerRouteFuture.present(); }, -/// child: const Text('Open Date Range Picker'), -/// ), -/// ), -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/material/date_picker/show_date_range_picker.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index de9b7ed0b2..14b18684f2 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -218,36 +218,11 @@ class Dialog extends StatelessWidget { /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// This demo shows a [TextButton] which when pressed, calls [showDialog]. When called, this method /// displays a Material dialog above the current contents of the app and returns /// a [Future] that completes when the dialog is dismissed. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return TextButton( -/// onPressed: () => showDialog( -/// context: context, -/// builder: (BuildContext context) => AlertDialog( -/// title: const Text('AlertDialog Title'), -/// content: const Text('AlertDialog description'), -/// actions: [ -/// TextButton( -/// onPressed: () => Navigator.pop(context, 'Cancel'), -/// child: const Text('Cancel'), -/// ), -/// TextButton( -/// onPressed: () => Navigator.pop(context, 'OK'), -/// child: const Text('OK'), -/// ), -/// ], -/// ), -/// ), -/// child: const Text('Show Dialog'), -/// ); -/// } -/// -/// ``` +/// ** See code in examples/api/lib/material/dialog/alert_dialog.1.dart ** /// {@end-tool} /// /// See also: @@ -999,7 +974,6 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation a /// For more information about state restoration, see [RestorationManager]. /// /// {@tool sample --template=stateless_widget_restoration_material} -/// /// This sample demonstrates how to create a restorable Material dialog. This is /// accomplished by enabling state restoration by specifying /// [MaterialApp.restorationScopeId] and using [Navigator.restorablePush] to @@ -1007,28 +981,7 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation a /// /// {@macro flutter.widgets.RestorationManager} /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: OutlinedButton( -/// onPressed: () { -/// Navigator.of(context).restorablePush(_dialogBuilder); -/// }, -/// child: const Text('Open Dialog'), -/// ), -/// ), -/// ); -/// } -/// -/// static Route _dialogBuilder(BuildContext context, Object? arguments) { -/// return DialogRoute( -/// context: context, -/// builder: (BuildContext context) => const AlertDialog(title: Text('Material Alert!')), -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/material/dialog/show_dialog.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/divider.dart b/packages/flutter/lib/src/material/divider.dart index b2e7036486..27d4685699 100644 --- a/packages/flutter/lib/src/material/divider.dart +++ b/packages/flutter/lib/src/material/divider.dart @@ -24,7 +24,6 @@ import 'theme.dart'; /// padding is automatically computed from the height. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to display a Divider between an orange and blue box /// inside a column. The Divider is 20 logical pixels in height and contains a /// vertically centered black line that is 5 logical pixels thick. The black @@ -32,51 +31,7 @@ import 'theme.dart'; /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/divider.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Center( -/// child: Column( -/// children: [ -/// Expanded( -/// child: Container( -/// color: Colors.amber, -/// child: const Center( -/// child: Text('Above'), -/// ), -/// ), -/// ), -/// const Divider( -/// height: 20, -/// thickness: 5, -/// indent: 20, -/// endIndent: 20, -/// ), -/// // Subheader example from Material spec. -/// // https://material.io/components/dividers#types -/// Container( -/// padding: const EdgeInsets.only(left: 20), -/// child: Align( -/// alignment: AlignmentDirectional.centerStart, -/// child: Text( -/// 'Subheader', -/// style: Theme.of(context).textTheme.caption, -/// textAlign: TextAlign.start, -/// ), -/// ), -/// ), -/// Expanded( -/// child: Container( -/// color: Theme.of(context).colorScheme.primary, -/// child: const Center( -/// child: Text('Below'), -/// ), -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/divider/divider.0.dart ** /// {@end-tool} /// See also: /// @@ -231,46 +186,12 @@ class Divider extends StatelessWidget { /// padding is automatically computed from the width. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to display a [VerticalDivider] between an purple and orange box /// inside a [Row]. The [VerticalDivider] is 20 logical pixels in width and contains a /// horizontally centered black line that is 1 logical pixels thick. The grey /// line is indented by 20 logical pixels. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// padding: const EdgeInsets.all(10), -/// child: Row( -/// children: [ -/// Expanded( -/// child: Container( -/// decoration: BoxDecoration( -/// borderRadius: BorderRadius.circular(10), -/// color: Colors.deepPurpleAccent, -/// ), -/// ), -/// ), -/// const VerticalDivider( -/// color: Colors.grey, -/// thickness: 1, -/// indent: 20, -/// endIndent: 0, -/// width: 20, -/// ), -/// Expanded( -/// child: Container( -/// decoration: BoxDecoration( -/// borderRadius: BorderRadius.circular(10), -/// color: Colors.deepOrangeAccent, -/// ), -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/divider/vertical_divider.0.dart ** /// {@end-tool} /// See also: /// diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index baabb57382..f2d31cc31b 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -801,46 +801,13 @@ class DropdownButtonHideUnderline extends InheritedWidget { /// dropdown with the new value. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// This sample shows a `DropdownButton` with a large arrow icon, /// purple text style, and bold purple underline, whose value is one of "One", /// "Two", "Free", or "Four". /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/dropdown_button.png) /// -/// ```dart -/// String dropdownValue = 'One'; -/// -/// @override -/// Widget build(BuildContext context) { -/// return DropdownButton( -/// value: dropdownValue, -/// icon: const Icon(Icons.arrow_downward), -/// iconSize: 24, -/// elevation: 16, -/// style: const TextStyle( -/// color: Colors.deepPurple -/// ), -/// underline: Container( -/// height: 2, -/// color: Colors.deepPurpleAccent, -/// ), -/// onChanged: (String? newValue) { -/// setState(() { -/// dropdownValue = newValue!; -/// }); -/// }, -/// items: ['One', 'Two', 'Free', 'Four'] -/// .map>((String value) { -/// return DropdownMenuItem( -/// value: value, -/// child: Text(value), -/// ); -/// }) -/// .toList(), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/dropdown/dropdown_button.0.dart ** /// {@end-tool} /// /// If the [onChanged] callback is null or the list of [items] is null @@ -989,36 +956,10 @@ class DropdownButton extends StatefulWidget { /// in [items]. /// /// {@tool dartpad --template=stateful_widget_scaffold} - /// /// This sample shows a `DropdownButton` with a button with [Text] that /// corresponds to but is unique from [DropdownMenuItem]. /// - /// ```dart - /// final List items = ['1','2','3']; - /// String selectedItem = '1'; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Padding( - /// padding: const EdgeInsets.symmetric(horizontal: 12.0), - /// child: DropdownButton( - /// value: selectedItem, - /// onChanged: (String? string) => setState(() => selectedItem = string!), - /// selectedItemBuilder: (BuildContext context) { - /// return items.map((String item) { - /// return Text(item); - /// }).toList(); - /// }, - /// items: items.map((String item) { - /// return DropdownMenuItem( - /// child: Text('Log $item'), - /// value: item, - /// ); - /// }).toList(), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/dropdown/dropdown_button.selected_item_builder.0.dart ** /// {@end-tool} /// /// If this callback is null, the [DropdownMenuItem] from [items] @@ -1040,45 +981,10 @@ class DropdownButton extends StatefulWidget { /// the dropdown button, consider using [selectedItemBuilder]. /// /// {@tool dartpad --template=stateful_widget_scaffold} - /// /// This sample shows a `DropdownButton` with a dropdown button text style /// that is different than its menu items. /// - /// ```dart - /// List options = ['One', 'Two', 'Free', 'Four']; - /// String dropdownValue = 'One'; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Container( - /// alignment: Alignment.center, - /// color: Colors.blue, - /// child: DropdownButton( - /// value: dropdownValue, - /// onChanged: (String? newValue) { - /// setState(() { - /// dropdownValue = newValue!; - /// }); - /// }, - /// style: const TextStyle(color: Colors.blue), - /// selectedItemBuilder: (BuildContext context) { - /// return options.map((String value) { - /// return Text( - /// dropdownValue, - /// style: const TextStyle(color: Colors.white), - /// ); - /// }).toList(); - /// }, - /// items: options.map>((String value) { - /// return DropdownMenuItem( - /// value: value, - /// child: Text(value), - /// ); - /// }).toList(), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/dropdown/dropdown_button.style.0.dart ** /// {@end-tool} /// /// Defaults to the [TextTheme.subtitle1] value of the current diff --git a/packages/flutter/lib/src/material/elevated_button.dart b/packages/flutter/lib/src/material/elevated_button.dart index 402fa84fb0..efa7cf01b5 100644 --- a/packages/flutter/lib/src/material/elevated_button.dart +++ b/packages/flutter/lib/src/material/elevated_button.dart @@ -47,36 +47,9 @@ import 'theme_data.dart'; /// button will be disabled. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// This sample produces an enabled and a disabled ElevatedButton. /// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// final ButtonStyle style = -/// ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20)); -/// -/// return Center( -/// child: Column( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// ElevatedButton( -/// style: style, -/// onPressed: null, -/// child: const Text('Disabled'), -/// ), -/// const SizedBox(height: 30), -/// ElevatedButton( -/// style: style, -/// onPressed: () {}, -/// child: const Text('Enabled'), -/// ), -/// ], -/// ), -/// ); -/// } -/// -/// ``` +/// ** See code in examples/api/lib/material/elevated_button/elevated_button.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/expansion_panel.dart b/packages/flutter/lib/src/material/expansion_panel.dart index e275d302db..36a389abbc 100644 --- a/packages/flutter/lib/src/material/expansion_panel.dart +++ b/packages/flutter/lib/src/material/expansion_panel.dart @@ -148,75 +148,9 @@ class ExpansionPanelRadio extends ExpansionPanel { /// and [ExpansionPanelList.radio]. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// Here is a simple example of how to implement ExpansionPanelList. /// -/// ```dart preamble -/// // stores ExpansionPanel state information -/// class Item { -/// Item({ -/// required this.expandedValue, -/// required this.headerValue, -/// this.isExpanded = false, -/// }); -/// -/// String expandedValue; -/// String headerValue; -/// bool isExpanded; -/// } -/// -/// List generateItems(int numberOfItems) { -/// return List.generate(numberOfItems, (int index) { -/// return Item( -/// headerValue: 'Panel $index', -/// expandedValue: 'This is item number $index', -/// ); -/// }); -/// } -/// ``` -/// -/// ```dart -/// final List _data = generateItems(8); -/// -/// @override -/// Widget build(BuildContext context) { -/// return SingleChildScrollView( -/// child: Container( -/// child: _buildPanel(), -/// ), -/// ); -/// } -/// -/// Widget _buildPanel() { -/// return ExpansionPanelList( -/// expansionCallback: (int index, bool isExpanded) { -/// setState(() { -/// _data[index].isExpanded = !isExpanded; -/// }); -/// }, -/// children: _data.map((Item item) { -/// return ExpansionPanel( -/// headerBuilder: (BuildContext context, bool isExpanded) { -/// return ListTile( -/// title: Text(item.headerValue), -/// ); -/// }, -/// body: ListTile( -/// title: Text(item.expandedValue), -/// subtitle: const Text('To delete this panel, tap the trash can icon'), -/// trailing: const Icon(Icons.delete), -/// onTap: () { -/// setState(() { -/// _data.removeWhere((Item currentItem) => item == currentItem); -/// }); -/// } -/// ), -/// isExpanded: item.isExpanded, -/// ); -/// }).toList(), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/expansion_panel/expansion_panel_list.0.dart ** /// {@end-tool} /// /// See also: @@ -252,72 +186,9 @@ class ExpansionPanelList extends StatefulWidget { /// of [ExpansionPanelRadio]. /// /// {@tool dartpad --template=stateful_widget_scaffold} - /// /// Here is a simple example of how to implement ExpansionPanelList.radio. /// - /// ```dart preamble - /// // stores ExpansionPanel state information - /// class Item { - /// Item({ - /// required this.id, - /// required this.expandedValue, - /// required this.headerValue, - /// }); - /// - /// int id; - /// String expandedValue; - /// String headerValue; - /// } - /// - /// List generateItems(int numberOfItems) { - /// return List.generate(numberOfItems, (int index) { - /// return Item( - /// id: index, - /// headerValue: 'Panel $index', - /// expandedValue: 'This is item number $index', - /// ); - /// }); - /// } - /// ``` - /// - /// ```dart - /// final List _data = generateItems(8); - /// - /// @override - /// Widget build(BuildContext context) { - /// return SingleChildScrollView( - /// child: Container( - /// child: _buildPanel(), - /// ), - /// ); - /// } - /// - /// Widget _buildPanel() { - /// return ExpansionPanelList.radio( - /// initialOpenPanelValue: 2, - /// children: _data.map((Item item) { - /// return ExpansionPanelRadio( - /// value: item.id, - /// headerBuilder: (BuildContext context, bool isExpanded) { - /// return ListTile( - /// title: Text(item.headerValue), - /// ); - /// }, - /// body: ListTile( - /// title: Text(item.expandedValue), - /// subtitle: const Text('To delete this panel, tap the trash can icon'), - /// trailing: const Icon(Icons.delete), - /// onTap: () { - /// setState(() { - /// _data.removeWhere((Item currentItem) => item == currentItem); - /// }); - /// } - /// ) - /// ); - /// }).toList(), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart ** /// {@end-tool} const ExpansionPanelList.radio({ Key? key, diff --git a/packages/flutter/lib/src/material/expansion_tile.dart b/packages/flutter/lib/src/material/expansion_tile.dart index a9a15d0add..8f88430684 100644 --- a/packages/flutter/lib/src/material/expansion_tile.dart +++ b/packages/flutter/lib/src/material/expansion_tile.dart @@ -31,50 +31,9 @@ const Duration _kExpand = Duration(milliseconds: 200); /// to the [leading] and [trailing] properties of [ExpansionTile]. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// This example demonstrates different configurations of ExpansionTile. /// -/// ```dart -/// bool _customTileExpanded = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// children: [ -/// const ExpansionTile( -/// title: Text('ExpansionTile 1'), -/// subtitle: Text('Trailing expansion arrow icon'), -/// children: [ -/// ListTile(title: Text('This is tile number 1')), -/// ], -/// ), -/// ExpansionTile( -/// title: const Text('ExpansionTile 2'), -/// subtitle: const Text('Custom expansion arrow icon'), -/// trailing: Icon( -/// _customTileExpanded -/// ? Icons.arrow_drop_down_circle -/// : Icons.arrow_drop_down, -/// ), -/// children: const [ -/// ListTile(title: Text('This is tile number 2')), -/// ], -/// onExpansionChanged: (bool expanded) { -/// setState(() => _customTileExpanded = expanded); -/// }, -/// ), -/// const ExpansionTile( -/// title: Text('ExpansionTile 3'), -/// subtitle: Text('Leading expansion arrow icon'), -/// controlAffinity: ListTileControlAffinity.leading, -/// children: [ -/// ListTile(title: Text('This is tile number 3')), -/// ], -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/expansion_tile/expansion_tile.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/flexible_space_bar.dart b/packages/flutter/lib/src/material/flexible_space_bar.dart index ac617d52e0..5cd8ad1ed1 100644 --- a/packages/flutter/lib/src/material/flexible_space_bar.dart +++ b/packages/flutter/lib/src/material/flexible_space_bar.dart @@ -62,83 +62,7 @@ enum StretchMode { /// `zoomBackground`. The app bar also makes use of [CollapseMode.parallax] by /// default. /// -/// ```dart imports -/// import 'package:flutter/material.dart'; -/// ``` -/// ```dart -/// void main() => runApp(const MaterialApp(home: MyApp())); -/// -/// class MyApp extends StatelessWidget { -/// const MyApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: CustomScrollView( -/// physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), -/// slivers: [ -/// SliverAppBar( -/// stretch: true, -/// onStretchTrigger: () { -/// // Function callback for stretch -/// return Future.value(); -/// }, -/// expandedHeight: 300.0, -/// flexibleSpace: FlexibleSpaceBar( -/// stretchModes: const [ -/// StretchMode.zoomBackground, -/// StretchMode.blurBackground, -/// StretchMode.fadeTitle, -/// ], -/// centerTitle: true, -/// title: const Text('Flight Report'), -/// background: Stack( -/// fit: StackFit.expand, -/// children: [ -/// Image.network( -/// 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg', -/// fit: BoxFit.cover, -/// ), -/// const DecoratedBox( -/// decoration: BoxDecoration( -/// gradient: LinearGradient( -/// begin: Alignment(0.0, 0.5), -/// end: Alignment.center, -/// colors: [ -/// Color(0x60000000), -/// Color(0x00000000), -/// ], -/// ), -/// ), -/// ), -/// ], -/// ), -/// ), -/// ), -/// SliverList( -/// delegate: SliverChildListDelegate( -/// const [ -/// ListTile( -/// leading: Icon(Icons.wb_sunny), -/// title: Text('Sunday'), -/// subtitle: Text('sunny, h: 80, l: 65'), -/// ), -/// ListTile( -/// leading: Icon(Icons.wb_sunny), -/// title: Text('Monday'), -/// subtitle: Text('sunny, h: 80, l: 65'), -/// ), -/// // ListTiles++ -/// ], -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// -/// ``` +/// ** See code in examples/api/lib/material/flexible_space_bar/flexible_space_bar.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index 84863e427f..3fd34fd08e 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -73,25 +73,7 @@ enum _FloatingActionButtonType { /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Floating Action Button'), -/// ), -/// body: const Center( -/// child: Text('Press the button below!') -/// ), -/// floatingActionButton: FloatingActionButton( -/// onPressed: () { -/// // Add your onPressed code here! -/// }, -/// child: const Icon(Icons.navigation), -/// backgroundColor: Colors.green, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/floating_action_button/floating_action_button.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_material} @@ -101,26 +83,7 @@ enum _FloatingActionButtonType { /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/floating_action_button_label.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Floating Action Button Label'), -/// ), -/// body: const Center( -/// child: Text('Press the button with a label below!'), -/// ), -/// floatingActionButton: FloatingActionButton.extended( -/// onPressed: () { -/// // Add your onPressed code here! -/// }, -/// label: const Text('Approve'), -/// icon: const Icon(Icons.thumb_up), -/// backgroundColor: Colors.pink, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/floating_action_button/floating_action_button.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/floating_action_button_location.dart b/packages/flutter/lib/src/material/floating_action_button_location.dart index 8f7cfaaa1b..9a76dcf814 100644 --- a/packages/flutter/lib/src/material/floating_action_button_location.dart +++ b/packages/flutter/lib/src/material/floating_action_button_location.dart @@ -450,7 +450,6 @@ abstract class FloatingActionButtonLocation { /// to implement a custom [FloatingActionButtonLocation]. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This is an example of a user-defined [FloatingActionButtonLocation]. /// /// The example shows a [Scaffold] with an [AppBar], a [BottomAppBar], and a @@ -463,33 +462,7 @@ abstract class FloatingActionButtonLocation { /// [FloatingActionButtonLocation] slightly different from /// [FloatingActionButtonLocation.endFloat]. /// -/// ```dart preamble -/// class AlmostEndFloatFabLocation extends StandardFabLocation -/// with FabEndOffsetX, FabFloatOffsetY { -/// @override -/// double getOffsetX (ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { -/// final double directionalAdjustment = -/// scaffoldGeometry.textDirection == TextDirection.ltr ? -50.0 : 50.0; -/// return super.getOffsetX(scaffoldGeometry, adjustment) + directionalAdjustment; -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Home page'), -/// ), -/// floatingActionButton: FloatingActionButton( -/// onPressed: () { print('FAB pressed.'); }, -/// tooltip: 'Increment', -/// child: const Icon(Icons.add), -/// ), -/// floatingActionButtonLocation: AlmostEndFloatFabLocation(), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/floating_action_button_location/standard_fab_location.0.dart ** /// {@end-tool} /// abstract class StandardFabLocation extends FloatingActionButtonLocation { diff --git a/packages/flutter/lib/src/material/icon_button.dart b/packages/flutter/lib/src/material/icon_button.dart index 4c89d46a31..48dcb38a98 100644 --- a/packages/flutter/lib/src/material/icon_button.dart +++ b/packages/flutter/lib/src/material/icon_button.dart @@ -41,36 +41,12 @@ const double _kMinButtonSize = kMinInteractiveDimension; /// how the icon itself is positioned within the hit region. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// This sample shows an `IconButton` that uses the Material icon "volume_up" to /// increase the volume. /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button.png) /// -/// ```dart preamble -/// double _volume = 0.0; -/// ``` -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// IconButton( -/// icon: const Icon(Icons.volume_up), -/// tooltip: 'Increase volume by 10', -/// onPressed: () { -/// setState(() { -/// _volume += 10; -/// }); -/// }, -/// ), -/// Text('Volume : $_volume') -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/icon_button/icon_button.0.dart ** /// {@end-tool} /// /// ### Adding a filled background @@ -86,7 +62,6 @@ const double _kMinButtonSize = kMinInteractiveDimension; /// [InkResponse] contributed by descendant widgets. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// In this sample the icon button's background color is defined with an [Ink] /// widget whose child is an [IconButton]. The icon button's filled background /// is a light shade of blue, it's a filled circle, and it's as big as the @@ -94,27 +69,7 @@ const double _kMinButtonSize = kMinInteractiveDimension; /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/icon_button_background.png) /// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return Material( -/// color: Colors.white, -/// child: Center( -/// child: Ink( -/// decoration: const ShapeDecoration( -/// color: Colors.lightBlue, -/// shape: CircleBorder(), -/// ), -/// child: IconButton( -/// icon: const Icon(Icons.android), -/// color: Colors.white, -/// onPressed: () {}, -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/icon_button/icon_button.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/ink_well.dart b/packages/flutter/lib/src/material/ink_well.dart index b2e9463992..d006f01e04 100644 --- a/packages/flutter/lib/src/material/ink_well.dart +++ b/packages/flutter/lib/src/material/ink_well.dart @@ -1167,33 +1167,10 @@ class _InkResponseState extends State<_InkResponseStateWidget> /// An example of this situation is as follows: /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// Tap the container to cause it to grow. Then, tap it again and hold before /// the widget reaches its maximum size to observe the clipped ink splash. /// -/// ```dart -/// double sideLength = 50; -/// -/// @override -/// Widget build(BuildContext context) { -/// return AnimatedContainer( -/// height: sideLength, -/// width: sideLength, -/// duration: const Duration(seconds: 2), -/// curve: Curves.easeIn, -/// child: Material( -/// color: Colors.yellow, -/// child: InkWell( -/// onTap: () { -/// setState(() { -/// sideLength == 50 ? sideLength = 100 : sideLength = 50; -/// }); -/// }, -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/ink_well/ink_well.0.dart ** /// {@end-tool} /// /// An InkWell's splashes will not properly update to conform to changes if the diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index a946c4c486..67a5749093 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2409,7 +2409,6 @@ class _InputDecoratorState extends State with TickerProviderStat /// configuration of an [InputDecorator], which does all the heavy lifting.) /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to style a `TextField` using an `InputDecorator`. The /// TextField displays a "send message" icon to the left of the input area, /// which is surrounded by a border an all sides. It displays the `hintText` @@ -2418,82 +2417,37 @@ class _InputDecoratorState extends State with TickerProviderStat /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return const TextField( -/// decoration: InputDecoration( -/// icon: Icon(Icons.send), -/// hintText: 'Hint Text', -/// helperText: 'Helper Text', -/// counterText: '0 characters', -/// border: OutlineInputBorder(), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to style a "collapsed" `TextField` using an /// `InputDecorator`. The collapsed `TextField` surrounds the hint text and /// input area with a border, but does not add padding around them. /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_collapsed.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return const TextField( -/// decoration: InputDecoration.collapsed( -/// hintText: 'Hint Text', -/// border: OutlineInputBorder(), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.1.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to create a `TextField` with hint text, a red border /// on all sides, and an error message. To display a red border and error /// message, provide `errorText` to the `InputDecoration` constructor. /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_error.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return const TextField( -/// decoration: InputDecoration( -/// hintText: 'Hint Text', -/// errorText: 'Error Text', -/// border: OutlineInputBorder(), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.2.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to style a `TextField` with a round border and /// additional text before and after the input area. It displays "Prefix" before /// the input area, and "Suffix" after the input area. /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/input_decoration_prefix_suffix.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return TextFormField( -/// initialValue: 'abc', -/// decoration: const InputDecoration( -/// prefix: Text('Prefix'), -/// suffix: Text('Suffix'), -/// border: OutlineInputBorder(), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/input_decorator/input_decoration.3.dart ** /// {@end-tool} /// /// See also: @@ -2656,37 +2610,10 @@ class InputDecoration { /// otherwise be specified using [labelText], which only takes one [TextStyle]. /// /// {@tool dartpad --template=stateless_widget_scaffold} - /// /// This example shows a `TextField` with a [Text.rich] widget as the [label]. /// The widget contains multiple [Text] widgets with different [TextStyle]'s. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return const Center( - /// child: TextField( - /// decoration: InputDecoration( - /// label: Text.rich( - /// TextSpan( - /// children: [ - /// WidgetSpan( - /// child: Text( - /// 'Username', - /// ), - /// ), - /// WidgetSpan( - /// child: Text( - /// '*', - /// style: TextStyle(color: Colors.red), - /// ), - /// ), - /// ], - /// ), - /// ), - /// ), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.label.0.dart ** /// {@end-tool} /// /// Only one of [label] and [labelText] can be specified. @@ -2899,7 +2826,6 @@ class InputDecoration { /// 48px. /// /// {@tool dartpad --template=stateless_widget_scaffold} - /// /// This example shows the differences between two `TextField` widgets when /// [prefixIconConstraints] is set to the default value and when one is not. /// @@ -2909,36 +2835,7 @@ class InputDecoration { /// If null, [BoxConstraints] with a minimum width and height of 48px is /// used. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return Padding( - /// padding: const EdgeInsets.symmetric(horizontal: 8.0), - /// child: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// children: const [ - /// TextField( - /// decoration: InputDecoration( - /// hintText: 'Normal Icon Constraints', - /// prefixIcon: Icon(Icons.search), - /// ), - /// ), - /// SizedBox(height: 10), - /// TextField( - /// decoration: InputDecoration( - /// isDense: true, - /// hintText:'Smaller Icon Constraints', - /// prefixIcon: Icon(Icons.search), - /// prefixIconConstraints: BoxConstraints( - /// minHeight: 32, - /// minWidth: 32, - /// ), - /// ), - /// ), - /// ], - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.prefix_icon_constraints.0.dart ** /// {@end-tool} final BoxConstraints? prefixIconConstraints; @@ -3077,36 +2974,7 @@ class InputDecoration { /// If null, [BoxConstraints] with a minimum width and height of 48px is /// used. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return Padding( - /// padding: const EdgeInsets.symmetric(horizontal: 8.0), - /// child: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// children: const [ - /// TextField( - /// decoration: InputDecoration( - /// hintText: 'Normal Icon Constraints', - /// suffixIcon: Icon(Icons.search), - /// ), - /// ), - /// SizedBox(height: 10), - /// TextField( - /// decoration: InputDecoration( - /// isDense: true, - /// hintText:'Smaller Icon Constraints', - /// suffixIcon: Icon(Icons.search), - /// suffixIconConstraints: BoxConstraints( - /// minHeight: 32, - /// minWidth: 32, - /// ), - /// ), - /// ), - /// ], - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/input_decorator/input_decoration.suffix_icon_constraints.0.dart ** /// {@end-tool} final BoxConstraints? suffixIconConstraints; diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 2c7702786e..d72d2118c8 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -440,293 +440,22 @@ enum ListTileControlAffinity { /// combination of other widgets, such as [Row]s and [Column]s. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// Here is an example of a custom list item that resembles a YouTube-related /// video list item created with [Expanded] and [Container] widgets. /// /// ![Custom list item a](https://flutter.github.io/assets-for-api-docs/assets/widgets/custom_list_item_a.png) /// -/// ```dart preamble -/// class CustomListItem extends StatelessWidget { -/// const CustomListItem({ -/// Key? key, -/// required this.thumbnail, -/// required this.title, -/// required this.user, -/// required this.viewCount, -/// }) : super(key: key); -/// -/// final Widget thumbnail; -/// final String title; -/// final String user; -/// final int viewCount; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Padding( -/// padding: const EdgeInsets.symmetric(vertical: 5.0), -/// child: Row( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// children: [ -/// Expanded( -/// flex: 2, -/// child: thumbnail, -/// ), -/// Expanded( -/// flex: 3, -/// child: _VideoDescription( -/// title: title, -/// user: user, -/// viewCount: viewCount, -/// ), -/// ), -/// const Icon( -/// Icons.more_vert, -/// size: 16.0, -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// -/// class _VideoDescription extends StatelessWidget { -/// const _VideoDescription({ -/// Key? key, -/// required this.title, -/// required this.user, -/// required this.viewCount, -/// }) : super(key: key); -/// -/// final String title; -/// final String user; -/// final int viewCount; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Padding( -/// padding: const EdgeInsets.fromLTRB(5.0, 0.0, 0.0, 0.0), -/// child: Column( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// children: [ -/// Text( -/// title, -/// style: const TextStyle( -/// fontWeight: FontWeight.w500, -/// fontSize: 14.0, -/// ), -/// ), -/// const Padding(padding: EdgeInsets.symmetric(vertical: 2.0)), -/// Text( -/// user, -/// style: const TextStyle(fontSize: 10.0), -/// ), -/// const Padding(padding: EdgeInsets.symmetric(vertical: 1.0)), -/// Text( -/// '$viewCount views', -/// style: const TextStyle(fontSize: 10.0), -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return ListView( -/// padding: const EdgeInsets.all(8.0), -/// itemExtent: 106.0, -/// children: [ -/// CustomListItem( -/// user: 'Flutter', -/// viewCount: 999000, -/// thumbnail: Container( -/// decoration: const BoxDecoration(color: Colors.blue), -/// ), -/// title: 'The Flutter YouTube Channel', -/// ), -/// CustomListItem( -/// user: 'Dash', -/// viewCount: 884000, -/// thumbnail: Container( -/// decoration: const BoxDecoration(color: Colors.yellow), -/// ), -/// title: 'Announcing Flutter 1.0', -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/list_tile/list_tile.4.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// Here is an example of an article list item with multiline titles and /// subtitles. It utilizes [Row]s and [Column]s, as well as [Expanded] and /// [AspectRatio] widgets to organize its layout. /// /// ![Custom list item b](https://flutter.github.io/assets-for-api-docs/assets/widgets/custom_list_item_b.png) /// -/// ```dart preamble -/// class _ArticleDescription extends StatelessWidget { -/// const _ArticleDescription({ -/// Key? key, -/// required this.title, -/// required this.subtitle, -/// required this.author, -/// required this.publishDate, -/// required this.readDuration, -/// }) : super(key: key); -/// -/// final String title; -/// final String subtitle; -/// final String author; -/// final String publishDate; -/// final String readDuration; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// children: [ -/// Expanded( -/// flex: 1, -/// child: Column( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// children: [ -/// Text( -/// title, -/// maxLines: 2, -/// overflow: TextOverflow.ellipsis, -/// style: const TextStyle( -/// fontWeight: FontWeight.bold, -/// ), -/// ), -/// const Padding(padding: EdgeInsets.only(bottom: 2.0)), -/// Text( -/// subtitle, -/// maxLines: 2, -/// overflow: TextOverflow.ellipsis, -/// style: const TextStyle( -/// fontSize: 12.0, -/// color: Colors.black54, -/// ), -/// ), -/// ], -/// ), -/// ), -/// Expanded( -/// flex: 1, -/// child: Column( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// mainAxisAlignment: MainAxisAlignment.end, -/// children: [ -/// Text( -/// author, -/// style: const TextStyle( -/// fontSize: 12.0, -/// color: Colors.black87, -/// ), -/// ), -/// Text( -/// '$publishDate - $readDuration', -/// style: const TextStyle( -/// fontSize: 12.0, -/// color: Colors.black54, -/// ), -/// ), -/// ], -/// ), -/// ), -/// ], -/// ); -/// } -/// } -/// -/// class CustomListItemTwo extends StatelessWidget { -/// const CustomListItemTwo({ -/// Key? key, -/// required this.thumbnail, -/// required this.title, -/// required this.subtitle, -/// required this.author, -/// required this.publishDate, -/// required this.readDuration, -/// }) : super(key: key); -/// -/// final Widget thumbnail; -/// final String title; -/// final String subtitle; -/// final String author; -/// final String publishDate; -/// final String readDuration; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Padding( -/// padding: const EdgeInsets.symmetric(vertical: 10.0), -/// child: SizedBox( -/// height: 100, -/// child: Row( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// children: [ -/// AspectRatio( -/// aspectRatio: 1.0, -/// child: thumbnail, -/// ), -/// Expanded( -/// child: Padding( -/// padding: const EdgeInsets.fromLTRB(20.0, 0.0, 2.0, 0.0), -/// child: _ArticleDescription( -/// title: title, -/// subtitle: subtitle, -/// author: author, -/// publishDate: publishDate, -/// readDuration: readDuration, -/// ), -/// ), -/// ) -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return ListView( -/// padding: const EdgeInsets.all(10.0), -/// children: [ -/// CustomListItemTwo( -/// thumbnail: Container( -/// decoration: const BoxDecoration(color: Colors.pink), -/// ), -/// title: 'Flutter 1.0 Launch', -/// subtitle: -/// 'Flutter continues to improve and expand its horizons. ' -/// 'This text should max out at two lines and clip', -/// author: 'Dash', -/// publishDate: 'Dec 28', -/// readDuration: '5 mins', -/// ), -/// CustomListItemTwo( -/// thumbnail: Container( -/// decoration: const BoxDecoration(color: Colors.blue), -/// ), -/// title: 'Flutter 1.2 Release - Continual updates to the framework', -/// subtitle: 'Flutter once again improves and makes updates.', -/// author: 'Flutter', -/// publishDate: 'Feb 26', -/// readDuration: '12 mins', -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/list_tile/list_tile.5.dart ** /// {@end-tool} /// /// See also: @@ -908,32 +637,11 @@ class ListTile extends StatelessWidget { /// can be overridden with a [ListTileTheme]. /// /// {@tool dartpad --template=stateful_widget_scaffold} - /// /// Here is an example of using a [StatefulWidget] to keep track of the /// selected index, and using that to set the `selected` property on the /// corresponding [ListTile]. /// - /// ```dart - /// int _selectedIndex = 0; - /// - /// @override - /// Widget build(BuildContext context) { - /// return ListView.builder( - /// itemCount: 10, - /// itemBuilder: (BuildContext context, int index) { - /// return ListTile( - /// title: Text('Item $index'), - /// selected: index == _selectedIndex, - /// onTap: () { - /// setState(() { - /// _selectedIndex = index; - /// }); - /// }, - /// ); - /// }, - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/list_tile/list_tile.selected.0.dart ** /// {@end-tool} final bool selected; diff --git a/packages/flutter/lib/src/material/material_state.dart b/packages/flutter/lib/src/material/material_state.dart index af09d7565a..1e6109719b 100644 --- a/packages/flutter/lib/src/material/material_state.dart +++ b/packages/flutter/lib/src/material/material_state.dart @@ -191,37 +191,10 @@ class _MaterialStateColor extends MaterialStateColor { /// [MaterialStateMouseCursor] and implement the abstract `resolve` method. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// This example defines a mouse cursor that resolves to /// [SystemMouseCursors.forbidden] when its widget is disabled. /// -/// ```dart imports -/// import 'package:flutter/rendering.dart'; -/// ``` -/// -/// ```dart preamble -/// class ListTileCursor extends MaterialStateMouseCursor { -/// @override -/// MouseCursor resolve(Set states) { -/// if (states.contains(MaterialState.disabled)) { -/// return SystemMouseCursors.forbidden; -/// } -/// return SystemMouseCursors.click; -/// } -/// @override -/// String get debugDescription => 'ListTileCursor()'; -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return ListTile( -/// title: const Text('Disabled ListTile'), -/// enabled: false, -/// mouseCursor: ListTileCursor(), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/material_state/material_state_mouse_cursor.0.dart ** /// {@end-tool} /// /// This class should only be used for parameters which are documented to take @@ -312,32 +285,10 @@ class _EnabledAndDisabledMouseCursor extends MaterialStateMouseCursor { /// their support, like [ActionChip.side]. /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This example defines a subclass of [MaterialStateBorderSide], that resolves /// to a red border side when its widget is selected. /// -/// ```dart -/// bool isSelected = true; -/// -/// @override -/// Widget build(BuildContext context) { -/// return FilterChip( -/// label: const Text('Select chip'), -/// selected: isSelected, -/// onSelected: (bool value) { -/// setState(() { -/// isSelected = value; -/// }); -/// }, -/// side: MaterialStateBorderSide.resolveWith((Set states) { -/// if (states.contains(MaterialState.selected)) { -/// return const BorderSide(width: 1, color: Colors.red); -/// } -/// return null; // Defer to default value on the theme or widget. -/// }), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/material_state/material_state_border_side.0.dart ** /// {@end-tool} /// /// This class should only be used for parameters which are documented to take @@ -415,42 +366,11 @@ class _MaterialStateBorderSide extends MaterialStateBorderSide { /// `resolve` method. /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This example defines a subclass of [RoundedRectangleBorder] and an /// implementation of [MaterialStateOutlinedBorder], that resolves to /// [RoundedRectangleBorder] when its widget is selected. /// -/// ```dart preamble -/// class SelectedBorder extends RoundedRectangleBorder implements MaterialStateOutlinedBorder { -/// @override -/// OutlinedBorder? resolve(Set states) { -/// if (states.contains(MaterialState.selected)) { -/// return const RoundedRectangleBorder(); -/// } -/// return null; // Defer to default value on the theme or widget. -/// } -/// } -/// ``` -/// -/// ```dart -/// bool isSelected = true; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Material( -/// child: FilterChip( -/// label: const Text('Select chip'), -/// selected: isSelected, -/// onSelected: (bool value) { -/// setState(() { -/// isSelected = value; -/// }); -/// }, -/// shape: SelectedBorder(), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/material_state/material_state_outlined_border.0.dart ** /// {@end-tool} /// /// This class should only be used for parameters which are documented to take @@ -490,35 +410,13 @@ abstract class MaterialStateOutlinedBorder extends OutlinedBorder implements Mat /// material state properties when their value is needed. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// This example shows how you can override the default text and icon /// color (the "foreground color") of a [TextButton] with a /// [MaterialStateProperty]. In this example, the button's text color /// will be `Colors.blue` when the button is being pressed, hovered, /// or focused. Otherwise, the text color will be `Colors.red`. /// -/// ```dart -/// Widget build(BuildContext context) { -/// Color getColor(Set states) { -/// const Set interactiveStates = { -/// MaterialState.pressed, -/// MaterialState.hovered, -/// MaterialState.focused, -/// }; -/// if (states.any(interactiveStates.contains)) { -/// return Colors.blue; -/// } -/// return Colors.red; -/// } -/// return TextButton( -/// style: ButtonStyle( -/// foregroundColor: MaterialStateProperty.resolveWith(getColor), -/// ), -/// onPressed: () {}, -/// child: const Text('TextButton'), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/material_state/material_state_property.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/navigation_rail.dart b/packages/flutter/lib/src/material/navigation_rail.dart index f8388e29a0..db47605c07 100644 --- a/packages/flutter/lib/src/material/navigation_rail.dart +++ b/packages/flutter/lib/src/material/navigation_rail.dart @@ -36,58 +36,12 @@ import 'theme.dart'; /// for an example. /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This example shows a [NavigationRail] used within a Scaffold with 3 /// [NavigationRailDestination]s. The main content is separated by a divider /// (although elevation on the navigation rail can be used instead). The /// `_selectedIndex` is updated by the `onDestinationSelected` callback. /// -/// ```dart -/// int _selectedIndex = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Row( -/// children: [ -/// NavigationRail( -/// selectedIndex: _selectedIndex, -/// onDestinationSelected: (int index) { -/// setState(() { -/// _selectedIndex = index; -/// }); -/// }, -/// labelType: NavigationRailLabelType.selected, -/// destinations: const [ -/// NavigationRailDestination( -/// icon: Icon(Icons.favorite_border), -/// selectedIcon: Icon(Icons.favorite), -/// label: Text('First'), -/// ), -/// NavigationRailDestination( -/// icon: Icon(Icons.bookmark_border), -/// selectedIcon: Icon(Icons.book), -/// label: Text('Second'), -/// ), -/// NavigationRailDestination( -/// icon: Icon(Icons.star_border), -/// selectedIcon: Icon(Icons.star), -/// label: Text('Third'), -/// ), -/// ], -/// ), -/// const VerticalDivider(thickness: 1, width: 1), -/// // This is the main content. -/// Expanded( -/// child: Center( -/// child: Text('selectedIndex: $_selectedIndex'), -/// ), -/// ) -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/navigation_rail/navigation_rail.0.dart ** /// {@end-tool} /// /// See also: @@ -331,7 +285,6 @@ class NavigationRail extends StatefulWidget { /// widget, such as an animated menu or a [FloatingActionButton] animation. /// /// {@tool dartpad --template=stateless_widget_material} - /// /// This example shows how to use this animation to create a /// [FloatingActionButton] that animates itself between the normal and /// extended states of the [NavigationRail]. @@ -339,45 +292,7 @@ class NavigationRail extends StatefulWidget { /// An instance of `ExtendableFab` would be created for /// [NavigationRail.leading]. /// - /// ```dart dartImports - /// import 'dart:ui'; - /// ``` - /// - /// ```dart - /// Widget build(BuildContext context) { - /// final Animation animation = NavigationRail.extendedAnimation(context); - /// return AnimatedBuilder( - /// animation: animation, - /// builder: (BuildContext context, Widget? child) { - /// // The extended fab has a shorter height than the regular fab. - /// return Container( - /// height: 56, - /// padding: EdgeInsets.symmetric( - /// vertical: lerpDouble(0, 6, animation.value)!, - /// ), - /// child: animation.value == 0 - /// ? FloatingActionButton( - /// child: const Icon(Icons.add), - /// onPressed: () {}, - /// ) - /// : Align( - /// alignment: AlignmentDirectional.centerStart, - /// widthFactor: animation.value, - /// child: Padding( - /// padding: const EdgeInsetsDirectional.only(start: 8), - /// child: FloatingActionButton.extended( - /// icon: const Icon(Icons.add), - /// label: const Text('CREATE'), - /// onPressed: () {}, - /// ), - /// ), - /// ), - /// ); - /// }, - /// ); - /// } - /// ``` - /// + /// ** See code in examples/api/lib/material/navigation_rail/navigation_rail.extended_animation.0.dart ** /// {@end-tool} static Animation extendedAnimation(BuildContext context) { return context.dependOnInheritedWidgetOfExactType<_ExtendedNavigationRailAnimation>()!.animation; diff --git a/packages/flutter/lib/src/material/outlined_button.dart b/packages/flutter/lib/src/material/outlined_button.dart index eb33e9cdc0..8466ca8d72 100644 --- a/packages/flutter/lib/src/material/outlined_button.dart +++ b/packages/flutter/lib/src/material/outlined_button.dart @@ -49,19 +49,9 @@ import 'theme_data.dart'; /// [ButtonStyle.side] properties must be specified. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// Here is an example of a basic [OutlinedButton]. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return OutlinedButton( -/// onPressed: () { -/// print('Received click'); -/// }, -/// child: const Text('Click Me'), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/outlined_button/outlined_button.0.dart ** /// {@end-tool} /// /// The static [styleFrom] method is a convenient way to create a diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index 7f7f8dce5f..535bec8502 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -247,52 +247,9 @@ class _LinearProgressIndicatorPainter extends CustomPainter { /// The indicator can be made taller by wrapping the widget with a [SizedBox]. /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// This example shows a [LinearProgressIndicator] with a changing value. /// -/// ```dart -/// late AnimationController controller; -/// -/// @override -/// void initState() { -/// controller = AnimationController( -/// vsync: this, -/// duration: const Duration(seconds: 5), -/// )..addListener(() { -/// setState(() {}); -/// }); -/// controller.repeat(reverse: true); -/// super.initState(); -/// } -/// -/// @override -/// void dispose() { -/// controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Padding( -/// padding: const EdgeInsets.all(20.0), -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.spaceEvenly, -/// children: [ -/// const Text( -/// 'Linear progress indicator with a fixed color', -/// style: TextStyle(fontSize: 20), -/// ), -/// LinearProgressIndicator( -/// value: controller.value, -/// semanticsLabel: 'Linear progress indicator', -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/progress_indicator/linear_progress_indicator.0.dart ** /// {@end-tool} /// /// See also: @@ -510,52 +467,9 @@ class _CircularProgressIndicatorPainter extends CustomPainter { /// specify a constant color use: `AlwaysStoppedAnimation(color)`. /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// This example shows a [CircularProgressIndicator] with a changing value. /// -/// ```dart -/// late AnimationController controller; -/// -/// @override -/// void initState() { -/// controller = AnimationController( -/// vsync: this, -/// duration: const Duration(seconds: 5), -/// )..addListener(() { -/// setState(() {}); -/// }); -/// controller.repeat(reverse: true); -/// super.initState(); -/// } -/// -/// @override -/// void dispose() { -/// controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Padding( -/// padding: const EdgeInsets.all(20.0), -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.spaceEvenly, -/// children: [ -/// Text( -/// 'Linear progress indicator with a fixed color', -/// style: Theme.of(context).textTheme.headline6, -/// ), -/// CircularProgressIndicator( -/// value: controller.value, -/// semanticsLabel: 'Linear progress indicator', -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/progress_indicator/circular_progress_indicator.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/radio.dart b/packages/flutter/lib/src/material/radio.dart index 0ddeb5b331..ad9b4ff8eb 100644 --- a/packages/flutter/lib/src/material/radio.dart +++ b/packages/flutter/lib/src/material/radio.dart @@ -28,7 +28,6 @@ const double _kInnerRadius = 4.5; /// radio button's [groupValue]. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// Here is an example of Radio widgets wrapped in ListTiles, which is similar /// to what you could get with the RadioListTile widget. /// @@ -44,41 +43,7 @@ const double _kInnerRadius = 4.5; /// /// Requires one of its ancestors to be a [Material] widget. /// -/// ```dart preamble -/// enum SingingCharacter { lafayette, jefferson } -/// ``` -/// -/// ```dart -/// SingingCharacter? _character = SingingCharacter.lafayette; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// children: [ -/// ListTile( -/// title: const Text('Lafayette'), -/// leading: Radio( -/// value: SingingCharacter.lafayette, -/// groupValue: _character, -/// onChanged: (SingingCharacter? value) { -/// setState(() { _character = value; }); -/// }, -/// ), -/// ), -/// ListTile( -/// title: const Text('Thomas Jefferson'), -/// leading: Radio( -/// value: SingingCharacter.jefferson, -/// groupValue: _character, -/// onChanged: (SingingCharacter? value) { -/// setState(() { _character = value; }); -/// }, -/// ), -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/radio/radio.0.dart ** /// {@end-tool} /// /// See also: @@ -204,45 +169,7 @@ class Radio extends StatefulWidget { /// This example shows how to enable deselecting a radio button by setting the /// [toggleable] attribute. /// - /// ```dart - /// int? groupValue; - /// static const List selections = [ - /// 'Hercules Mulligan', - /// 'Eliza Hamilton', - /// 'Philip Schuyler', - /// 'Maria Reynolds', - /// 'Samuel Seabury', - /// ]; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// body: ListView.builder( - /// itemBuilder: (BuildContext context, int index) { - /// return Row( - /// mainAxisSize: MainAxisSize.min, - /// crossAxisAlignment: CrossAxisAlignment.center, - /// children: [ - /// Radio( - /// value: index, - /// groupValue: groupValue, - /// // TRY THIS: Try setting the toggleable value to false and - /// // see how that changes the behavior of the widget. - /// toggleable: true, - /// onChanged: (int? value) { - /// setState(() { - /// groupValue = value; - /// }); - /// }), - /// Text(selections[index]), - /// ], - /// ); - /// }, - /// itemCount: selections.length, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/radio/radio.toggleable.0.dart ** /// {@end-tool} final bool toggleable; diff --git a/packages/flutter/lib/src/material/radio_list_tile.dart b/packages/flutter/lib/src/material/radio_list_tile.dart index f8744e435f..088ddb0d1f 100644 --- a/packages/flutter/lib/src/material/radio_list_tile.dart +++ b/packages/flutter/lib/src/material/radio_list_tile.dart @@ -43,38 +43,12 @@ import 'theme_data.dart'; /// callback. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// ![RadioListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile.png) /// /// This widget shows a pair of radio buttons that control the `_character` /// field. The field is of the type `SingingCharacter`, an enum. /// -/// ```dart preamble -/// enum SingingCharacter { lafayette, jefferson } -/// ``` -/// ```dart -/// SingingCharacter? _character = SingingCharacter.lafayette; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// children: [ -/// RadioListTile( -/// title: const Text('Lafayette'), -/// value: SingingCharacter.lafayette, -/// groupValue: _character, -/// onChanged: (SingingCharacter? value) { setState(() { _character = value; }); }, -/// ), -/// RadioListTile( -/// title: const Text('Thomas Jefferson'), -/// value: SingingCharacter.jefferson, -/// groupValue: _character, -/// onChanged: (SingingCharacter? value) { setState(() { _character = value; }); }, -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/radio_list_tile/radio_list_tile.0.dart ** /// {@end-tool} /// /// ## Semantics in RadioListTile @@ -95,101 +69,13 @@ import 'theme_data.dart'; /// widget to accommodate similar use cases. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// ![Radio list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile_semantics.png) /// /// Here is an example of a custom labeled radio widget, called /// LinkedLabelRadio, that includes an interactive [RichText] widget that /// handles tap gestures. /// -/// ```dart imports -/// import 'package:flutter/gestures.dart'; -/// ``` -/// ```dart preamble -/// class LinkedLabelRadio extends StatelessWidget { -/// const LinkedLabelRadio({ -/// Key? key, -/// required this.label, -/// required this.padding, -/// required this.groupValue, -/// required this.value, -/// required this.onChanged, -/// }) :super(key: key); -/// -/// final String label; -/// final EdgeInsets padding; -/// final bool groupValue; -/// final bool value; -/// final ValueChanged onChanged; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Padding( -/// padding: padding, -/// child: Row( -/// children: [ -/// Radio( -/// groupValue: groupValue, -/// value: value, -/// onChanged: (bool? newValue) { -/// onChanged(newValue!); -/// } -/// ), -/// RichText( -/// text: TextSpan( -/// text: label, -/// style: const TextStyle( -/// color: Colors.blueAccent, -/// decoration: TextDecoration.underline, -/// ), -/// recognizer: TapGestureRecognizer() -/// ..onTap = () { -/// print('Label has been tapped.'); -/// }, -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// ``` -/// ```dart -/// bool _isRadioSelected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// LinkedLabelRadio( -/// label: 'First tappable label text', -/// padding: const EdgeInsets.symmetric(horizontal: 5.0), -/// value: true, -/// groupValue: _isRadioSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isRadioSelected = newValue; -/// }); -/// }, -/// ), -/// LinkedLabelRadio( -/// label: 'Second tappable label text', -/// padding: const EdgeInsets.symmetric(horizontal: 5.0), -/// value: false, -/// groupValue: _isRadioSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isRadioSelected = newValue; -/// }); -/// }, -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/radio_list_tile/radio_list_tile.1.dart ** /// {@end-tool} /// /// ## RadioListTile isn't exactly what I want @@ -200,92 +86,12 @@ import 'theme_data.dart'; /// [InkWell]. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// ![Custom radio list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/radio_list_tile_custom.png) /// /// Here is an example of a custom LabeledRadio widget, but you can easily /// make your own configurable widget. /// -/// ```dart preamble -/// class LabeledRadio extends StatelessWidget { -/// const LabeledRadio({ -/// Key? key, -/// required this.label, -/// required this.padding, -/// required this.groupValue, -/// required this.value, -/// required this.onChanged, -/// }) : super(key: key); -/// -/// final String label; -/// final EdgeInsets padding; -/// final bool groupValue; -/// final bool value; -/// final ValueChanged onChanged; -/// -/// @override -/// Widget build(BuildContext context) { -/// return InkWell( -/// onTap: () { -/// if (value != groupValue) { -/// onChanged(value); -/// } -/// }, -/// child: Padding( -/// padding: padding, -/// child: Row( -/// children: [ -/// Radio( -/// groupValue: groupValue, -/// value: value, -/// onChanged: (bool? newValue) { -/// onChanged(newValue!); -/// }, -/// ), -/// Text(label), -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// ```dart -/// bool _isRadioSelected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// LabeledRadio( -/// label: 'This is the first label text', -/// padding: const EdgeInsets.symmetric(horizontal: 5.0), -/// value: true, -/// groupValue: _isRadioSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isRadioSelected = newValue; -/// }); -/// }, -/// ), -/// LabeledRadio( -/// label: 'This is the second label text', -/// padding: const EdgeInsets.symmetric(horizontal: 5.0), -/// value: false, -/// groupValue: _isRadioSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isRadioSelected = newValue; -/// }); -/// }, -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/radio_list_tile/radio_list_tile.2.dart ** /// {@end-tool} /// /// See also: @@ -395,38 +201,7 @@ class RadioListTile extends StatelessWidget { /// This example shows how to enable deselecting a radio button by setting the /// [toggleable] attribute. /// - /// ```dart - /// int? groupValue; - /// static const List selections = [ - /// 'Hercules Mulligan', - /// 'Eliza Hamilton', - /// 'Philip Schuyler', - /// 'Maria Reynolds', - /// 'Samuel Seabury', - /// ]; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// body: ListView.builder( - /// itemBuilder: (BuildContext context, int index) { - /// return RadioListTile( - /// value: index, - /// groupValue: groupValue, - /// toggleable: true, - /// title: Text(selections[index]), - /// onChanged: (int? value) { - /// setState(() { - /// groupValue = value; - /// }); - /// }, - /// ); - /// }, - /// itemCount: selections.length, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/radio_list_tile/radio_list_tile.toggleable.0.dart ** /// {@end-tool} final bool toggleable; diff --git a/packages/flutter/lib/src/material/range_slider.dart b/packages/flutter/lib/src/material/range_slider.dart index 4f1814753d..83c08f377e 100644 --- a/packages/flutter/lib/src/material/range_slider.dart +++ b/packages/flutter/lib/src/material/range_slider.dart @@ -34,7 +34,6 @@ typedef PaintRangeValueIndicator = void Function(PaintingContext context, Offset /// {@youtube 560 315 https://www.youtube.com/watch?v=ufb4gIPDmEs} /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// ![A range slider widget, consisting of 5 divisions and showing the default /// value indicator.](https://flutter.github.io/assets-for-api-docs/assets/material/range_slider.png) /// @@ -42,28 +41,7 @@ typedef PaintRangeValueIndicator = void Function(PaintingContext context, Offset /// divisions, from 0 to 100. This means are values are split between 0, 20, 40, /// 60, 80, and 100. The range values are initialized with 40 and 80 in this demo. /// -/// ```dart -/// RangeValues _currentRangeValues = const RangeValues(40, 80); -/// -/// @override -/// Widget build(BuildContext context) { -/// return RangeSlider( -/// values: _currentRangeValues, -/// min: 0, -/// max: 100, -/// divisions: 5, -/// labels: RangeLabels( -/// _currentRangeValues.start.round().toString(), -/// _currentRangeValues.end.round().toString(), -/// ), -/// onChanged: (RangeValues values) { -/// setState(() { -/// _currentRangeValues = values; -/// }); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/range_slider/range_slider.0.dart ** /// {@end-tool} /// /// A range slider can be used to select from either a continuous or a discrete diff --git a/packages/flutter/lib/src/material/reorderable_list.dart b/packages/flutter/lib/src/material/reorderable_list.dart index a5f6d5215f..f2fa59d856 100644 --- a/packages/flutter/lib/src/material/reorderable_list.dart +++ b/packages/flutter/lib/src/material/reorderable_list.dart @@ -31,39 +31,8 @@ import 'theme.dart'; /// /// {@tool dartpad --template=stateful_widget_scaffold} /// -/// ```dart -/// final List _items = List.generate(50, (int index) => index); -/// -/// @override -/// Widget build(BuildContext context) { -/// final ColorScheme colorScheme = Theme.of(context).colorScheme; -/// final Color oddItemColor = colorScheme.primary.withOpacity(0.05); -/// final Color evenItemColor = colorScheme.primary.withOpacity(0.15); -/// -/// return ReorderableListView( -/// padding: const EdgeInsets.symmetric(horizontal: 40), -/// children: [ -/// for (int index = 0; index < _items.length; index++) -/// ListTile( -/// key: Key('$index'), -/// tileColor: _items[index].isOdd ? oddItemColor : evenItemColor, -/// title: Text('Item ${_items[index]}'), -/// ), -/// ], -/// onReorder: (int oldIndex, int newIndex) { -/// setState(() { -/// if (oldIndex < newIndex) { -/// newIndex -= 1; -/// } -/// final int item = _items.removeAt(oldIndex); -/// _items.insert(newIndex, item); -/// }); -/// }, -/// ); -/// } -/// -/// ``` /// +/// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.0.dart ** ///{@end-tool} class ReorderableListView extends StatefulWidget { /// Creates a reorderable list from a pre-built list of widgets. @@ -132,38 +101,8 @@ class ReorderableListView extends StatefulWidget { /// list items are built lazily on demand. /// {@tool dartpad --template=stateful_widget_material} /// - /// ```dart - /// final List _items = List.generate(50, (int index) => index); /// - /// @override - /// Widget build(BuildContext context) { - /// final ColorScheme colorScheme = Theme.of(context).colorScheme; - /// final Color oddItemColor = colorScheme.primary.withOpacity(0.05); - /// final Color evenItemColor = colorScheme.primary.withOpacity(0.15); - /// - /// return ReorderableListView.builder( - /// padding: const EdgeInsets.symmetric(horizontal: 40), - /// itemCount:_items.length, - /// itemBuilder: (BuildContext context, int index) { - /// return ListTile( - /// key: Key('$index'), - /// tileColor: _items[index].isOdd ? oddItemColor : evenItemColor, - /// title: Text('Item ${_items[index]}'), - /// ); - /// }, - /// onReorder: (int oldIndex, int newIndex) { - /// setState(() { - /// if (oldIndex < newIndex) { - /// newIndex -= 1; - /// } - /// final int item = _items.removeAt(oldIndex); - /// _items.insert(newIndex, item); - /// }); - /// }, - /// ); - /// } - /// - /// ``` + /// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.reorderable_list_view_builder.0.dart ** /// {@end-tool} /// See also: /// @@ -234,53 +173,8 @@ class ReorderableListView extends StatefulWidget { /// /// {@tool dartpad --template=stateful_widget_scaffold} /// - /// ```dart - /// final List _items = List.generate(50, (int index) => index); /// - /// @override - /// Widget build(BuildContext context) { - /// final ColorScheme colorScheme = Theme.of(context).colorScheme; - /// final Color oddItemColor = colorScheme.primary.withOpacity(0.05); - /// final Color evenItemColor = colorScheme.primary.withOpacity(0.15); - /// - /// return ReorderableListView( - /// buildDefaultDragHandles: false, - /// children: [ - /// for (int index = 0; index < _items.length; index++) - /// Container( - /// key: Key('$index'), - /// color: _items[index].isOdd ? oddItemColor : evenItemColor, - /// child: Row( - /// children: [ - /// Container( - /// width: 64, - /// height: 64, - /// padding: const EdgeInsets.all(8), - /// child: ReorderableDragStartListener( - /// index: index, - /// child: Card( - /// color: colorScheme.primary, - /// elevation: 2, - /// ), - /// ), - /// ), - /// Text('Item ${_items[index]}'), - /// ], - /// ), - /// ), - /// ], - /// onReorder: (int oldIndex, int newIndex) { - /// setState(() { - /// if (oldIndex < newIndex) { - /// newIndex -= 1; - /// } - /// final int item = _items.removeAt(oldIndex); - /// _items.insert(newIndex, item); - /// }); - /// }, - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart ** ///{@end-tool} final bool buildDefaultDragHandles; diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 6842e398ae..ddf398eaf6 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart @@ -74,23 +74,9 @@ enum _ScaffoldSlot { /// ScaffoldMessenger in between the levels of nesting. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// Here is an example of showing a [SnackBar] when the user presses a button. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return OutlinedButton( -/// onPressed: () { -/// ScaffoldMessenger.of(context).showSnackBar( -/// const SnackBar( -/// content: Text('A SnackBar has been shown.'), -/// ), -/// ); -/// }, -/// child: const Text('Show SnackBar'), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/scaffold/scaffold_messenger.0.dart ** /// {@end-tool} /// /// See also: @@ -120,20 +106,7 @@ class ScaffoldMessenger extends StatefulWidget { /// Typical usage of the [ScaffoldMessenger.of] function is to call it in /// response to a user gesture or an application state change. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return ElevatedButton( - /// child: const Text('SHOW A SNACKBAR'), - /// onPressed: () { - /// ScaffoldMessenger.of(context).showSnackBar( - /// const SnackBar( - /// content: Text('Have a snack!'), - /// ), - /// ); - /// }, - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger.of.0.dart ** /// {@end-tool} /// /// A less elegant but more expedient solution is to assign a [GlobalKey] to the @@ -150,65 +123,7 @@ class ScaffoldMessenger extends StatefulWidget { /// example shows a key being used to obtain the [ScaffoldMessengerState] /// provided by the [MaterialApp]. /// - /// ```dart imports - /// import 'package:flutter/material.dart'; - /// ``` - /// ```dart - /// void main() => runApp(const MyApp()); - /// - /// class MyApp extends StatefulWidget { - /// const MyApp({Key? key}) : super(key: key); - /// - /// @override - /// State createState() => _MyAppState(); - /// } - /// - /// class _MyAppState extends State { - /// final GlobalKey _scaffoldMessengerKey = GlobalKey(); - /// int _counter = 0; - /// - /// void _incrementCounter() { - /// setState(() { - /// _counter++; - /// }); - /// if (_counter % 10 == 0) { - /// _scaffoldMessengerKey.currentState!.showSnackBar(const SnackBar( - /// content: Text('A multiple of ten!'), - /// )); - /// } - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return MaterialApp( - /// scaffoldMessengerKey: _scaffoldMessengerKey, - /// home: Scaffold( - /// appBar: AppBar(title: const Text('ScaffoldMessenger Demo')), - /// body: Center( - /// child: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// children: [ - /// const Text( - /// 'You have pushed the button this many times:', - /// ), - /// Text( - /// '$_counter', - /// style: Theme.of(context).textTheme.headline4, - /// ), - /// ], - /// ), - /// ), - /// floatingActionButton: FloatingActionButton( - /// onPressed: _incrementCounter, - /// tooltip: 'Increment', - /// child: const Icon(Icons.add), - /// ), - /// ), - /// ); - /// } - /// } - /// - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger.of.1.dart ** /// {@end-tool} /// /// If there is no [ScaffoldMessenger] in scope, then this will assert in @@ -338,23 +253,9 @@ class ScaffoldMessengerState extends State with TickerProvide /// [ScaffoldMessengerState]. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} - /// /// Here is an example of showing a [SnackBar] when the user presses a button. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return OutlinedButton( - /// onPressed: () { - /// ScaffoldMessenger.of(context).showSnackBar( - /// const SnackBar( - /// content: Text('A SnackBar has been shown.'), - /// ), - /// ); - /// }, - /// child: const Text('Show SnackBar'), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_snack_bar.0.dart ** /// {@end-tool} ScaffoldFeatureController showSnackBar(SnackBar snackBar) { _snackBarController ??= SnackBar.createAnimationController(vsync: this) @@ -478,29 +379,9 @@ class ScaffoldMessengerState extends State with TickerProvide /// [ScaffoldMessengerState]. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} - /// /// Here is an example of showing a [MaterialBanner] when the user presses a button. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return OutlinedButton( - /// onPressed: () { - /// ScaffoldMessenger.of(context).showMaterialBanner( - /// const MaterialBanner( - /// content: Text('This is a MaterialBanner'), - /// actions: [ - /// TextButton( - /// child: Text('DISMISS'), - /// onPressed: null, - /// ), - /// ], - /// ), - /// ); - /// }, - /// child: const Text('Show MaterialBanner'), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold_messenger_state.show_material_banner.0.dart ** /// {@end-tool} ScaffoldFeatureController showMaterialBanner(MaterialBanner materialBanner) { _materialBannerController ??= MaterialBanner.createAnimationController(vsync: this) @@ -1469,26 +1350,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr /// /// ![The Scaffold has a white background with a blue AppBar at the top. A blue FloatingActionButton is positioned at the bottom right corner of the Scaffold.](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold.png) /// -/// ```dart -/// int _count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Sample Code'), -/// ), -/// body: Center( -/// child: Text('You have pressed the button $_count times.') -/// ), -/// floatingActionButton: FloatingActionButton( -/// onPressed: () => setState(() => _count++), -/// tooltip: 'Increment Counter', -/// child: const Icon(Icons.add), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/scaffold/scaffold.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material} @@ -1499,27 +1361,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_background_color.png) /// -/// ```dart -/// int _count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Sample Code'), -/// ), -/// body: Center( -/// child: Text('You have pressed the button $_count times.') -/// ), -/// backgroundColor: Colors.blueGrey.shade200, -/// floatingActionButton: FloatingActionButton( -/// onPressed: () => setState(() => _count++), -/// tooltip: 'Increment Counter', -/// child: const Icon(Icons.add), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/scaffold/scaffold.1.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material} @@ -1532,33 +1374,7 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/material/scaffold_bottom_app_bar.png) /// -/// ```dart -/// int _count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Sample Code'), -/// ), -/// body: Center( -/// child: Text('You have pressed the button $_count times.'), -/// ), -/// bottomNavigationBar: BottomAppBar( -/// shape: const CircularNotchedRectangle(), -/// child: Container(height: 50.0), -/// ), -/// floatingActionButton: FloatingActionButton( -/// onPressed: () => setState(() { -/// _count++; -/// }), -/// tooltip: 'Increment Counter', -/// child: const Icon(Icons.add), -/// ), -/// floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/scaffold/scaffold.2.dart ** /// {@end-tool} /// /// ## Scaffold layout, the keyboard, and display "notches" @@ -1771,47 +1587,7 @@ class Scaffold extends StatefulWidget { /// [ScaffoldState.openDrawer] to open the drawer and [Navigator.pop] to close /// it. /// - /// ```dart - /// final GlobalKey _scaffoldKey = GlobalKey(); - /// - /// void _openDrawer() { - /// _scaffoldKey.currentState!.openDrawer(); - /// } - /// - /// void _closeDrawer() { - /// Navigator.of(context).pop(); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// key: _scaffoldKey, - /// appBar: AppBar(title: const Text('Drawer Demo')), - /// body: Center( - /// child: ElevatedButton( - /// onPressed: _openDrawer, - /// child: const Text('Open Drawer'), - /// ), - /// ), - /// drawer: Drawer( - /// child: Center( - /// child: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// children: [ - /// const Text('This is the Drawer'), - /// ElevatedButton( - /// onPressed: _closeDrawer, - /// child: const Text('Close Drawer'), - /// ), - /// ], - /// ), - /// ), - /// ), - /// // Disable opening the drawer with a swipe gesture. - /// drawerEnableOpenDragGesture: false, - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold.drawer.0.dart ** /// {@end-tool} final Widget? drawer; @@ -1834,47 +1610,7 @@ class Scaffold extends StatefulWidget { /// [ScaffoldState.openEndDrawer] to open the drawer and [Navigator.pop] to /// close it. /// - /// ```dart - /// final GlobalKey _scaffoldKey = GlobalKey(); - /// - /// void _openEndDrawer() { - /// _scaffoldKey.currentState!.openEndDrawer(); - /// } - /// - /// void _closeEndDrawer() { - /// Navigator.of(context).pop(); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// key: _scaffoldKey, - /// appBar: AppBar(title: const Text('Drawer Demo')), - /// body: Center( - /// child: ElevatedButton( - /// onPressed: _openEndDrawer, - /// child: const Text('Open End Drawer'), - /// ), - /// ), - /// endDrawer: Drawer( - /// child: Center( - /// child: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// children: [ - /// const Text('This is the Drawer'), - /// ElevatedButton( - /// onPressed: _closeEndDrawer, - /// child: const Text('Close Drawer'), - /// ), - /// ], - /// ), - /// ), - /// ), - /// // Disable opening the end drawer with a swipe gesture. - /// endDrawerEnableOpenDragGesture: false, - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold.end_drawer.0.dart ** /// {@end-tool} final Widget? endDrawer; @@ -2003,75 +1739,7 @@ class Scaffold extends StatefulWidget { /// Typical usage of the [Scaffold.of] function is to call it from within the /// `build` method of a child of a [Scaffold]. /// - /// ```dart imports - /// import 'package:flutter/material.dart'; - /// ``` - /// - /// ```dart main - /// void main() => runApp(const MyApp()); - /// ``` - /// - /// ```dart preamble - /// class MyApp extends StatelessWidget { - /// const MyApp({Key? key}) : super(key: key); - /// - /// // This widget is the root of your application. - /// @override - /// Widget build(BuildContext context) { - /// return MaterialApp( - /// title: 'Flutter Code Sample for Scaffold.of.', - /// theme: ThemeData( - /// primarySwatch: Colors.blue, - /// ), - /// home: Scaffold( - /// body: const MyScaffoldBody(), - /// appBar: AppBar(title: const Text('Scaffold.of Example')), - /// ), - /// color: Colors.white, - /// ); - /// } - /// } - /// ``` - /// - /// ```dart - /// class MyScaffoldBody extends StatelessWidget { - /// const MyScaffoldBody({Key? key}) : super(key: key); - /// - /// @override - /// Widget build(BuildContext context) { - /// return Center( - /// child: ElevatedButton( - /// child: const Text('SHOW BOTTOM SHEET'), - /// onPressed: () { - /// Scaffold.of(context).showBottomSheet( - /// (BuildContext context) { - /// return Container( - /// alignment: Alignment.center, - /// height: 200, - /// color: Colors.amber, - /// child: Center( - /// child: Column( - /// mainAxisSize: MainAxisSize.min, - /// children: [ - /// const Text('BottomSheet'), - /// ElevatedButton( - /// child: const Text('Close BottomSheet'), - /// onPressed: () { - /// Navigator.pop(context); - /// }, - /// ) - /// ], - /// ), - /// ), - /// ); - /// }, - /// ); - /// }, - /// ), - /// ); - /// } - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold.of.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_material} @@ -2082,49 +1750,7 @@ class Scaffold extends StatefulWidget { /// to provide a new scope with a [BuildContext] that is "under" the /// [Scaffold]: /// - /// ```dart - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar(title: const Text('Demo')), - /// body: Builder( - /// // Create an inner BuildContext so that the onPressed methods - /// // can refer to the Scaffold with Scaffold.of(). - /// builder: (BuildContext context) { - /// return Center( - /// child: ElevatedButton( - /// child: const Text('SHOW BOTTOM SHEET'), - /// onPressed: () { - /// Scaffold.of(context).showBottomSheet( - /// (BuildContext context) { - /// return Container( - /// alignment: Alignment.center, - /// height: 200, - /// color: Colors.amber, - /// child: Center( - /// child: Column( - /// mainAxisSize: MainAxisSize.min, - /// children: [ - /// const Text('BottomSheet'), - /// ElevatedButton( - /// child: const Text('Close BottomSheet'), - /// onPressed: () { - /// Navigator.pop(context); - /// }, - /// ) - /// ], - /// ), - /// ), - /// ); - /// }, - /// ); - /// }, - /// ), - /// ); - /// }, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold.of.1.dart ** /// {@end-tool} /// /// A more efficient solution is to split your build function into several @@ -2401,23 +2027,9 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto /// [ScaffoldMessengerState]. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} - /// /// Here is an example of showing a [SnackBar] when the user presses a button. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return OutlinedButton( - /// onPressed: () { - /// ScaffoldMessenger.of(context).showSnackBar( - /// const SnackBar( - /// content: Text('A SnackBar has been shown.'), - /// ), - /// ); - /// }, - /// child: const Text('Show SnackBar'), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold_state.show_snack_bar.0.dart ** /// {@end-tool} /// /// See also: @@ -2818,45 +2430,11 @@ class ScaffoldState extends State with TickerProviderStateMixin, Resto /// [showModalBottomSheet] function. /// /// {@tool dartpad --template=stateless_widget_scaffold} - /// /// This example demonstrates how to use `showBottomSheet` to display a /// bottom sheet when a user taps a button. It also demonstrates how to /// close a bottom sheet using the Navigator. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return Center( - /// child: ElevatedButton( - /// child: const Text('showBottomSheet'), - /// onPressed: () { - /// Scaffold.of(context).showBottomSheet( - /// (BuildContext context) { - /// return Container( - /// height: 200, - /// color: Colors.amber, - /// child: Center( - /// child: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// mainAxisSize: MainAxisSize.min, - /// children: [ - /// const Text('BottomSheet'), - /// ElevatedButton( - /// child: const Text('Close BottomSheet'), - /// onPressed: () { - /// Navigator.pop(context); - /// } - /// ) - /// ], - /// ), - /// ), - /// ); - /// }, - /// ); - /// }, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/scaffold/scaffold_state.show_bottom_sheet.0.dart ** /// {@end-tool} /// See also: /// diff --git a/packages/flutter/lib/src/material/scrollbar.dart b/packages/flutter/lib/src/material/scrollbar.dart index 22500e7110..15009f4fbb 100644 --- a/packages/flutter/lib/src/material/scrollbar.dart +++ b/packages/flutter/lib/src/material/scrollbar.dart @@ -37,50 +37,16 @@ const Duration _kScrollbarTimeToFade = Duration(milliseconds: 600); /// {@tool dartpad --template=stateless_widget_scaffold} /// This sample shows a [Scrollbar] that executes a fade animation as scrolling occurs. /// The Scrollbar will fade into view as the user scrolls, and fade out when scrolling stops. -/// ```dart -/// Widget build(BuildContext context) { -/// return Scrollbar( -/// child: GridView.builder( -/// itemCount: 120, -/// gridDelegate: -/// const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), -/// itemBuilder: (BuildContext context, int index) { -/// return Center( -/// child: Text('item $index'), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// +/// ** See code in examples/api/lib/material/scrollbar/scrollbar.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_scaffold} /// When isAlwaysShown is true, the scrollbar thumb will remain visible without the /// fade animation. This requires that a ScrollController is provided to controller, /// or that the PrimaryScrollController is available. -/// ```dart -/// final ScrollController _controllerOne = ScrollController(); /// -/// @override -/// Widget build(BuildContext context) { -/// return Scrollbar( -/// controller: _controllerOne, -/// isAlwaysShown: true, -/// child: GridView.builder( -/// controller: _controllerOne, -/// itemCount: 120, -/// gridDelegate: -/// const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), -/// itemBuilder: (BuildContext context, int index) { -/// return Center( -/// child: Text('item $index'), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/scrollbar/scrollbar.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/slider.dart b/packages/flutter/lib/src/material/slider.dart index 50ddee5f8e..1d2c60fb7c 100644 --- a/packages/flutter/lib/src/material/slider.dart +++ b/packages/flutter/lib/src/material/slider.dart @@ -39,32 +39,13 @@ enum _SliderType { material, adaptive } /// {@youtube 560 315 https://www.youtube.com/watch?v=ufb4gIPDmEs} /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// ![A slider widget, consisting of 5 divisions and showing the default value /// indicator.](https://flutter.github.io/assets-for-api-docs/assets/material/slider.png) /// /// The Sliders value is part of the Stateful widget subclass to change the value /// setState was called. /// -/// ```dart -/// double _currentSliderValue = 20; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Slider( -/// value: _currentSliderValue, -/// min: 0, -/// max: 100, -/// divisions: 5, -/// label: _currentSliderValue.round().toString(), -/// onChanged: (double value) { -/// setState(() { -/// _currentSliderValue = value; -/// }); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/slider/slider.0.dart ** /// {@end-tool} /// /// A slider can be used to select from either a continuous or a discrete set of diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 2ca6e8a0ca..e0277da2a9 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -158,67 +158,18 @@ class _SnackBarActionState extends State { /// enabled. This is controlled by [AccessibilityFeatures.accessibleNavigation]. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// Here is an example of a [SnackBar] with an [action] button implemented using /// [SnackBarAction]. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return ElevatedButton( -/// child: const Text('Show Snackbar'), -/// onPressed: () { -/// ScaffoldMessenger.of(context).showSnackBar( -/// SnackBar( -/// content: const Text('Awesome Snackbar!'), -/// action: SnackBarAction( -/// label: 'Action', -/// onPressed: () { -/// // Code to execute. -/// }, -/// ), -/// ), -/// ); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/snack_bar/snack_bar.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// Here is an example of a customized [SnackBar]. It utilizes /// [behavior], [shape], [padding], [width], and [duration] to customize the /// location, appearance, and the duration for which the [SnackBar] is visible. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return ElevatedButton( -/// child: const Text('Show Snackbar'), -/// onPressed: () { -/// ScaffoldMessenger.of(context).showSnackBar( -/// SnackBar( -/// action: SnackBarAction( -/// label: 'Action', -/// onPressed: () { -/// // Code to execute. -/// }, -/// ), -/// content: const Text('Awesome SnackBar!'), -/// duration: const Duration(milliseconds: 1500), -/// width: 280.0, // Width of the SnackBar. -/// padding: const EdgeInsets.symmetric( -/// horizontal: 8.0, // Inner padding for SnackBar content. -/// ), -/// behavior: SnackBarBehavior.floating, -/// shape: RoundedRectangleBorder( -/// borderRadius: BorderRadius.circular(10.0), -/// ), -/// ), -/// ); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/snack_bar/snack_bar.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index 2c0644cdf9..01e1b2c14f 100755 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -124,43 +124,8 @@ class Step { /// /// {@tool sample --template=stateful_widget_scaffold_center} /// -/// ```dart -/// int _index = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Stepper( -/// currentStep: _index, -/// onStepCancel: () { -/// if (_index > 0) { -/// setState(() { _index -= 1; }); -/// } -/// }, -/// onStepContinue: () { -/// if (_index <= 0) { -/// setState(() { _index += 1; }); -/// } -/// }, -/// onStepTapped: (int index) { -/// setState(() { _index = index; }); -/// }, -/// steps: [ -/// Step( -/// title: const Text('Step 1 title'), -/// content: Container( -/// alignment: Alignment.centerLeft, -/// child: const Text('Content for Step 1') -/// ), -/// ), -/// const Step( -/// title: Text('Step 2 title'), -/// content: Text('Content for Step 2'), -/// ), -/// ], -/// ); -/// } -/// ``` /// +/// ** See code in examples/api/lib/material/stepper/stepper.0.dart ** /// {@end-tool} /// /// See also: @@ -242,43 +207,7 @@ class Stepper extends StatefulWidget { /// {@tool dartpad --template=stateless_widget_scaffold} /// Creates a stepper control with custom buttons. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return Stepper( - /// controlsBuilder: - /// (BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }) { - /// return Row( - /// children: [ - /// TextButton( - /// onPressed: onStepContinue, - /// child: const Text('NEXT'), - /// ), - /// TextButton( - /// onPressed: onStepCancel, - /// child: const Text('CANCEL'), - /// ), - /// ], - /// ); - /// }, - /// steps: const [ - /// Step( - /// title: Text('A'), - /// content: SizedBox( - /// width: 100.0, - /// height: 100.0, - /// ), - /// ), - /// Step( - /// title: Text('B'), - /// content: SizedBox( - /// width: 100.0, - /// height: 100.0, - /// ), - /// ), - /// ], - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/material/stepper/stepper.controls_builder.0.dart ** /// {@end-tool} final ControlsWidgetBuilder? controlsBuilder; diff --git a/packages/flutter/lib/src/material/switch_list_tile.dart b/packages/flutter/lib/src/material/switch_list_tile.dart index 654b34ab9b..c77e8fa9d4 100644 --- a/packages/flutter/lib/src/material/switch_list_tile.dart +++ b/packages/flutter/lib/src/material/switch_list_tile.dart @@ -50,25 +50,12 @@ enum _SwitchListTileType { material, adaptive } /// callback. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// ![SwitchListTile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile.png) /// /// This widget shows a switch that, when toggled, changes the state of a [bool] /// member field called `_lights`. /// -/// ```dart -/// bool _lights = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return SwitchListTile( -/// title: const Text('Lights'), -/// value: _lights, -/// onChanged: (bool value) { setState(() { _lights = value; }); }, -/// secondary: const Icon(Icons.lightbulb_outline), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/switch_list_tile/switch_list_tile.0.dart ** /// {@end-tool} /// /// ## Semantics in SwitchListTile @@ -89,81 +76,13 @@ enum _SwitchListTileType { material, adaptive } /// widget to accommodate similar use cases. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// ![Switch list tile semantics sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_semantics.png) /// /// Here is an example of a custom labeled radio widget, called /// LinkedLabelRadio, that includes an interactive [RichText] widget that /// handles tap gestures. /// -/// ```dart imports -/// import 'package:flutter/gestures.dart'; -/// ``` -/// ```dart preamble -/// class LinkedLabelSwitch extends StatelessWidget { -/// const LinkedLabelSwitch({ -/// Key? key, -/// required this.label, -/// required this.padding, -/// required this.value, -/// required this.onChanged, -/// }) : super(key: key); -/// -/// final String label; -/// final EdgeInsets padding; -/// final bool value; -/// final ValueChanged onChanged; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Padding( -/// padding: padding, -/// child: Row( -/// children: [ -/// Expanded( -/// child: RichText( -/// text: TextSpan( -/// text: label, -/// style: const TextStyle( -/// color: Colors.blueAccent, -/// decoration: TextDecoration.underline, -/// ), -/// recognizer: TapGestureRecognizer() -/// ..onTap = () { -/// print('Label has been tapped.'); -/// }, -/// ), -/// ), -/// ), -/// Switch( -/// value: value, -/// onChanged: (bool newValue) { -/// onChanged(newValue); -/// }, -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// ``` -/// ```dart -/// bool _isSelected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return LinkedLabelSwitch( -/// label: 'Linked, tappable label text', -/// padding: const EdgeInsets.symmetric(horizontal: 20.0), -/// value: _isSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isSelected = newValue; -/// }); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/switch_list_tile/switch_list_tile.1.dart ** /// {@end-tool} /// /// ## SwitchListTile isn't exactly what I want @@ -174,68 +93,12 @@ enum _SwitchListTileType { material, adaptive } /// [InkWell]. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// ![Custom switch list tile sample](https://flutter.github.io/assets-for-api-docs/assets/material/switch_list_tile_custom.png) /// /// Here is an example of a custom LabeledSwitch widget, but you can easily /// make your own configurable widget. /// -/// ```dart preamble -/// class LabeledSwitch extends StatelessWidget { -/// const LabeledSwitch({ -/// Key? key, -/// required this.label, -/// required this.padding, -/// required this.value, -/// required this.onChanged, -/// }) : super(key: key); -/// -/// final String label; -/// final EdgeInsets padding; -/// final bool value; -/// final ValueChanged onChanged; -/// -/// @override -/// Widget build(BuildContext context) { -/// return InkWell( -/// onTap: () { -/// onChanged(!value); -/// }, -/// child: Padding( -/// padding: padding, -/// child: Row( -/// children: [ -/// Expanded(child: Text(label)), -/// Switch( -/// value: value, -/// onChanged: (bool newValue) { -/// onChanged(newValue); -/// }, -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// ```dart -/// bool _isSelected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return LabeledSwitch( -/// label: 'This is the label text', -/// padding: const EdgeInsets.symmetric(horizontal: 20.0), -/// value: _isSelected, -/// onChanged: (bool newValue) { -/// setState(() { -/// _isSelected = newValue; -/// }); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/switch_list_tile/switch_list_tile.2.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/tab_controller.dart b/packages/flutter/lib/src/material/tab_controller.dart index 8f105500cc..8c2d74b408 100644 --- a/packages/flutter/lib/src/material/tab_controller.dart +++ b/packages/flutter/lib/src/material/tab_controller.dart @@ -85,55 +85,10 @@ import 'constants.dart'; /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This example shows how to listen to page updates in [TabBar] and [TabBarView] /// when using [DefaultTabController]. /// -/// ```dart preamble -/// const List tabs = [ -/// Tab(text: 'Zeroth'), -/// Tab(text: 'First'), -/// Tab(text: 'Second'), -/// ]; -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return DefaultTabController( -/// length: tabs.length, -/// // The Builder widget is used to have a different BuildContext to access -/// // closest DefaultTabController. -/// child: Builder( -/// builder: (BuildContext context) { -/// final TabController tabController = DefaultTabController.of(context)!; -/// tabController.addListener(() { -/// if (!tabController.indexIsChanging) { -/// // Your code goes here. -/// // To get index of current tab use tabController.index -/// } -/// }); -/// return Scaffold( -/// appBar: AppBar( -/// bottom: const TabBar( -/// tabs: tabs, -/// ), -/// ), -/// body: TabBarView( -/// children: tabs.map((Tab tab) { -/// return Center( -/// child: Text( -/// '${tab.text!} Tab', -/// style: Theme.of(context).textTheme.headline5, -/// ), -/// ); -/// }).toList(), -/// ), -/// ); -/// } -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/tab_controller/tab_controller.1.dart ** /// {@end-tool} /// class TabController extends ChangeNotifier { diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index c0d8dcbc11..b5926054f3 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -591,45 +591,7 @@ class _TabBarScrollController extends ScrollController { /// This sample shows the implementation of [TabBar] and [TabBarView] using a [DefaultTabController]. /// Each [Tab] corresponds to a child of the [TabBarView] in the order they are written. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return DefaultTabController( -/// initialIndex: 1, -/// length: 3, -/// child: Scaffold( -/// appBar: AppBar( -/// title: const Text('TabBar Widget'), -/// bottom: const TabBar( -/// tabs: [ -/// Tab( -/// icon: Icon(Icons.cloud_outlined), -/// ), -/// Tab( -/// icon: Icon(Icons.beach_access_sharp), -/// ), -/// Tab( -/// icon: Icon(Icons.brightness_5_sharp), -/// ), -/// ], -/// ), -/// ), -/// body: const TabBarView( -/// children: [ -/// Center( -/// child: Text("It's cloudy here"), -/// ), -/// Center( -/// child: Text("It's rainy here"), -/// ), -/// Center( -/// child: Text("It's sunny here"), -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/tabs/tab_bar.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material_ticker} @@ -637,53 +599,7 @@ class _TabBarScrollController extends ScrollController { /// to control the behavior of the [TabBar] and [TabBarView]. This can be used instead of /// a [DefaultTabController], demonstrated below. /// -/// ```dart -/// -/// late TabController _tabController; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _tabController = TabController(length: 3, vsync: this); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('TabBar Widget'), -/// bottom: TabBar( -/// controller: _tabController, -/// tabs: const [ -/// Tab( -/// icon: Icon(Icons.cloud_outlined), -/// ), -/// Tab( -/// icon: Icon(Icons.beach_access_sharp), -/// ), -/// Tab( -/// icon: Icon(Icons.brightness_5_sharp), -/// ), -/// ], -/// ), -/// ), -/// body: TabBarView( -/// controller: _tabController, -/// children: const [ -/// Center( -/// child: Text("It's cloudy here"), -/// ), -/// Center( -/// child: Text("It's rainy here"), -/// ), -/// Center( -/// child: Text("It's sunny here"), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/tabs/tab_bar.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/text_button.dart b/packages/flutter/lib/src/material/text_button.dart index 33abda510e..2882127d27 100644 --- a/packages/flutter/lib/src/material/text_button.dart +++ b/packages/flutter/lib/src/material/text_button.dart @@ -51,67 +51,10 @@ import 'theme_data.dart'; /// button will be disabled, it will not react to touch. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows how to render a disabled TextButton, an enabled TextButton /// and lastly a TextButton with gradient background. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Center( -/// child: Column( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// TextButton( -/// style: TextButton.styleFrom( -/// textStyle: const TextStyle(fontSize: 20), -/// ), -/// onPressed: null, -/// child: const Text('Disabled'), -/// ), -/// const SizedBox(height: 30), -/// TextButton( -/// style: TextButton.styleFrom( -/// textStyle: const TextStyle(fontSize: 20), -/// ), -/// onPressed: () {}, -/// child: const Text('Enabled'), -/// ), -/// const SizedBox(height: 30), -/// ClipRRect( -/// borderRadius: BorderRadius.circular(4), -/// child: Stack( -/// children: [ -/// Positioned.fill( -/// child: Container( -/// decoration: const BoxDecoration( -/// gradient: LinearGradient( -/// colors: [ -/// Color(0xFF0D47A1), -/// Color(0xFF1976D2), -/// Color(0xFF42A5F5), -/// ], -/// ), -/// ), -/// ), -/// ), -/// TextButton( -/// style: TextButton.styleFrom( -/// padding: const EdgeInsets.all(16.0), -/// primary: Colors.white, -/// textStyle: const TextStyle(fontSize: 20), -/// ), -/// onPressed: () {}, -/// child: const Text('Gradient'), -/// ), -/// ], -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// -/// ``` +/// ** See code in examples/api/lib/material/text_button/text_button.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index dc67d74080..dc712fecdf 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -197,53 +197,10 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete /// the user finishes editing. /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This sample shows how to get a value from a TextField via the [onSubmitted] /// callback. /// -/// ```dart -/// late TextEditingController _controller; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _controller = TextEditingController(); -/// } -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: TextField( -/// controller: _controller, -/// onSubmitted: (String value) async { -/// await showDialog( -/// context: context, -/// builder: (BuildContext context) { -/// return AlertDialog( -/// title: const Text('Thanks!'), -/// content: Text ('You typed "$value", which has length ${value.characters.length}.'), -/// actions: [ -/// TextButton( -/// onPressed: () { Navigator.pop(context); }, -/// child: const Text('OK'), -/// ), -/// ], -/// ); -/// }, -/// ); -/// }, -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/text_field/text_field.1.dart ** /// {@end-tool} /// /// For most applications the [onSubmitted] callback will be sufficient for diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index 1f38f4b8c7..dcd38f4baf 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -71,48 +71,7 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType; /// This example shows how to move the focus to the next field when the user /// presses the SPACE key. /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return Material( -/// child: Center( -/// child: Shortcuts( -/// shortcuts: const { -/// // Pressing space in the field will now move to the next field. -/// SingleActivator(LogicalKeyboardKey.space): NextFocusIntent(), -/// }, -/// child: FocusTraversalGroup( -/// child: Form( -/// autovalidateMode: AutovalidateMode.always, -/// onChanged: () { -/// Form.of(primaryFocus!.context!)!.save(); -/// }, -/// child: Wrap( -/// children: List.generate(5, (int index) { -/// return Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: ConstrainedBox( -/// constraints: BoxConstraints.tight(const Size(200, 50)), -/// child: TextFormField( -/// onSaved: (String? value) { -/// print('Value for field $index saved as "$value"'); -/// }, -/// ), -/// ), -/// ); -/// }), -/// ), -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/text_form_field/text_form_field.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/material/tooltip.dart b/packages/flutter/lib/src/material/tooltip.dart index c364d325ff..5df8ad5589 100644 --- a/packages/flutter/lib/src/material/tooltip.dart +++ b/packages/flutter/lib/src/material/tooltip.dart @@ -31,24 +31,15 @@ import 'tooltip_theme.dart'; /// {@youtube 560 315 https://www.youtube.com/watch?v=EeEfD5fI-5Q} /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// This example show a basic [Tooltip] which has a [Text] as child. /// [message] contains your label to be shown by the tooltip when /// the child that Tooltip wraps is hovered over on web or desktop. On mobile, /// the tooltip is shown when the widget is long pressed. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return const Tooltip( -/// message: 'I am a Tooltip', -/// child: Text('Hover over the text to show a tooltip.'), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/tooltip/tooltip.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// This example covers most of the attributes available in Tooltip. /// `decoration` has been used to give a gradient and borderRadius to Tooltip. /// `height` has been used to set a specific height of the Tooltip. @@ -61,26 +52,7 @@ import 'tooltip_theme.dart'; /// `waitDuration` accepts a Duration for which a mouse pointer has to hover over the child /// widget before the tooltip is shown. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Tooltip( -/// message: 'I am a Tooltip', -/// child: const Text('Tap this text and hold down to show a tooltip.'), -/// decoration: BoxDecoration( -/// borderRadius: BorderRadius.circular(25), -/// gradient: const LinearGradient(colors: [Colors.amber, Colors.red]), -/// ), -/// height: 50, -/// padding: const EdgeInsets.all(8.0), -/// preferBelow: false, -/// textStyle: const TextStyle( -/// fontSize: 24, -/// ), -/// showDuration: const Duration(seconds: 2), -/// waitDuration: const Duration(seconds: 1), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/material/tooltip/tooltip.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/painting/gradient.dart b/packages/flutter/lib/src/painting/gradient.dart index 03cdeb3e07..fa96fb96e6 100644 --- a/packages/flutter/lib/src/painting/gradient.dart +++ b/packages/flutter/lib/src/painting/gradient.dart @@ -335,20 +335,7 @@ abstract class Gradient { /// This sample draws a picture that looks like vertical window shades by having /// a [Container] display a [BoxDecoration] with a [LinearGradient]. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// decoration: const BoxDecoration( -/// gradient: LinearGradient( -/// begin: Alignment.topLeft, -/// end: Alignment(0.8, 0.0), // 10% of the width, so there are ten blinds. -/// colors: [Color(0xffee0000), Color(0xffeeee00)], // red to yellow -/// tileMode: TileMode.repeated, // repeats the gradient over the canvas -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/painting/gradient/linear_gradient.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/rendering/sliver_grid.dart b/packages/flutter/lib/src/rendering/sliver_grid.dart index 4b0685d5cc..cf54395a0e 100644 --- a/packages/flutter/lib/src/rendering/sliver_grid.dart +++ b/packages/flutter/lib/src/rendering/sliver_grid.dart @@ -276,49 +276,19 @@ abstract class SliverGridDelegate { /// This delegate creates grids with equally sized and spaced tiles. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// Here is an example using the [childAspectRatio] property. On a device with a /// screen width of 800.0, it creates a GridView with each tile with a width of /// 200.0 and a height of 100.0. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return GridView( -/// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( -/// crossAxisCount: 4, -/// childAspectRatio: 0.5, -/// ), -/// children: List.generate(20, (int i) { -/// return Builder(builder: (BuildContext context) { -/// return Text('$i'); -/// }); -/// }), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// Here is an example using the [mainAxisExtent] property. On a device with a /// screen width of 800.0, it creates a GridView with each tile with a width of /// 200.0 and a height of 150.0. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return GridView( -/// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( -/// crossAxisCount: 4, -/// mainAxisExtent: 150.0, -/// ), -/// children: List.generate(20, (int i) { -/// return Builder(builder: (BuildContext context) { -/// return Text('$i'); -/// }); -/// }), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/rendering/sliver_grid/sliver_grid_delegate_with_fixed_cross_axis_count.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/services/keyboard_key.dart b/packages/flutter/lib/src/services/keyboard_key.dart index 7262413d86..bc9f75cf01 100644 --- a/packages/flutter/lib/src/services/keyboard_key.dart +++ b/packages/flutter/lib/src/services/keyboard_key.dart @@ -50,71 +50,7 @@ abstract class KeyboardKey with Diagnosticable { /// This example shows how to detect if the user has selected the logical "Q" /// key. /// -/// ```dart imports -/// import 'package:flutter/foundation.dart'; -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart -/// // The node used to request the keyboard focus. -/// final FocusNode _focusNode = FocusNode(); -/// // The message to display. -/// String? _message; -/// -/// // Focus nodes need to be disposed. -/// @override -/// void dispose() { -/// _focusNode.dispose(); -/// super.dispose(); -/// } -/// -/// // Handles the key events from the RawKeyboardListener and update the -/// // _message. -/// void _handleKeyEvent(RawKeyEvent event) { -/// setState(() { -/// if (event.logicalKey == LogicalKeyboardKey.keyQ) { -/// _message = 'Pressed the "Q" key!'; -/// } else { -/// if (kReleaseMode) { -/// _message = 'Not a Q: Pressed 0x${event.logicalKey.keyId.toRadixString(16)}'; -/// } else { -/// // The debugName will only print useful information in debug mode. -/// _message = 'Not a Q: Pressed ${event.logicalKey.debugName}'; -/// } -/// } -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// final TextTheme textTheme = Theme.of(context).textTheme; -/// return Container( -/// color: Colors.white, -/// alignment: Alignment.center, -/// child: DefaultTextStyle( -/// style: textTheme.headline4!, -/// child: RawKeyboardListener( -/// focusNode: _focusNode, -/// onKey: _handleKeyEvent, -/// child: AnimatedBuilder( -/// animation: _focusNode, -/// builder: (BuildContext context, Widget? child) { -/// if (!_focusNode.hasFocus) { -/// return GestureDetector( -/// onTap: () { -/// FocusScope.of(context).requestFocus(_focusNode); -/// }, -/// child: const Text('Tap to focus'), -/// ); -/// } -/// return Text(_message ?? 'Press a key'); -/// }, -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/services/keyboard_key/logical_keyboard_key.0.dart ** /// {@end-tool} /// See also: /// @@ -3560,65 +3496,7 @@ class LogicalKeyboardKey extends KeyboardKey { /// This example shows how to detect if the user has selected the physical key /// to the right of the CAPS LOCK key. /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart -/// // The node used to request the keyboard focus. -/// final FocusNode _focusNode = FocusNode(); -/// // The message to display. -/// String? _message; -/// -/// // Focus nodes need to be disposed. -/// @override -/// void dispose() { -/// _focusNode.dispose(); -/// super.dispose(); -/// } -/// -/// // Handles the key events from the RawKeyboardListener and update the -/// // _message. -/// void _handleKeyEvent(RawKeyEvent event) { -/// setState(() { -/// if (event.physicalKey == PhysicalKeyboardKey.keyA) { -/// _message = 'Pressed the key next to CAPS LOCK!'; -/// } else { -/// _message = 'Wrong key.'; -/// } -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// final TextTheme textTheme = Theme.of(context).textTheme; -/// return Container( -/// color: Colors.white, -/// alignment: Alignment.center, -/// child: DefaultTextStyle( -/// style: textTheme.headline4!, -/// child: RawKeyboardListener( -/// focusNode: _focusNode, -/// onKey: _handleKeyEvent, -/// child: AnimatedBuilder( -/// animation: _focusNode, -/// builder: (BuildContext context, Widget? child) { -/// if (!_focusNode.hasFocus) { -/// return GestureDetector( -/// onTap: () { -/// FocusScope.of(context).requestFocus(_focusNode); -/// }, -/// child: const Text('Tap to focus'), -/// ); -/// } -/// return Text(_message ?? 'Press a key'); -/// }, -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/services/keyboard_key/physical_keyboard_key.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/services/system_chrome.dart b/packages/flutter/lib/src/services/system_chrome.dart index b81d079d1d..d8885af733 100644 --- a/packages/flutter/lib/src/services/system_chrome.dart +++ b/packages/flutter/lib/src/services/system_chrome.dart @@ -570,45 +570,7 @@ class SystemChrome { /// The following example creates a widget that changes the status bar color /// to a random value on Android. /// - /// ```dart dartImports - /// import 'dart:math' as math; - /// ``` - /// - /// ```dart imports - /// import 'package:flutter/services.dart'; - /// ``` - /// - /// ```dart - /// final math.Random _random = math.Random(); - /// SystemUiOverlayStyle _currentStyle = SystemUiOverlayStyle.light; - /// - /// void _changeColor() { - /// final Color color = Color.fromRGBO( - /// _random.nextInt(255), - /// _random.nextInt(255), - /// _random.nextInt(255), - /// 1.0, - /// ); - /// setState(() { - /// _currentStyle = SystemUiOverlayStyle.dark.copyWith( - /// statusBarColor: color, - /// ); - /// }); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return AnnotatedRegion( - /// value: _currentStyle, - /// child: Center( - /// child: ElevatedButton( - /// child: const Text('Change Color'), - /// onPressed: _changeColor, - /// ), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/services/system_chrome/system_chrome.set_system_u_i_overlay_style.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/actions.dart b/packages/flutter/lib/src/widgets/actions.dart index d83d5a9a48..206112302e 100644 --- a/packages/flutter/lib/src/widgets/actions.dart +++ b/packages/flutter/lib/src/widgets/actions.dart @@ -148,136 +148,7 @@ abstract class Action with Diagnosticable { /// sends the focus to the preceding text field when the currently focused /// field becomes empty. /// - /// ```dart imports - /// import 'package:flutter/material.dart'; - /// import 'package:flutter/services.dart'; - /// ``` - /// - /// ```dart main - /// void main() { - /// runApp( - /// const MaterialApp( - /// home: Scaffold( - /// body: Center(child: SimpleUSPhoneNumberEntry()), - /// ), - /// ), - /// ); - /// } - /// ``` - /// - /// ```dart - /// // This implements a custom phone number input field that handles the - /// // [DeleteTextIntent] intent. - /// class DigitInput extends StatefulWidget { - /// const DigitInput({ - /// Key? key, - /// required this.controller, - /// required this.focusNode, - /// this.maxLength, - /// this.textInputAction = TextInputAction.next, - /// }) : super(key: key); - /// - /// final int? maxLength; - /// final TextEditingController controller; - /// final TextInputAction textInputAction; - /// final FocusNode focusNode; - /// - /// @override - /// DigitInputState createState() => DigitInputState(); - /// } - /// - /// class DigitInputState extends State { - /// late final Action _deleteTextAction = CallbackAction( - /// onInvoke: (DeleteTextIntent intent) { - /// // For simplicity we delete everything in the section. - /// widget.controller.clear(); - /// }, - /// ); - /// - /// @override - /// Widget build(BuildContext context) { - /// return Actions( - /// actions: >{ - /// // Make the default `DeleteTextIntent` handler overridable. - /// DeleteTextIntent: Action.overridable(defaultAction: _deleteTextAction, context: context), - /// }, - /// child: TextField( - /// controller: widget.controller, - /// textInputAction: TextInputAction.next, - /// keyboardType: TextInputType.phone, - /// focusNode: widget.focusNode, - /// decoration: const InputDecoration( - /// border: OutlineInputBorder(), - /// ), - /// inputFormatters: [ - /// FilteringTextInputFormatter.digitsOnly, - /// LengthLimitingTextInputFormatter(widget.maxLength), - /// ], - /// ), - /// ); - /// } - /// } - /// - /// class SimpleUSPhoneNumberEntry extends StatefulWidget { - /// const SimpleUSPhoneNumberEntry({ Key? key }) : super(key: key); - /// - /// @override - /// State createState() => _SimpleUSPhoneNumberEntryState(); - /// } - /// - /// class _DeleteDigit extends Action { - /// _DeleteDigit(this.state); - /// - /// final _SimpleUSPhoneNumberEntryState state; - /// @override - /// Object? invoke(DeleteTextIntent intent) { - /// assert(callingAction != null); - /// callingAction?.invoke(intent); - /// - /// if (state.lineNumberController.text.isEmpty && state.lineNumberFocusNode.hasFocus) { - /// state.prefixFocusNode.requestFocus(); - /// } - /// - /// if (state.prefixController.text.isEmpty && state.prefixFocusNode.hasFocus) { - /// state.areaCodeFocusNode.requestFocus(); - /// } - /// } - /// - /// // This action is only enabled when the `callingAction` exists and is - /// // enabled. - /// @override - /// bool get isActionEnabled => callingAction?.isActionEnabled ?? false; - /// } - /// - /// class _SimpleUSPhoneNumberEntryState extends State { - /// final FocusNode areaCodeFocusNode = FocusNode(); - /// final TextEditingController areaCodeController = TextEditingController(); - /// final FocusNode prefixFocusNode = FocusNode(); - /// final TextEditingController prefixController = TextEditingController(); - /// final FocusNode lineNumberFocusNode = FocusNode(); - /// final TextEditingController lineNumberController = TextEditingController(); - /// - /// @override - /// Widget build(BuildContext context) { - /// return Actions( - /// actions: >{ - /// DeleteTextIntent : _DeleteDigit(this), - /// }, - /// child: Row( - /// mainAxisAlignment: MainAxisAlignment.spaceBetween, - /// children: [ - /// const Expanded(child: Text('(', textAlign: TextAlign.center,), flex: 1), - /// Expanded(child: DigitInput(focusNode: areaCodeFocusNode, controller: areaCodeController, maxLength: 3), flex: 3), - /// const Expanded(child: Text(')', textAlign: TextAlign.center,), flex: 1), - /// Expanded(child: DigitInput(focusNode: prefixFocusNode, controller: prefixController, maxLength: 3), flex: 3), - /// const Expanded(child: Text('-', textAlign: TextAlign.center,), flex: 1), - /// Expanded(child: DigitInput(focusNode: lineNumberFocusNode, controller: lineNumberController, textInputAction: TextInputAction.done, maxLength: 4), flex: 4), - /// ], - /// ), - /// ); - /// } - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/actions/action.action_overridable.0.dart ** /// {@end-tool} factory Action.overridable({ required Action defaultAction, @@ -522,98 +393,7 @@ abstract class Action with Diagnosticable { /// This example shows how ActionListener handles adding and removing of /// the [listener] in the widget lifecycle. /// -/// ```dart preamble -/// class ActionListenerExample extends StatefulWidget { -/// const ActionListenerExample({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _ActionListenerExampleState(); -/// } -/// -/// class _ActionListenerExampleState extends State { -/// bool _on = false; -/// late final MyAction _myAction; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _myAction = MyAction(); -/// } -/// -/// void _toggleState() { -/// setState(() { -/// _on = !_on; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Row( -/// crossAxisAlignment: CrossAxisAlignment.center, -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: OutlinedButton( -/// onPressed: _toggleState, -/// child: Text(_on ? 'Disable' : 'Enable'), -/// ), -/// ), -/// if (_on) -/// Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: ActionListener( -/// listener: (Action action) { -/// if (action.intentType == MyIntent) { -/// ScaffoldMessenger.of(context).showSnackBar(const SnackBar( -/// content: Text('Action Listener Called'), -/// )); -/// } -/// }, -/// action: _myAction, -/// child: ElevatedButton( -/// onPressed: () => const ActionDispatcher() -/// .invokeAction(_myAction, const MyIntent()), -/// child: const Text('Call Action Listener'), -/// ), -/// ), -/// ), -/// if (!_on) Container(), -/// ], -/// ); -/// } -/// } -/// -/// class MyAction extends Action { -/// @override -/// void addActionListener(ActionListenerCallback listener) { -/// super.addActionListener(listener); -/// print('Action Listener was added'); -/// } -/// -/// @override -/// void removeActionListener(ActionListenerCallback listener) { -/// super.removeActionListener(listener); -/// print('Action Listener was removed'); -/// } -/// -/// @override -/// void invoke(covariant MyIntent intent) { -/// notifyActionListeners(); -/// } -/// } -/// -/// class MyIntent extends Intent { -/// const MyIntent(); -/// } -/// ``` -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return const ActionListenerExample(); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/actions/action_listener.0.dart ** /// {@end-tool} /// @immutable @@ -804,7 +584,6 @@ class ActionDispatcher with Diagnosticable { /// containing the ambient [Actions] widget. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// This example creates a custom [Action] subclass `ModifyAction` for modifying /// a model, and another, `SaveAction` for saving it. /// @@ -820,149 +599,7 @@ class ActionDispatcher with Diagnosticable { /// need to know about the `SaveAction` class, only the `SaveIntent`, and it /// only needs to know about a value notifier, not the entire model. /// -/// ```dart preamble -/// // A simple model class that notifies listeners when it changes. -/// class Model { -/// ValueNotifier isDirty = ValueNotifier(false); -/// ValueNotifier data = ValueNotifier(0); -/// -/// int save() { -/// if (isDirty.value) { -/// print('Saved Data: ${data.value}'); -/// isDirty.value = false; -/// } -/// return data.value; -/// } -/// -/// void setValue(int newValue) { -/// isDirty.value = data.value != newValue; -/// data.value = newValue; -/// } -/// } -/// -/// class ModifyIntent extends Intent { -/// const ModifyIntent(this.value); -/// -/// final int value; -/// } -/// -/// // An Action that modifies the model by setting it to the value that it gets -/// // from the Intent passed to it when invoked. -/// class ModifyAction extends Action { -/// ModifyAction(this.model); -/// -/// final Model model; -/// -/// @override -/// void invoke(covariant ModifyIntent intent) { -/// model.setValue(intent.value); -/// } -/// } -/// -/// // An intent for saving data. -/// class SaveIntent extends Intent { -/// const SaveIntent(); -/// } -/// -/// // An Action that saves the data in the model it is created with. -/// class SaveAction extends Action { -/// SaveAction(this.model); -/// -/// final Model model; -/// -/// @override -/// int invoke(covariant SaveIntent intent) => model.save(); -/// } -/// -/// class SaveButton extends StatefulWidget { -/// const SaveButton(this.valueNotifier, {Key? key}) : super(key: key); -/// -/// final ValueNotifier valueNotifier; -/// -/// @override -/// State createState() => _SaveButtonState(); -/// } -/// -/// class _SaveButtonState extends State { -/// int savedValue = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return AnimatedBuilder( -/// animation: widget.valueNotifier, -/// builder: (BuildContext context, Widget? child) { -/// return TextButton.icon( -/// icon: const Icon(Icons.save), -/// label: Text('$savedValue'), -/// style: ButtonStyle( -/// foregroundColor: MaterialStateProperty.all( -/// widget.valueNotifier.value ? Colors.red : Colors.green, -/// ), -/// ), -/// onPressed: () { -/// setState(() { -/// savedValue = Actions.invoke(context, const SaveIntent())! as int; -/// }); -/// }, -/// ); -/// }, -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Model model = Model(); -/// int count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Actions( -/// actions: >{ -/// ModifyIntent: ModifyAction(model), -/// SaveIntent: SaveAction(model), -/// }, -/// child: Builder( -/// builder: (BuildContext context) { -/// return Row( -/// mainAxisAlignment: MainAxisAlignment.spaceAround, -/// children: [ -/// const Spacer(), -/// Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// IconButton( -/// icon: const Icon(Icons.exposure_plus_1), -/// onPressed: () { -/// Actions.invoke(context, ModifyIntent(++count)); -/// }, -/// ), -/// AnimatedBuilder( -/// animation: model.data, -/// builder: (BuildContext context, Widget? child) { -/// return Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: Text('${model.data.value}', -/// style: Theme.of(context).textTheme.headline4), -/// ); -/// }), -/// IconButton( -/// icon: const Icon(Icons.exposure_minus_1), -/// onPressed: () { -/// Actions.invoke(context, ModifyIntent(--count)); -/// }, -/// ), -/// ], -/// ), -/// SaveButton(model.isDirty), -/// const Spacer(), -/// ], -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/actions/actions.0.dart ** /// {@end-tool} /// /// See also: @@ -1412,128 +1049,7 @@ class _ActionsMarker extends InheritedWidget { /// bindings created by [WidgetsApp] (the parent for [MaterialApp], and /// [CupertinoApp]), so the `ENTER` key will also activate the buttons. /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart preamble -/// class FadButton extends StatefulWidget { -/// const FadButton({ -/// Key? key, -/// required this.onPressed, -/// required this.child, -/// }) : super(key: key); -/// -/// final VoidCallback onPressed; -/// final Widget child; -/// -/// @override -/// State createState() => _FadButtonState(); -/// } -/// -/// class _FadButtonState extends State { -/// bool _focused = false; -/// bool _hovering = false; -/// bool _on = false; -/// late final Map> _actionMap; -/// final Map _shortcutMap = const { -/// SingleActivator(LogicalKeyboardKey.keyX): ActivateIntent(), -/// }; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _actionMap = >{ -/// ActivateIntent: CallbackAction( -/// onInvoke: (Intent intent) => _toggleState(), -/// ), -/// }; -/// } -/// -/// Color get color { -/// Color baseColor = Colors.lightBlue; -/// if (_focused) { -/// baseColor = Color.alphaBlend(Colors.black.withOpacity(0.25), baseColor); -/// } -/// if (_hovering) { -/// baseColor = Color.alphaBlend(Colors.black.withOpacity(0.1), baseColor); -/// } -/// return baseColor; -/// } -/// -/// void _toggleState() { -/// setState(() { -/// _on = !_on; -/// }); -/// } -/// -/// void _handleFocusHighlight(bool value) { -/// setState(() { -/// _focused = value; -/// }); -/// } -/// -/// void _handleHoveHighlight(bool value) { -/// setState(() { -/// _hovering = value; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return GestureDetector( -/// onTap: _toggleState, -/// child: FocusableActionDetector( -/// actions: _actionMap, -/// shortcuts: _shortcutMap, -/// onShowFocusHighlight: _handleFocusHighlight, -/// onShowHoverHighlight: _handleHoveHighlight, -/// child: Row( -/// children: [ -/// Container( -/// padding: const EdgeInsets.all(10.0), -/// color: color, -/// child: widget.child, -/// ), -/// Container( -/// width: 30, -/// height: 30, -/// margin: const EdgeInsets.all(10.0), -/// color: _on ? Colors.red : Colors.transparent, -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('FocusableActionDetector Example'), -/// ), -/// body: Center( -/// child: Row( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: TextButton(onPressed: () {}, child: const Text('Press Me')), -/// ), -/// Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: FadButton(onPressed: () {}, child: const Text('And Me')), -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/actions/focusable_action_detector.0.dart ** /// {@end-tool} /// /// This widget doesn't have any visual representation, it is just a detector that diff --git a/packages/flutter/lib/src/widgets/animated_list.dart b/packages/flutter/lib/src/widgets/animated_list.dart index 83642b4dae..7abba1f076 100644 --- a/packages/flutter/lib/src/widgets/animated_list.dart +++ b/packages/flutter/lib/src/widgets/animated_list.dart @@ -51,216 +51,7 @@ class _ActiveItem implements Comparable<_ActiveItem> { /// This sample application uses an [AnimatedList] to create an effect when /// items are removed or added to the list. /// -/// ```dart imports -/// import 'package:flutter/foundation.dart'; -/// import 'package:flutter/material.dart'; -/// ``` -/// -/// ```dart -/// void main() { -/// runApp(const AnimatedListSample()); -/// } -/// -/// class AnimatedListSample extends StatefulWidget { -/// const AnimatedListSample({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _AnimatedListSampleState(); -/// } -/// -/// class _AnimatedListSampleState extends State { -/// final GlobalKey _listKey = GlobalKey(); -/// late ListModel _list; -/// int? _selectedItem; -/// late int _nextItem; // The next item inserted when the user presses the '+' button. -/// -/// @override -/// void initState() { -/// super.initState(); -/// _list = ListModel( -/// listKey: _listKey, -/// initialItems: [0, 1, 2], -/// removedItemBuilder: _buildRemovedItem, -/// ); -/// _nextItem = 3; -/// } -/// -/// // Used to build list items that haven't been removed. -/// Widget _buildItem(BuildContext context, int index, Animation animation) { -/// return CardItem( -/// animation: animation, -/// item: _list[index], -/// selected: _selectedItem == _list[index], -/// onTap: () { -/// setState(() { -/// _selectedItem = _selectedItem == _list[index] ? null : _list[index]; -/// }); -/// }, -/// ); -/// } -/// -/// // Used to build an item after it has been removed from the list. This -/// // method is needed because a removed item remains visible until its -/// // animation has completed (even though it's gone as far this ListModel is -/// // concerned). The widget will be used by the -/// // [AnimatedListState.removeItem] method's -/// // [AnimatedListRemovedItemBuilder] parameter. -/// Widget _buildRemovedItem(int item, BuildContext context, Animation animation) { -/// return CardItem( -/// animation: animation, -/// item: item, -/// selected: false, -/// // No gesture detector here: we don't want removed items to be interactive. -/// ); -/// } -/// -/// // Insert the "next item" into the list model. -/// void _insert() { -/// final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!); -/// _list.insert(index, _nextItem++); -/// } -/// -/// // Remove the selected item from the list model. -/// void _remove() { -/// if (_selectedItem != null) { -/// _list.removeAt(_list.indexOf(_selectedItem!)); -/// setState(() { -/// _selectedItem = null; -/// }); -/// } -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('AnimatedList'), -/// actions: [ -/// IconButton( -/// icon: const Icon(Icons.add_circle), -/// onPressed: _insert, -/// tooltip: 'insert a new item', -/// ), -/// IconButton( -/// icon: const Icon(Icons.remove_circle), -/// onPressed: _remove, -/// tooltip: 'remove the selected item', -/// ), -/// ], -/// ), -/// body: Padding( -/// padding: const EdgeInsets.all(16.0), -/// child: AnimatedList( -/// key: _listKey, -/// initialItemCount: _list.length, -/// itemBuilder: _buildItem, -/// ), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// typedef RemovedItemBuilder = Widget Function(T item, BuildContext context, Animation animation); -/// -/// /// Keeps a Dart [List] in sync with an [AnimatedList]. -/// /// -/// /// The [insert] and [removeAt] methods apply to both the internal list and -/// /// the animated list that belongs to [listKey]. -/// /// -/// /// This class only exposes as much of the Dart List API as is needed by the -/// /// sample app. More list methods are easily added, however methods that -/// /// mutate the list must make the same changes to the animated list in terms -/// /// of [AnimatedListState.insertItem] and [AnimatedList.removeItem]. -/// class ListModel { -/// ListModel({ -/// required this.listKey, -/// required this.removedItemBuilder, -/// Iterable? initialItems, -/// }) : _items = List.from(initialItems ?? []); -/// -/// final GlobalKey listKey; -/// final RemovedItemBuilder removedItemBuilder; -/// final List _items; -/// -/// AnimatedListState? get _animatedList => listKey.currentState; -/// -/// void insert(int index, E item) { -/// _items.insert(index, item); -/// _animatedList!.insertItem(index); -/// } -/// -/// E removeAt(int index) { -/// final E removedItem = _items.removeAt(index); -/// if (removedItem != null) { -/// _animatedList!.removeItem( -/// index, -/// (BuildContext context, Animation animation) { -/// return removedItemBuilder(removedItem, context, animation); -/// }, -/// ); -/// } -/// return removedItem; -/// } -/// -/// int get length => _items.length; -/// -/// E operator [](int index) => _items[index]; -/// -/// int indexOf(E item) => _items.indexOf(item); -/// } -/// -/// /// Displays its integer item as 'item N' on a Card whose color is based on -/// /// the item's value. -/// /// -/// /// The text is displayed in bright green if [selected] is -/// /// true. This widget's height is based on the [animation] parameter, it -/// /// varies from 0 to 128 as the animation varies from 0.0 to 1.0. -/// class CardItem extends StatelessWidget { -/// const CardItem({ -/// Key? key, -/// this.onTap, -/// this.selected = false, -/// required this.animation, -/// required this.item, -/// }) : assert(item >= 0), -/// super(key: key); -/// -/// final Animation animation; -/// final VoidCallback? onTap; -/// final int item; -/// final bool selected; -/// -/// @override -/// Widget build(BuildContext context) { -/// TextStyle textStyle = Theme.of(context).textTheme.headline4!; -/// if (selected) { -/// textStyle = textStyle.copyWith(color: Colors.lightGreenAccent[400]); -/// } -/// return Padding( -/// padding: const EdgeInsets.all(2.0), -/// child: SizeTransition( -/// axis: Axis.vertical, -/// sizeFactor: animation, -/// child: GestureDetector( -/// behavior: HitTestBehavior.opaque, -/// onTap: onTap, -/// child: SizedBox( -/// height: 80.0, -/// child: Card( -/// color: Colors.primaries[item % Colors.primaries.length], -/// child: Center( -/// child: Text('Item $item', style: textStyle), -/// ), -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/animated_list/animated_list.0.dart ** /// {@end-tool} /// /// See also: @@ -534,237 +325,7 @@ class AnimatedListState extends State with TickerProviderStateMixi /// This sample application uses a [SliverAnimatedList] to create an animated /// effect when items are removed or added to the list. /// -/// ```dart imports -/// import 'package:flutter/foundation.dart'; -/// import 'package:flutter/material.dart'; -/// ``` -/// -/// ```dart -/// void main() => runApp(const SliverAnimatedListSample()); -/// -/// class SliverAnimatedListSample extends StatefulWidget { -/// const SliverAnimatedListSample({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _SliverAnimatedListSampleState(); -/// } -/// -/// class _SliverAnimatedListSampleState extends State { -/// final GlobalKey _listKey = GlobalKey(); -/// final GlobalKey _scaffoldKey = GlobalKey(); -/// final GlobalKey _scaffoldMessengerKey = GlobalKey(); -/// late ListModel _list; -/// int? _selectedItem; -/// late int _nextItem; // The next item inserted when the user presses the '+' button. -/// -/// @override -/// void initState() { -/// super.initState(); -/// _list = ListModel( -/// listKey: _listKey, -/// initialItems: [0, 1, 2], -/// removedItemBuilder: _buildRemovedItem, -/// ); -/// _nextItem = 3; -/// } -/// -/// // Used to build list items that haven't been removed. -/// Widget _buildItem(BuildContext context, int index, Animation animation) { -/// return CardItem( -/// animation: animation, -/// item: _list[index], -/// selected: _selectedItem == _list[index], -/// onTap: () { -/// setState(() { -/// _selectedItem = _selectedItem == _list[index] ? null : _list[index]; -/// }); -/// }, -/// ); -/// } -/// -/// // Used to build an item after it has been removed from the list. This -/// // method is needed because a removed item remains visible until its -/// // animation has completed (even though it's gone as far this ListModel is -/// // concerned). The widget will be used by the -/// // [AnimatedListState.removeItem] method's -/// // [AnimatedListRemovedItemBuilder] parameter. -/// Widget _buildRemovedItem(int item, BuildContext context, Animation animation) { -/// return CardItem( -/// animation: animation, -/// item: item, -/// selected: false, -/// ); -/// } -/// -/// // Insert the "next item" into the list model. -/// void _insert() { -/// final int index = _selectedItem == null ? _list.length : _list.indexOf(_selectedItem!); -/// _list.insert(index, _nextItem++); -/// } -/// -/// // Remove the selected item from the list model. -/// void _remove() { -/// if (_selectedItem != null) { -/// _list.removeAt(_list.indexOf(_selectedItem!)); -/// setState(() { -/// _selectedItem = null; -/// }); -/// } else { -/// _scaffoldMessengerKey.currentState!.showSnackBar(const SnackBar( -/// content: Text( -/// 'Select an item to remove from the list.', -/// style: TextStyle(fontSize: 20), -/// ), -/// )); -/// } -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// scaffoldMessengerKey: _scaffoldMessengerKey, -/// home: Scaffold( -/// key: _scaffoldKey, -/// body: CustomScrollView( -/// slivers: [ -/// SliverAppBar( -/// title: const Text( -/// 'SliverAnimatedList', -/// style: TextStyle(fontSize: 30), -/// ), -/// expandedHeight: 60, -/// centerTitle: true, -/// backgroundColor: Colors.amber[900], -/// leading: IconButton( -/// icon: const Icon(Icons.add_circle), -/// onPressed: _insert, -/// tooltip: 'Insert a new item.', -/// iconSize: 32, -/// ), -/// actions: [ -/// IconButton( -/// icon: const Icon(Icons.remove_circle), -/// onPressed: _remove, -/// tooltip: 'Remove the selected item.', -/// iconSize: 32, -/// ), -/// ], -/// ), -/// SliverAnimatedList( -/// key: _listKey, -/// initialItemCount: _list.length, -/// itemBuilder: _buildItem, -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// } -/// -/// typedef RemovedItemBuilder = Widget Function(int item, BuildContext context, Animation animation); -/// -/// // Keeps a Dart [List] in sync with an [AnimatedList]. -/// // -/// // The [insert] and [removeAt] methods apply to both the internal list and -/// // the animated list that belongs to [listKey]. -/// // -/// // This class only exposes as much of the Dart List API as is needed by the -/// // sample app. More list methods are easily added, however methods that -/// // mutate the list must make the same changes to the animated list in terms -/// // of [AnimatedListState.insertItem] and [AnimatedList.removeItem]. -/// class ListModel { -/// ListModel({ -/// required this.listKey, -/// required this.removedItemBuilder, -/// Iterable? initialItems, -/// }) : _items = List.from(initialItems ?? []); -/// -/// final GlobalKey listKey; -/// final RemovedItemBuilder removedItemBuilder; -/// final List _items; -/// -/// SliverAnimatedListState get _animatedList => listKey.currentState!; -/// -/// void insert(int index, E item) { -/// _items.insert(index, item); -/// _animatedList.insertItem(index); -/// } -/// -/// E removeAt(int index) { -/// final E removedItem = _items.removeAt(index); -/// if (removedItem != null) { -/// _animatedList.removeItem( -/// index, -/// (BuildContext context, Animation animation) => removedItemBuilder(index, context, animation), -/// ); -/// } -/// return removedItem; -/// } -/// -/// int get length => _items.length; -/// -/// E operator [](int index) => _items[index]; -/// -/// int indexOf(E item) => _items.indexOf(item); -/// } -/// -/// // Displays its integer item as 'Item N' on a Card whose color is based on -/// // the item's value. -/// // -/// // The card turns gray when [selected] is true. This widget's height -/// // is based on the [animation] parameter. It varies as the animation value -/// // transitions from 0.0 to 1.0. -/// class CardItem extends StatelessWidget { -/// const CardItem({ -/// Key? key, -/// this.onTap, -/// this.selected = false, -/// required this.animation, -/// required this.item, -/// }) : assert(item >= 0), -/// super(key: key); -/// -/// final Animation animation; -/// final VoidCallback? onTap; -/// final int item; -/// final bool selected; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Padding( -/// padding: -/// const EdgeInsets.only( -/// left: 2.0, -/// right: 2.0, -/// top: 2.0, -/// bottom: 0.0, -/// ), -/// child: SizeTransition( -/// axis: Axis.vertical, -/// sizeFactor: animation, -/// child: GestureDetector( -/// onTap: onTap, -/// child: SizedBox( -/// height: 80.0, -/// child: Card( -/// color: selected -/// ? Colors.black12 -/// : Colors.primaries[item % Colors.primaries.length], -/// child: Center( -/// child: Text( -/// 'Item $item', -/// style: Theme.of(context).textTheme.headline4, -/// ), -/// ), -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/animated_list/sliver_animated_list.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/animated_size.dart b/packages/flutter/lib/src/widgets/animated_size.dart index 902f12944e..4ff314683a 100644 --- a/packages/flutter/lib/src/widgets/animated_size.dart +++ b/packages/flutter/lib/src/widgets/animated_size.dart @@ -15,34 +15,7 @@ import 'ticker_provider.dart'; /// This example makes a [Container] react to being touched, causing the child /// of the [AnimatedSize] widget, here a [FlutterLogo], to animate. /// -/// ```dart -/// class _MyStatefulWidgetState extends State { -/// double _size = 50.0; -/// bool _large = false; -/// -/// void _updateSize() { -/// setState(() { -/// _size = _large ? 250.0 : 100.0; -/// _large = !_large; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return GestureDetector( -/// onTap: () => _updateSize(), -/// child: Container( -/// color: Colors.amberAccent, -/// child: AnimatedSize( -/// curve: Curves.easeIn, -/// duration: const Duration(seconds: 1), -/// child: FlutterLogo(size: _size), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/animated_size/animated_size.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/animated_switcher.dart b/packages/flutter/lib/src/widgets/animated_switcher.dart index 79d169748f..9fcf6ba757 100644 --- a/packages/flutter/lib/src/widgets/animated_switcher.dart +++ b/packages/flutter/lib/src/widgets/animated_switcher.dart @@ -93,43 +93,7 @@ typedef AnimatedSwitcherLayoutBuilder = Widget Function(Widget? currentChild, Li /// This sample shows a counter that animates the scale of a text widget /// whenever the value changes. /// -/// ```dart -/// int _count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.white, -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// AnimatedSwitcher( -/// duration: const Duration(milliseconds: 500), -/// transitionBuilder: (Widget child, Animation animation) { -/// return ScaleTransition(child: child, scale: animation); -/// }, -/// child: Text( -/// '$_count', -/// // This key causes the AnimatedSwitcher to interpret this as a "new" -/// // child each time the count changes, so that it will begin its animation -/// // when the count changes. -/// key: ValueKey(_count), -/// style: Theme.of(context).textTheme.headline4, -/// ), -/// ), -/// ElevatedButton( -/// child: const Text('Increment'), -/// onPressed: () { -/// setState(() { -/// _count += 1; -/// }); -/// }, -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/animated_switcher/animated_switcher.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/async.dart b/packages/flutter/lib/src/widgets/async.dart index 9a776108fb..7cbbac860f 100644 --- a/packages/flutter/lib/src/widgets/async.dart +++ b/packages/flutter/lib/src/widgets/async.dart @@ -367,116 +367,13 @@ typedef AsyncWidgetBuilder = Widget Function(BuildContext context, AsyncSnaps /// to be processed. /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This sample shows a [StreamBuilder] that listens to a Stream that emits bids /// for an auction. Every time the StreamBuilder receives a bid from the Stream, /// it will display the price of the bid below an icon. If the Stream emits an /// error, the error is displayed below an error icon. When the Stream finishes /// emitting bids, the final price is displayed. /// -/// ```dart -/// final Stream _bids = (() async* { -/// await Future.delayed(const Duration(seconds: 1)); -/// yield 1; -/// await Future.delayed(const Duration(seconds: 1)); -/// })(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline2!, -/// textAlign: TextAlign.center, -/// child: Container( -/// alignment: FractionalOffset.center, -/// color: Colors.white, -/// child: StreamBuilder( -/// stream: _bids, -/// builder: (BuildContext context, AsyncSnapshot snapshot) { -/// List children; -/// if (snapshot.hasError) { -/// children = [ -/// const Icon( -/// Icons.error_outline, -/// color: Colors.red, -/// size: 60, -/// ), -/// Padding( -/// padding: const EdgeInsets.only(top: 16), -/// child: Text('Error: ${snapshot.error}'), -/// ), -/// Padding( -/// padding: const EdgeInsets.only(top: 8), -/// child: Text('Stack trace: ${snapshot.stackTrace}'), -/// ), -/// ]; -/// } else { -/// switch (snapshot.connectionState) { -/// case ConnectionState.none: -/// children = const [ -/// Icon( -/// Icons.info, -/// color: Colors.blue, -/// size: 60, -/// ), -/// Padding( -/// padding: EdgeInsets.only(top: 16), -/// child: Text('Select a lot'), -/// ) -/// ]; -/// break; -/// case ConnectionState.waiting: -/// children = const [ -/// SizedBox( -/// child: CircularProgressIndicator(), -/// width: 60, -/// height: 60, -/// ), -/// Padding( -/// padding: EdgeInsets.only(top: 16), -/// child: Text('Awaiting bids...'), -/// ) -/// ]; -/// break; -/// case ConnectionState.active: -/// children = [ -/// const Icon( -/// Icons.check_circle_outline, -/// color: Colors.green, -/// size: 60, -/// ), -/// Padding( -/// padding: const EdgeInsets.only(top: 16), -/// child: Text('\$${snapshot.data}'), -/// ) -/// ]; -/// break; -/// case ConnectionState.done: -/// children = [ -/// const Icon( -/// Icons.info, -/// color: Colors.blue, -/// size: 60, -/// ), -/// Padding( -/// padding: const EdgeInsets.only(top: 16), -/// child: Text('\$${snapshot.data} (closed)'), -/// ) -/// ]; -/// break; -/// } -/// } -/// -/// return Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// crossAxisAlignment: CrossAxisAlignment.center, -/// children: children, -/// ); -/// }, -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/async/stream_builder.0.dart ** /// {@end-tool} /// /// See also: @@ -610,77 +507,13 @@ class StreamBuilder extends StreamBuilderBase> { /// may appear for the latter, depending on how the stream is implemented. /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This sample shows a [FutureBuilder] that displays a loading spinner while it /// loads data. It displays a success icon and text if the [Future] completes /// with a result, or an error icon and text if the [Future] completes with an /// error. Assume the `_calculation` field is set by pressing a button elsewhere /// in the UI. /// -/// ```dart -/// final Future _calculation = Future.delayed( -/// const Duration(seconds: 2), -/// () => 'Data Loaded', -/// ); -/// -/// @override -/// Widget build(BuildContext context) { -/// return DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline2!, -/// textAlign: TextAlign.center, -/// child: FutureBuilder( -/// future: _calculation, // a previously-obtained Future or null -/// builder: (BuildContext context, AsyncSnapshot snapshot) { -/// List children; -/// if (snapshot.hasData) { -/// children = [ -/// const Icon( -/// Icons.check_circle_outline, -/// color: Colors.green, -/// size: 60, -/// ), -/// Padding( -/// padding: const EdgeInsets.only(top: 16), -/// child: Text('Result: ${snapshot.data}'), -/// ) -/// ]; -/// } else if (snapshot.hasError) { -/// children = [ -/// const Icon( -/// Icons.error_outline, -/// color: Colors.red, -/// size: 60, -/// ), -/// Padding( -/// padding: const EdgeInsets.only(top: 16), -/// child: Text('Error: ${snapshot.error}'), -/// ) -/// ]; -/// } else { -/// children = const [ -/// SizedBox( -/// child: CircularProgressIndicator(), -/// width: 60, -/// height: 60, -/// ), -/// Padding( -/// padding: EdgeInsets.only(top: 16), -/// child: Text('Awaiting result...'), -/// ) -/// ]; -/// } -/// return Center( -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// crossAxisAlignment: CrossAxisAlignment.center, -/// children: children, -/// ), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/async/future_builder.0.dart ** /// {@end-tool} // TODO(ianh): remove unreachable code above once https://github.com/dart-lang/sdk/issues/35520 is fixed class FutureBuilder extends StatefulWidget { diff --git a/packages/flutter/lib/src/widgets/autocomplete.dart b/packages/flutter/lib/src/widgets/autocomplete.dart index 5eb804c71c..3e95138201 100644 --- a/packages/flutter/lib/src/widgets/autocomplete.dart +++ b/packages/flutter/lib/src/widgets/autocomplete.dart @@ -87,86 +87,7 @@ typedef AutocompleteOptionToString = String Function(T option) /// This example shows how to create a very basic autocomplete widget using the /// [fieldViewBuilder] and [optionsViewBuilder] parameters. /// -/// ```dart main -/// import 'package:flutter/material.dart'; -/// import 'package:flutter/widgets.dart'; -/// -/// void main() => runApp(const AutocompleteExampleApp()); -/// -/// class AutocompleteExampleApp extends StatelessWidget { -/// const AutocompleteExampleApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('RawAutocomplete Basic'), -/// ), -/// body: const Center( -/// child: AutocompleteBasicExample(), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// class AutocompleteBasicExample extends StatelessWidget { -/// const AutocompleteBasicExample({Key? key}) : super(key: key); -/// -/// static const List _options = [ -/// 'aardvark', -/// 'bobcat', -/// 'chameleon', -/// ]; -/// -/// @override -/// Widget build(BuildContext context) { -/// return RawAutocomplete( -/// optionsBuilder: (TextEditingValue textEditingValue) { -/// return _options.where((String option) { -/// return option.contains(textEditingValue.text.toLowerCase()); -/// }); -/// }, -/// fieldViewBuilder: (BuildContext context, TextEditingController textEditingController, FocusNode focusNode, VoidCallback onFieldSubmitted) { -/// return TextFormField( -/// controller: textEditingController, -/// focusNode: focusNode, -/// onFieldSubmitted: (String value) { -/// onFieldSubmitted(); -/// }, -/// ); -/// }, -/// optionsViewBuilder: (BuildContext context, AutocompleteOnSelected onSelected, Iterable options) { -/// return Align( -/// alignment: Alignment.topLeft, -/// child: Material( -/// elevation: 4.0, -/// child: SizedBox( -/// height: 200.0, -/// child: ListView.builder( -/// padding: const EdgeInsets.all(8.0), -/// itemCount: options.length, -/// itemBuilder: (BuildContext context, int index) { -/// final String option = options.elementAt(index); -/// return GestureDetector( -/// onTap: () { -/// onSelected(option); -/// }, -/// child: ListTile( -/// title: Text(option), -/// ), -/// ); -/// }, -/// ), -/// ), -/// ), -/// ); -/// }, -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.0.dart ** /// {@end-tool} /// /// The type parameter T represents the type of the options. Most commonly this @@ -179,309 +100,13 @@ typedef AutocompleteOptionToString = String Function(T option) /// This example is similar to the previous example, but it uses a custom T data /// type instead of directly using String. /// -/// ```dart main -/// import 'package:flutter/material.dart'; -/// import 'package:flutter/widgets.dart'; -/// -/// void main() => runApp(const AutocompleteExampleApp()); -/// -/// class AutocompleteExampleApp extends StatelessWidget { -/// const AutocompleteExampleApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('RawAutocomplete Custom Type'), -/// ), -/// body: const Center( -/// child: AutocompleteCustomTypeExample(), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// // An example of a type that someone might want to autocomplete a list of. -/// @immutable -/// class User { -/// const User({ -/// required this.email, -/// required this.name, -/// }); -/// -/// final String email; -/// final String name; -/// -/// @override -/// String toString() { -/// return '$name, $email'; -/// } -/// -/// @override -/// bool operator ==(Object other) { -/// if (other.runtimeType != runtimeType) { -/// return false; -/// } -/// return other is User -/// && other.name == name -/// && other.email == email; -/// } -/// -/// @override -/// int get hashCode => hashValues(email, name); -/// } -/// -/// class AutocompleteCustomTypeExample extends StatelessWidget { -/// const AutocompleteCustomTypeExample({Key? key}) : super(key: key); -/// -/// static const List _userOptions = [ -/// User(name: 'Alice', email: 'alice@example.com'), -/// User(name: 'Bob', email: 'bob@example.com'), -/// User(name: 'Charlie', email: 'charlie123@gmail.com'), -/// ]; -/// -/// static String _displayStringForOption(User option) => option.name; -/// -/// @override -/// Widget build(BuildContext context) { -/// return RawAutocomplete( -/// optionsBuilder: (TextEditingValue textEditingValue) { -/// return _userOptions.where((User option) { -/// // Search based on User.toString, which includes both name and -/// // email, even though the display string is just the name. -/// return option.toString().contains(textEditingValue.text.toLowerCase()); -/// }); -/// }, -/// displayStringForOption: _displayStringForOption, -/// fieldViewBuilder: (BuildContext context, TextEditingController textEditingController, FocusNode focusNode, VoidCallback onFieldSubmitted) { -/// return TextFormField( -/// controller: textEditingController, -/// focusNode: focusNode, -/// onFieldSubmitted: (String value) { -/// onFieldSubmitted(); -/// }, -/// ); -/// }, -/// optionsViewBuilder: (BuildContext context, AutocompleteOnSelected onSelected, Iterable options) { -/// return Align( -/// alignment: Alignment.topLeft, -/// child: Material( -/// elevation: 4.0, -/// child: SizedBox( -/// height: 200.0, -/// child: ListView.builder( -/// padding: const EdgeInsets.all(8.0), -/// itemCount: options.length, -/// itemBuilder: (BuildContext context, int index) { -/// final User option = options.elementAt(index); -/// return GestureDetector( -/// onTap: () { -/// onSelected(option); -/// }, -/// child: ListTile( -/// title: Text(_displayStringForOption(option)), -/// ), -/// ); -/// }, -/// ), -/// ), -/// ), -/// ); -/// }, -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.1.dart ** /// {@end-tool} /// /// {@tool dartpad --template=freeform} /// This example shows the use of RawAutocomplete in a form. /// -/// ```dart main -/// import 'package:flutter/material.dart'; -/// import 'package:flutter/widgets.dart'; -/// -/// void main() => runApp(const AutocompleteExampleApp()); -/// -/// class AutocompleteExampleApp extends StatelessWidget { -/// const AutocompleteExampleApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('RawAutocomplete Form'), -/// ), -/// body: const Center( -/// child: AutocompleteFormExample(), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// class AutocompleteFormExample extends StatefulWidget { -/// const AutocompleteFormExample({Key? key}) : super(key: key); -/// -/// @override -/// AutocompleteFormExampleState createState() => AutocompleteFormExampleState(); -/// } -/// -/// class AutocompleteFormExampleState extends State { -/// final GlobalKey _formKey = GlobalKey(); -/// final TextEditingController _textEditingController = TextEditingController(); -/// String? _dropdownValue; -/// String? _autocompleteSelection; -/// -/// static const List _options = [ -/// 'aardvark', -/// 'bobcat', -/// 'chameleon', -/// ]; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Form( -/// key: _formKey, -/// child: Column( -/// children: [ -/// DropdownButtonFormField( -/// value: _dropdownValue, -/// icon: const Icon(Icons.arrow_downward), -/// hint: const Text('This is a regular DropdownButtonFormField'), -/// iconSize: 24, -/// elevation: 16, -/// style: const TextStyle(color: Colors.deepPurple), -/// onChanged: (String? newValue) { -/// setState(() { -/// _dropdownValue = newValue; -/// }); -/// }, -/// items: ['One', 'Two', 'Free', 'Four'] -/// .map>((String value) { -/// return DropdownMenuItem( -/// value: value, -/// child: Text(value), -/// ); -/// }).toList(), -/// validator: (String? value) { -/// if (value == null) { -/// return 'Must make a selection.'; -/// } -/// return null; -/// }, -/// ), -/// TextFormField( -/// controller: _textEditingController, -/// decoration: const InputDecoration( -/// hintText: 'This is a regular TextFormField', -/// ), -/// validator: (String? value) { -/// if (value == null || value.isEmpty) { -/// return "Can't be empty."; -/// } -/// return null; -/// }, -/// ), -/// RawAutocomplete( -/// optionsBuilder: (TextEditingValue textEditingValue) { -/// return _options.where((String option) { -/// return option.contains(textEditingValue.text.toLowerCase()); -/// }); -/// }, -/// onSelected: (String selection) { -/// setState(() { -/// _autocompleteSelection = selection; -/// }); -/// }, -/// fieldViewBuilder: (BuildContext context, TextEditingController textEditingController, FocusNode focusNode, VoidCallback onFieldSubmitted) { -/// return TextFormField( -/// controller: textEditingController, -/// decoration: const InputDecoration( -/// hintText: 'This is a RawAutocomplete!', -/// ), -/// focusNode: focusNode, -/// onFieldSubmitted: (String value) { -/// onFieldSubmitted(); -/// }, -/// validator: (String? value) { -/// if (!_options.contains(value)) { -/// return 'Nothing selected.'; -/// } -/// return null; -/// }, -/// ); -/// }, -/// optionsViewBuilder: (BuildContext context, AutocompleteOnSelected onSelected, Iterable options) { -/// return Align( -/// alignment: Alignment.topLeft, -/// child: Material( -/// elevation: 4.0, -/// child: SizedBox( -/// height: 200.0, -/// child: ListView.builder( -/// padding: const EdgeInsets.all(8.0), -/// itemCount: options.length, -/// itemBuilder: (BuildContext context, int index) { -/// final String option = options.elementAt(index); -/// return GestureDetector( -/// onTap: () { -/// onSelected(option); -/// }, -/// child: ListTile( -/// title: Text(option), -/// ), -/// ); -/// }, -/// ), -/// ), -/// ), -/// ); -/// }, -/// ), -/// ElevatedButton( -/// onPressed: () { -/// FocusScope.of(context).unfocus(); -/// if (!_formKey.currentState!.validate()) { -/// return; -/// } -/// showDialog( -/// context: context, -/// builder: (BuildContext context) { -/// return AlertDialog( -/// title: const Text('Successfully submitted'), -/// content: SingleChildScrollView( -/// child: ListBody( -/// children: [ -/// Text('DropdownButtonFormField: "$_dropdownValue"'), -/// Text('TextFormField: "${_textEditingController.text}"'), -/// Text('RawAutocomplete: "$_autocompleteSelection"'), -/// ], -/// ), -/// ), -/// actions: [ -/// TextButton( -/// child: const Text('Ok'), -/// onPressed: () { -/// Navigator.of(context).pop(); -/// }, -/// ), -/// ], -/// ); -/// }, -/// ); -/// }, -/// child: const Text('Submit'), -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.2.dart ** /// {@end-tool} /// /// See also: @@ -544,89 +169,7 @@ class RawAutocomplete extends StatefulWidget { /// This examples shows how to create an autocomplete widget with the text /// field in the AppBar and the results in the main body of the app. /// - /// ```dart main - /// import 'package:flutter/material.dart'; - /// import 'package:flutter/widgets.dart'; - /// - /// void main() => runApp(const AutocompleteExampleApp()); - /// - /// class AutocompleteExampleApp extends StatelessWidget { - /// const AutocompleteExampleApp({Key? key}) : super(key: key); - /// - /// @override - /// Widget build(BuildContext context) { - /// return const MaterialApp( - /// home: RawAutocompleteSplit(), - /// ); - /// } - /// } - /// - /// const List _options = [ - /// 'aardvark', - /// 'bobcat', - /// 'chameleon', - /// ]; - /// - /// class RawAutocompleteSplit extends StatefulWidget { - /// const RawAutocompleteSplit({Key? key}) : super(key: key); - /// - /// @override - /// RawAutocompleteSplitState createState() => RawAutocompleteSplitState(); - /// } - /// - /// class RawAutocompleteSplitState extends State { - /// final TextEditingController _textEditingController = TextEditingController(); - /// final FocusNode _focusNode = FocusNode(); - /// final GlobalKey _autocompleteKey = GlobalKey(); - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar( - /// // This is where the real field is being built. - /// title: TextFormField( - /// controller: _textEditingController, - /// focusNode: _focusNode, - /// decoration: const InputDecoration( - /// hintText: 'Split RawAutocomplete App', - /// ), - /// onFieldSubmitted: (String value) { - /// RawAutocomplete.onFieldSubmitted(_autocompleteKey); - /// }, - /// ), - /// ), - /// body: Align( - /// alignment: Alignment.topLeft, - /// child: RawAutocomplete( - /// key: _autocompleteKey, - /// focusNode: _focusNode, - /// textEditingController: _textEditingController, - /// optionsBuilder: (TextEditingValue textEditingValue) { - /// return _options.where((String option) { - /// return option.contains(textEditingValue.text.toLowerCase()); - /// }).toList(); - /// }, - /// optionsViewBuilder: (BuildContext context, AutocompleteOnSelected onSelected, Iterable options) { - /// return Material( - /// elevation: 4.0, - /// child: ListView( - /// children: options.map((String option) => GestureDetector( - /// onTap: () { - /// onSelected(option); - /// }, - /// child: ListTile( - /// title: Text(option), - /// ), - /// )).toList(), - /// ), - /// ); - /// }, - /// ), - /// ), - /// ); - /// } - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/autocomplete/raw_autocomplete.focus_node.0.dart ** /// {@end-tool} /// {@endtemplate} /// diff --git a/packages/flutter/lib/src/widgets/autofill.dart b/packages/flutter/lib/src/widgets/autofill.dart index d1bd1afcdf..40b8647e63 100644 --- a/packages/flutter/lib/src/widgets/autofill.dart +++ b/packages/flutter/lib/src/widgets/autofill.dart @@ -52,95 +52,10 @@ enum AutofillContextAction { /// [Form] can be saved for future autofill by the platform. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// An example form with autofillable fields grouped into different /// `AutofillGroup`s. /// -/// ```dart -/// bool isSameAddress = true; -/// final TextEditingController shippingAddress1 = TextEditingController(); -/// final TextEditingController shippingAddress2 = TextEditingController(); -/// final TextEditingController billingAddress1 = TextEditingController(); -/// final TextEditingController billingAddress2 = TextEditingController(); -/// -/// final TextEditingController creditCardNumber = TextEditingController(); -/// final TextEditingController creditCardSecurityCode = TextEditingController(); -/// -/// final TextEditingController phoneNumber = TextEditingController(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return ListView( -/// children: [ -/// const Text('Shipping address'), -/// // The address fields are grouped together as some platforms are -/// // capable of autofilling all of these fields in one go. -/// AutofillGroup( -/// child: Column( -/// children: [ -/// TextField( -/// controller: shippingAddress1, -/// autofillHints: const [AutofillHints.streetAddressLine1], -/// ), -/// TextField( -/// controller: shippingAddress2, -/// autofillHints: const [AutofillHints.streetAddressLine2], -/// ), -/// ], -/// ), -/// ), -/// const Text('Billing address'), -/// Checkbox( -/// value: isSameAddress, -/// onChanged: (bool? newValue) { -/// if (newValue != null) { -/// setState(() { isSameAddress = newValue; }); -/// } -/// }, -/// ), -/// // Again the address fields are grouped together for the same reason. -/// if (!isSameAddress) AutofillGroup( -/// child: Column( -/// children: [ -/// TextField( -/// controller: billingAddress1, -/// autofillHints: const [AutofillHints.streetAddressLine1], -/// ), -/// TextField( -/// controller: billingAddress2, -/// autofillHints: const [AutofillHints.streetAddressLine2], -/// ), -/// ], -/// ), -/// ), -/// const Text('Credit Card Information'), -/// // The credit card number and the security code are grouped together -/// // as some platforms are capable of autofilling both fields. -/// AutofillGroup( -/// child: Column( -/// children: [ -/// TextField( -/// controller: creditCardNumber, -/// autofillHints: const [AutofillHints.creditCardNumber], -/// ), -/// TextField( -/// controller: creditCardSecurityCode, -/// autofillHints: const [AutofillHints.creditCardSecurityCode], -/// ), -/// ], -/// ), -/// ), -/// const Text('Contact Phone Number'), -/// // The phone number field can still be autofilled despite lacking an -/// // `AutofillScope`. -/// TextField( -/// controller: phoneNumber, -/// autofillHints: const [AutofillHints.telephoneNumber], -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/autofill/autofill_group.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index b077b49a62..351338bd19 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -1050,44 +1050,11 @@ class PhysicalModel extends SingleChildRenderObjectWidget { /// as rectangles with rounded corners. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This example shows how to use a [PhysicalShape] on a centered [SizedBox] /// to clip it to a rounded rectangle using a [ShapeBorderClipper] and give it /// an orange color along with a shadow. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('PhysicalShape Sample'), -/// ), -/// body: Center( -/// child: PhysicalShape( -/// elevation: 5.0, -/// child: const SizedBox( -/// child: Center( -/// child: Text( -/// 'Hello, World!', -/// style: TextStyle( -/// color: Colors.white, -/// fontSize: 20.0, -/// ), -/// ), -/// ), -/// height: 200.0, -/// width: 200.0, -/// ), -/// clipper: ShapeBorderClipper( -/// shape: RoundedRectangleBorder( -/// borderRadius: BorderRadius.circular(10.0), -/// ) -/// ), -/// color: Colors.orange, -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/physical_shape.0.dart ** /// {@end-tool} /// /// See also: @@ -1568,24 +1535,10 @@ class CompositedTransformFollower extends SingleChildRenderObjectWidget { /// {@youtube 560 315 https://www.youtube.com/watch?v=T4Uehk3_wlY} /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// In this example, the image is stretched to fill the entire [Container], which would /// not happen normally without using FittedBox. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// height: 400, -/// width: 300, -/// color: Colors.red, -/// child: FittedBox( -/// child: Image.network('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'), -/// fit: BoxFit.fill, -/// ), -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/widgets/basic/fitted_box.0.dart ** /// {@end-tool} /// /// See also: @@ -2744,30 +2697,11 @@ class UnconstrainedBox extends StatelessWidget { /// {@youtube 560 315 https://www.youtube.com/watch?v=PEsY654EGZ0} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows a [FractionallySizedBox] whose one child is 50% of /// the box's size per the width and height factor parameters, and centered /// within that box by the alignment parameter. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return SizedBox.expand( -/// child: FractionallySizedBox( -/// widthFactor: 0.5, -/// heightFactor: 0.5, -/// alignment: FractionalOffset.center, -/// child: DecoratedBox( -/// decoration: BoxDecoration( -/// border: Border.all( -/// color: Colors.blue, -/// width: 4, -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/fractionally_sized_box.0.dart ** /// {@end-tool} /// /// See also: @@ -3117,57 +3051,12 @@ class SizedOverflowBox extends SingleChildRenderObjectWidget { /// keeping it alive in an [Offstage] subtree. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// This example shows a [FlutterLogo] widget when the `_offstage` member field /// is false, and hides it without any room in the parent when it is true. When /// offstage, this app displays a button to get the logo size, which will be /// displayed in a [SnackBar]. /// -/// ```dart -/// final GlobalKey _key = GlobalKey(); -/// bool _offstage = true; -/// -/// Size _getFlutterLogoSize() { -/// final RenderBox renderLogo = _key.currentContext!.findRenderObject()! as RenderBox; -/// return renderLogo.size; -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// Offstage( -/// offstage: _offstage, -/// child: FlutterLogo( -/// key: _key, -/// size: 150.0, -/// ), -/// ), -/// Text('Flutter logo is offstage: $_offstage'), -/// ElevatedButton( -/// child: const Text('Toggle Offstage Value'), -/// onPressed: () { -/// setState(() { -/// _offstage = !_offstage; -/// }); -/// }, -/// ), -/// if (_offstage) -/// ElevatedButton( -/// child: const Text('Get Flutter Logo size'), -/// onPressed: () { -/// ScaffoldMessenger.of(context).showSnackBar( -/// SnackBar( -/// content: Text('Flutter Logo size is ${_getFlutterLogoSize()}'), -/// ), -/// ); -/// } -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/offstage.0.dart ** /// {@end-tool} /// /// See also: @@ -3241,7 +3130,6 @@ class _OffstageElement extends SingleChildRenderObjectElement { /// by applying the aspect ratio to the maximum height. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This examples shows how AspectRatio sets width when its parent's width /// constraint is infinite. Since its parent's allowed height is a fixed value, /// the actual width is determined via the given AspectRatio. @@ -3249,22 +3137,7 @@ class _OffstageElement extends SingleChildRenderObjectElement { /// Since the height is fixed at 100.0 in this example and the aspect ratio is /// set to 16 / 9, the width should then be 100.0 / 9 * 16. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.blue, -/// alignment: Alignment.center, -/// width: double.infinity, -/// height: 100.0, -/// child: AspectRatio( -/// aspectRatio: 16 / 9, -/// child: Container( -/// color: Colors.green, -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/aspect_ratio.0.dart ** /// {@end-tool} /// /// Now consider a second example, this time with an aspect ratio of 2.0 and @@ -3274,24 +3147,8 @@ class _OffstageElement extends SingleChildRenderObjectElement { /// /// {@tool dartpad --template=stateless_widget_scaffold} /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.blue, -/// alignment: Alignment.center, -/// width: 100.0, -/// height: 100.0, -/// child: AspectRatio( -/// aspectRatio: 2.0, -/// child: Container( -/// width: 100.0, -/// height: 50.0, -/// color: Colors.green, -/// ), -/// ), -/// ); -/// } -/// ``` +/// +/// ** See code in examples/api/lib/widgets/basic/aspect_ratio.1.dart ** /// {@end-tool} /// /// In that same situation, if the aspect ratio is 0.5, we'll also select a @@ -3308,24 +3165,8 @@ class _OffstageElement extends SingleChildRenderObjectElement { /// /// {@tool dartpad --template=stateless_widget_scaffold} /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.blue, -/// alignment: Alignment.center, -/// width: 100.0, -/// height: 100.0, -/// child: AspectRatio( -/// aspectRatio: 0.5, -/// child: Container( -/// width: 100.0, -/// height: 50.0, -/// color: Colors.green, -/// ), -/// ), -/// ); -/// } -/// ``` +/// +/// ** See code in examples/api/lib/widgets/basic/aspect_ratio.2.dart ** /// {@end-tool} /// /// See also: @@ -5173,37 +5014,7 @@ class Flexible extends ParentDataWidget { /// /// ![This results in two thin blue boxes with a larger amber box in between.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_column.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Expanded Column Sample'), -/// ), -/// body: Center( -/// child: Column( -/// children: [ -/// Container( -/// color: Colors.blue, -/// height: 100, -/// width: 100, -/// ), -/// Expanded( -/// child: Container( -/// color: Colors.amber, -/// width: 100, -/// ), -/// ), -/// Container( -/// color: Colors.blue, -/// height: 100, -/// width: 100, -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/expanded.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_material} @@ -5212,40 +5023,7 @@ class Flexible extends ParentDataWidget { /// /// ![This results in a wide amber box, followed by a thin blue box, with a medium width amber box at the end.](https://flutter.github.io/assets-for-api-docs/assets/widgets/expanded_row.png) /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Expanded Row Sample'), -/// ), -/// body: Center( -/// child: Row( -/// children: [ -/// Expanded( -/// flex: 2, -/// child: Container( -/// color: Colors.amber, -/// height: 100, -/// ), -/// ), -/// Container( -/// color: Colors.blue, -/// height: 100, -/// width: 50, -/// ), -/// Expanded( -/// flex: 1, -/// child: Container( -/// color: Colors.amber, -/// height: 100, -/// ), -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/expanded.1.dart ** /// {@end-tool} /// /// See also: @@ -5558,125 +5336,11 @@ class Wrap extends MultiChildRenderObjectWidget { /// /// /// {@tool dartpad --template=freeform} -/// /// This example uses the [Flow] widget to create a menu that opens and closes /// as it is interacted with, shown above. The color of the button in the menu /// changes to indicate which one has been selected. /// -/// ```dart main -/// import 'package:flutter/material.dart'; -/// -/// void main() => runApp(const FlowApp()); -/// -/// class FlowApp extends StatelessWidget { -/// const FlowApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('Flow Example'), -/// ), -/// body: const FlowMenu(), -/// ), -/// ); -/// } -/// } -/// -/// class FlowMenu extends StatefulWidget { -/// const FlowMenu({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _FlowMenuState(); -/// } -/// -/// class _FlowMenuState extends State with SingleTickerProviderStateMixin { -/// late AnimationController menuAnimation; -/// IconData lastTapped = Icons.notifications; -/// final List menuItems = [ -/// Icons.home, -/// Icons.new_releases, -/// Icons.notifications, -/// Icons.settings, -/// Icons.menu, -/// ]; -/// -/// void _updateMenu(IconData icon) { -/// if (icon != Icons.menu) { -/// setState(() => lastTapped = icon); -/// } -/// } -/// -/// @override -/// void initState() { -/// super.initState(); -/// menuAnimation = AnimationController( -/// duration: const Duration(milliseconds: 250), -/// vsync: this, -/// ); -/// } -/// -/// Widget flowMenuItem(IconData icon) { -/// final double buttonDiameter = MediaQuery.of(context).size.width / menuItems.length; -/// return Padding( -/// padding: const EdgeInsets.symmetric(vertical: 8.0), -/// child: RawMaterialButton( -/// fillColor: lastTapped == icon ? Colors.amber[700] : Colors.blue, -/// splashColor: Colors.amber[100], -/// shape: const CircleBorder(), -/// constraints: BoxConstraints.tight(Size(buttonDiameter, buttonDiameter)), -/// onPressed: () { -/// _updateMenu(icon); -/// menuAnimation.status == AnimationStatus.completed -/// ? menuAnimation.reverse() -/// : menuAnimation.forward(); -/// }, -/// child: Icon( -/// icon, -/// color: Colors.white, -/// size: 45.0, -/// ), -/// ), -/// ); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Flow( -/// delegate: FlowMenuDelegate(menuAnimation: menuAnimation), -/// children: menuItems.map((IconData icon) => flowMenuItem(icon)).toList(), -/// ); -/// } -/// } -/// -/// class FlowMenuDelegate extends FlowDelegate { -/// FlowMenuDelegate({required this.menuAnimation}) : super(repaint: menuAnimation); -/// -/// final Animation menuAnimation; -/// -/// @override -/// bool shouldRepaint(FlowMenuDelegate oldDelegate) { -/// return menuAnimation != oldDelegate.menuAnimation; -/// } -/// -/// @override -/// void paintChildren(FlowPaintingContext context) { -/// double dx = 0.0; -/// for (int i = 0; i < context.childCount; ++i) { -/// dx = context.getChildSize(i)!.width * i; -/// context.paintChild( -/// i, -/// transform: Matrix4.translationValues( -/// dx * menuAnimation.value, -/// 0, -/// 0, -/// ), -/// ); -/// } -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/flow.0.dart ** /// {@end-tool} /// class Flow extends MultiChildRenderObjectWidget { @@ -6378,63 +6042,7 @@ class WidgetToRenderBoxAdapter extends LeafRenderObjectWidget { /// This example makes a [Container] react to being touched, showing a count of /// the number of pointer downs and ups. /// -/// ```dart imports -/// import 'package:flutter/widgets.dart'; -/// ``` -/// -/// ```dart -/// int _downCounter = 0; -/// int _upCounter = 0; -/// double x = 0.0; -/// double y = 0.0; -/// -/// void _incrementDown(PointerEvent details) { -/// _updateLocation(details); -/// setState(() { -/// _downCounter++; -/// }); -/// } -/// void _incrementUp(PointerEvent details) { -/// _updateLocation(details); -/// setState(() { -/// _upCounter++; -/// }); -/// } -/// void _updateLocation(PointerEvent details) { -/// setState(() { -/// x = details.position.dx; -/// y = details.position.dy; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return ConstrainedBox( -/// constraints: BoxConstraints.tight(const Size(300.0, 200.0)), -/// child: Listener( -/// onPointerDown: _incrementDown, -/// onPointerMove: _updateLocation, -/// onPointerUp: _incrementUp, -/// child: Container( -/// color: Colors.lightBlueAccent, -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// const Text('You have pressed or released in this area this many times:'), -/// Text( -/// '$_downCounter presses\n$_upCounter releases', -/// style: Theme.of(context).textTheme.headline4, -/// ), -/// Text( -/// 'The cursor is here: (${x.toStringAsFixed(2)}, ${y.toStringAsFixed(2)})', -/// ), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/listener.0.dart ** /// {@end-tool} class Listener extends SingleChildRenderObjectWidget { /// Creates a widget that forwards point events to callbacks. @@ -6548,61 +6156,7 @@ class Listener extends SingleChildRenderObjectWidget { /// This example makes a [Container] react to being entered by a mouse /// pointer, showing a count of the number of entries and exits. /// -/// ```dart imports -/// import 'package:flutter/widgets.dart'; -/// ``` -/// -/// ```dart -/// int _enterCounter = 0; -/// int _exitCounter = 0; -/// double x = 0.0; -/// double y = 0.0; -/// -/// void _incrementEnter(PointerEvent details) { -/// setState(() { -/// _enterCounter++; -/// }); -/// } -/// void _incrementExit(PointerEvent details) { -/// setState(() { -/// _exitCounter++; -/// }); -/// } -/// void _updateLocation(PointerEvent details) { -/// setState(() { -/// x = details.position.dx; -/// y = details.position.dy; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return ConstrainedBox( -/// constraints: BoxConstraints.tight(const Size(300.0, 200.0)), -/// child: MouseRegion( -/// onEnter: _incrementEnter, -/// onHover: _updateLocation, -/// onExit: _incrementExit, -/// child: Container( -/// color: Colors.lightBlueAccent, -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// const Text('You have entered or exited this box this many times:'), -/// Text( -/// '$_enterCounter Entries\n$_exitCounter Exits', -/// style: Theme.of(context).textTheme.headline4, -/// ), -/// Text( -/// 'The cursor is here: (${x.toStringAsFixed(2)}, ${y.toStringAsFixed(2)})', -/// ), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/mouse_region.0.dart ** /// {@end-tool} /// /// See also: @@ -6719,26 +6273,7 @@ class MouseRegion extends StatefulWidget { /// that unconditionally creates the `MouseRegion`, you can ignore the /// aforementioned restriction. /// - /// ```dart - /// bool hovered = false; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Container( - /// height: 100, - /// width: 100, - /// decoration: BoxDecoration(color: hovered ? Colors.yellow : Colors.blue), - /// child: MouseRegion( - /// onEnter: (_) { - /// setState(() { hovered = true; }); - /// }, - /// onExit: (_) { - /// setState(() { hovered = false; }); - /// }, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/basic/mouse_region.on_exit.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_scaffold_center} @@ -6750,89 +6285,7 @@ class MouseRegion extends StatefulWidget { /// the `MouseRegion`, it simply trigger the exit callback during that event /// as well. /// - /// ```dart preamble - /// // A region that hides its content one second after being hovered. - /// class MyTimedButton extends StatefulWidget { - /// const MyTimedButton({ Key? key, required this.onEnterButton, required this.onExitButton }) - /// : super(key: key); - /// - /// final VoidCallback onEnterButton; - /// final VoidCallback onExitButton; - /// - /// @override - /// State createState() => _MyTimedButton(); - /// } - /// - /// class _MyTimedButton extends State { - /// bool regionIsHidden = false; - /// bool hovered = false; - /// - /// Future startCountdown() async { - /// await Future.delayed(const Duration(seconds: 1)); - /// hideButton(); - /// } - /// - /// void hideButton() { - /// setState(() { regionIsHidden = true; }); - /// // This statement is necessary. - /// if (hovered) { - /// widget.onExitButton(); - /// } - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return SizedBox( - /// width: 100, - /// height: 100, - /// child: MouseRegion( - /// child: regionIsHidden ? null : MouseRegion( - /// onEnter: (_) { - /// widget.onEnterButton(); - /// setState(() { hovered = true; }); - /// startCountdown(); - /// }, - /// onExit: (_) { - /// setState(() { hovered = false; }); - /// widget.onExitButton(); - /// }, - /// child: Container(color: Colors.red), - /// ), - /// ), - /// ); - /// } - /// } - /// ``` - /// - /// ```dart - /// Key key = UniqueKey(); - /// bool hovering = false; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Column( - /// children: [ - /// ElevatedButton( - /// onPressed: () { - /// setState(() { key = UniqueKey(); }); - /// }, - /// child: const Text('Refresh'), - /// ), - /// if (hovering) const Text('Hovering'), - /// if (!hovering) const Text('Not hovering'), - /// MyTimedButton( - /// key: key, - /// onEnterButton: () { - /// setState(() { hovering = true; }); - /// }, - /// onExitButton: () { - /// setState(() { hovering = false; }); - /// }, - /// ), - /// ], - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/basic/mouse_region.on_exit.1.dart ** /// {@end-tool} /// /// {@macro flutter.widgets.MouseRegion.onEnter.triggerTime} @@ -7039,46 +6492,7 @@ class RepaintBoundary extends SingleChildRenderObjectWidget { /// not be tapped. When [ignoring] is set to `false` anything /// inside the `Column` can be tapped. /// -/// ```dart -/// bool ignoring = false; -/// void setIgnoring(bool newValue) { -/// setState(() { -/// ignoring = newValue; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// centerTitle: true, -/// title: ElevatedButton( -/// onPressed: () { -/// setIgnoring(!ignoring); -/// }, -/// child: Text( -/// ignoring ? 'Set ignoring to false' : 'Set ignoring to true', -/// ), -/// ), -/// ), -/// body: Center( -/// child: IgnorePointer( -/// ignoring: ignoring, -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.spaceEvenly, -/// children: [ -/// Text('Ignoring: $ignoring'), -/// ElevatedButton( -/// onPressed: () {}, -/// child: const Text('Click me!'), -/// ), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/ignore_pointer.0.dart ** /// {@end-tool} /// /// See also: @@ -7149,37 +6563,7 @@ class IgnorePointer extends SingleChildRenderObjectWidget { /// top of the stack, which absorbs pointer events, preventing its child button /// __and__ the button below it in the stack from receiving the pointer events. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Stack( -/// alignment: AlignmentDirectional.center, -/// children: [ -/// SizedBox( -/// width: 200.0, -/// height: 100.0, -/// child: ElevatedButton( -/// onPressed: () {}, -/// child: null, -/// ), -/// ), -/// SizedBox( -/// width: 100.0, -/// height: 200.0, -/// child: AbsorbPointer( -/// absorbing: true, -/// child: ElevatedButton( -/// style: ElevatedButton.styleFrom( -/// primary: Colors.blue.shade200, -/// ), -/// onPressed: () {}, -/// child: null, -/// ), -/// ), -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/basic/absorb_pointer.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/color_filter.dart b/packages/flutter/lib/src/widgets/color_filter.dart index fa4c0e9b02..c94b7fe1d9 100644 --- a/packages/flutter/lib/src/widgets/color_filter.dart +++ b/packages/flutter/lib/src/widgets/color_filter.dart @@ -18,36 +18,10 @@ import 'framework.dart'; /// {@youtube 560 315 https://www.youtube.com/watch?v=F7Cll22Dno8} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// These two images have two [ColorFilter]s applied with different [BlendMode]s, /// one with red color and [BlendMode.modulate] another with a grey color and [BlendMode.saturation]. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return SingleChildScrollView( -/// child: Column( -/// children: [ -/// ColorFiltered( -/// colorFilter: const ColorFilter.mode( -/// Colors.red, -/// BlendMode.modulate, -/// ), -/// child: Image.network( -/// 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl-2.jpg'), -/// ), -/// ColorFiltered( -/// colorFilter: const ColorFilter.mode( -/// Colors.grey, -/// BlendMode.saturation, -/// ), -/// child: Image.network( -/// 'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/color_filter/color_filtered.0.dart ** ///{@end-tool} /// /// See Also: diff --git a/packages/flutter/lib/src/widgets/dismissible.dart b/packages/flutter/lib/src/widgets/dismissible.dart index 290c5d9932..eaeb339c1b 100644 --- a/packages/flutter/lib/src/widgets/dismissible.dart +++ b/packages/flutter/lib/src/widgets/dismissible.dart @@ -66,40 +66,11 @@ enum DismissDirection { /// {@youtube 560 315 https://www.youtube.com/watch?v=iEMgjrfuc58} /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// This sample shows how you can use the [Dismissible] widget to /// remove list items using swipe gestures. Swipe any of the list /// tiles to the left or right to dismiss them from the [ListView]. /// -/// ```dart -/// List items = List.generate(100, (int index) => index); -/// -/// @override -/// Widget build(BuildContext context) { -/// return ListView.builder( -/// itemCount: items.length, -/// padding: const EdgeInsets.symmetric(vertical: 16), -/// itemBuilder: (BuildContext context, int index) { -/// return Dismissible( -/// child: ListTile( -/// title: Text( -/// 'Item ${items[index]}', -/// ), -/// ), -/// background: Container( -/// color: Colors.green, -/// ), -/// key: ValueKey(items[index]), -/// onDismissed: (DismissDirection direction) { -/// setState(() { -/// items.removeAt(index); -/// }); -/// }, -/// ); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/dismissible/dismissible.0.dart ** /// {@end-tool} /// /// Backgrounds can be used to implement the "leave-behind" idiom. If a background diff --git a/packages/flutter/lib/src/widgets/drag_target.dart b/packages/flutter/lib/src/widgets/drag_target.dart index 2f833a85dc..a9243ac147 100644 --- a/packages/flutter/lib/src/widgets/drag_target.dart +++ b/packages/flutter/lib/src/widgets/drag_target.dart @@ -166,72 +166,11 @@ enum DragAnchor { /// {@youtube 560 315 https://www.youtube.com/watch?v=QzA4c4QHZCY} /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// The following example has a [Draggable] widget along with a [DragTarget] /// in a row demonstrating an incremented `acceptedData` integer value when /// you drag the element to the target. /// -/// ```dart -/// int acceptedData = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Row( -/// mainAxisAlignment: MainAxisAlignment.spaceEvenly, -/// children: [ -/// Draggable( -/// // Data is the value this Draggable stores. -/// data: 10, -/// child: Container( -/// height: 100.0, -/// width: 100.0, -/// color: Colors.lightGreenAccent, -/// child: const Center( -/// child: Text('Draggable'), -/// ), -/// ), -/// feedback: Container( -/// color: Colors.deepOrange, -/// height: 100, -/// width: 100, -/// child: const Icon(Icons.directions_run), -/// ), -/// childWhenDragging: Container( -/// height: 100.0, -/// width: 100.0, -/// color: Colors.pinkAccent, -/// child: const Center( -/// child: Text('Child When Dragging'), -/// ), -/// ), -/// ), -/// DragTarget( -/// builder: ( -/// BuildContext context, -/// List accepted, -/// List rejected, -/// ) { -/// return Container( -/// height: 100.0, -/// width: 100.0, -/// color: Colors.cyan, -/// child: Center( -/// child: Text('Value is updated to: $acceptedData'), -/// ), -/// ); -/// }, -/// onAccept: (int data) { -/// setState(() { -/// acceptedData += data; -/// }); -/// }, -/// ), -/// ], -/// ); -/// } -/// -/// ``` -/// +/// ** See code in examples/api/lib/widgets/drag_target/draggable.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 726514a285..9123167990 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -90,42 +90,7 @@ const int _kObscureShowLatestCharCursorTicks = 3; /// change listener forces the entered text to be lower case and keeps the /// cursor at the end of the input. /// -/// ```dart -/// final TextEditingController _controller = TextEditingController(); -/// -/// @override -/// void initState() { -/// super.initState(); -/// _controller.addListener(() { -/// final String text = _controller.text.toLowerCase(); -/// _controller.value = _controller.value.copyWith( -/// text: text, -/// selection: TextSelection(baseOffset: text.length, extentOffset: text.length), -/// composing: TextRange.empty, -/// ); -/// }); -/// } -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Container( -/// alignment: Alignment.center, -/// padding: const EdgeInsets.all(6), -/// child: TextFormField( -/// controller: _controller, -/// decoration: const InputDecoration(border: OutlineInputBorder()), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/editable_text/text_editing_controller.0.dart ** /// {@end-tool} /// /// See also: @@ -955,55 +920,10 @@ class EditableText extends StatefulWidget { /// [TextEditingController.addListener]. /// /// {@tool dartpad --template=stateful_widget_material} - /// /// This example shows how onChanged could be used to check the TextField's /// current value each time the user inserts or deletes a character. /// - /// ```dart - /// final TextEditingController _controller = TextEditingController(); - /// - /// @override - /// void dispose() { - /// _controller.dispose(); - /// super.dispose(); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// body: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// children: [ - /// const Text('What number comes next in the sequence?'), - /// const Text('1, 1, 2, 3, 5, 8...?'), - /// TextField( - /// controller: _controller, - /// onChanged: (String value) async { - /// if (value != '13') { - /// return; - /// } - /// await showDialog( - /// context: context, - /// builder: (BuildContext context) { - /// return AlertDialog( - /// title: const Text('That is correct!'), - /// content: const Text ('13 is the right answer.'), - /// actions: [ - /// TextButton( - /// onPressed: () { Navigator.pop(context); }, - /// child: const Text('OK'), - /// ), - /// ], - /// ); - /// }, - /// ); - /// }, - /// ), - /// ], - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/editable_text/editable_text.on_changed.0.dart ** /// {@end-tool} /// {@endtemplate} /// diff --git a/packages/flutter/lib/src/widgets/focus_manager.dart b/packages/flutter/lib/src/widgets/focus_manager.dart index ea1715aff1..fb8fa12b83 100644 --- a/packages/flutter/lib/src/widgets/focus_manager.dart +++ b/packages/flutter/lib/src/widgets/focus_manager.dart @@ -378,109 +378,7 @@ enum UnfocusDisposition { /// [Focus] or [FocusScope] widgets. See the [Focus] widget for a similar /// example using [Focus] and [FocusScope] widgets. /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart preamble -/// class ColorfulButton extends StatefulWidget { -/// const ColorfulButton({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _ColorfulButtonState(); -/// } -/// -/// class _ColorfulButtonState extends State { -/// late FocusNode _node; -/// bool _focused = false; -/// late FocusAttachment _nodeAttachment; -/// Color _color = Colors.white; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _node = FocusNode(debugLabel: 'Button'); -/// _node.addListener(_handleFocusChange); -/// _nodeAttachment = _node.attach(context, onKey: _handleKeyPress); -/// } -/// -/// void _handleFocusChange() { -/// if (_node.hasFocus != _focused) { -/// setState(() { -/// _focused = _node.hasFocus; -/// }); -/// } -/// } -/// -/// KeyEventResult _handleKeyPress(FocusNode node, RawKeyEvent event) { -/// if (event is RawKeyDownEvent) { -/// print('Focus node ${node.debugLabel} got key event: ${event.logicalKey}'); -/// if (event.logicalKey == LogicalKeyboardKey.keyR) { -/// print('Changing color to red.'); -/// setState(() { -/// _color = Colors.red; -/// }); -/// return KeyEventResult.handled; -/// } else if (event.logicalKey == LogicalKeyboardKey.keyG) { -/// print('Changing color to green.'); -/// setState(() { -/// _color = Colors.green; -/// }); -/// return KeyEventResult.handled; -/// } else if (event.logicalKey == LogicalKeyboardKey.keyB) { -/// print('Changing color to blue.'); -/// setState(() { -/// _color = Colors.blue; -/// }); -/// return KeyEventResult.handled; -/// } -/// } -/// return KeyEventResult.ignored; -/// } -/// -/// @override -/// void dispose() { -/// _node.removeListener(_handleFocusChange); -/// // The attachment will automatically be detached in dispose(). -/// _node.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// _nodeAttachment.reparent(); -/// return GestureDetector( -/// onTap: () { -/// if (_focused) { -/// _node.unfocus(); -/// } else { -/// _node.requestFocus(); -/// } -/// }, -/// child: Center( -/// child: Container( -/// width: 400, -/// height: 100, -/// color: _focused ? _color : Colors.white, -/// alignment: Alignment.center, -/// child: Text( -/// _focused ? "I'm in color! Press R,G,B!" : 'Press to focus'), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// final TextTheme textTheme = Theme.of(context).textTheme; -/// return DefaultTextStyle( -/// style: textTheme.headline4!, -/// child: const ColorfulButton(), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/focus_manager/focus_node.0.dart ** /// {@end-tool} /// /// See also: @@ -881,73 +779,7 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier { /// Try pressing the TAB key after unfocusing to see what the next widget /// chosen is. /// - /// ```dart imports - /// import 'package:flutter/foundation.dart'; - /// ``` - /// - /// ```dart - /// UnfocusDisposition disposition = UnfocusDisposition.scope; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Material( - /// child: Container( - /// color: Colors.white, - /// child: Column( - /// mainAxisAlignment: MainAxisAlignment.center, - /// children: [ - /// Wrap( - /// children: List.generate(4, (int index) { - /// return const SizedBox( - /// width: 200, - /// child: Padding( - /// padding: EdgeInsets.all(8.0), - /// child: TextField( - /// decoration: InputDecoration(border: OutlineInputBorder()), - /// ), - /// ), - /// ); - /// }), - /// ), - /// Row( - /// mainAxisAlignment: MainAxisAlignment.spaceAround, - /// children: [ - /// ...List.generate(UnfocusDisposition.values.length, - /// (int index) { - /// return Row( - /// mainAxisSize: MainAxisSize.min, - /// children: [ - /// Radio( - /// groupValue: disposition, - /// onChanged: (UnfocusDisposition? value) { - /// setState(() { - /// if (value != null) { - /// disposition = value; - /// } - /// }); - /// }, - /// value: UnfocusDisposition.values[index], - /// ), - /// Text(describeEnum(UnfocusDisposition.values[index])), - /// ], - /// ); - /// }), - /// OutlinedButton( - /// child: const Text('UNFOCUS'), - /// onPressed: () { - /// setState(() { - /// primaryFocus!.unfocus(disposition: disposition); - /// }); - /// }, - /// ), - /// ], - /// ), - /// ], - /// ), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/focus_manager/focus_node.unfocus.0.dart ** /// {@end-tool} void unfocus({ UnfocusDisposition disposition = UnfocusDisposition.scope, diff --git a/packages/flutter/lib/src/widgets/focus_scope.dart b/packages/flutter/lib/src/widgets/focus_scope.dart index 6e5d7a6915..571f80d6d6 100644 --- a/packages/flutter/lib/src/widgets/focus_scope.dart +++ b/packages/flutter/lib/src/widgets/focus_scope.dart @@ -53,79 +53,7 @@ import 'inherited_notifier.dart'; /// widgets. See [FocusNode] for a similar example that doesn't use [Focus] or /// [FocusScope]. /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart -/// Color _color = Colors.white; -/// -/// KeyEventResult _handleKeyPress(FocusNode node, RawKeyEvent event) { -/// if (event is RawKeyDownEvent) { -/// print('Focus node ${node.debugLabel} got key event: ${event.logicalKey}'); -/// if (event.logicalKey == LogicalKeyboardKey.keyR) { -/// print('Changing color to red.'); -/// setState(() { -/// _color = Colors.red; -/// }); -/// return KeyEventResult.handled; -/// } else if (event.logicalKey == LogicalKeyboardKey.keyG) { -/// print('Changing color to green.'); -/// setState(() { -/// _color = Colors.green; -/// }); -/// return KeyEventResult.handled; -/// } else if (event.logicalKey == LogicalKeyboardKey.keyB) { -/// print('Changing color to blue.'); -/// setState(() { -/// _color = Colors.blue; -/// }); -/// return KeyEventResult.handled; -/// } -/// } -/// return KeyEventResult.ignored; -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// final TextTheme textTheme = Theme.of(context).textTheme; -/// return FocusScope( -/// debugLabel: 'Scope', -/// autofocus: true, -/// child: DefaultTextStyle( -/// style: textTheme.headline4!, -/// child: Focus( -/// onKey: _handleKeyPress, -/// debugLabel: 'Button', -/// child: Builder( -/// builder: (BuildContext context) { -/// final FocusNode focusNode = Focus.of(context); -/// final bool hasFocus = focusNode.hasFocus; -/// return GestureDetector( -/// onTap: () { -/// if (hasFocus) { -/// focusNode.unfocus(); -/// } else { -/// focusNode.requestFocus(); -/// } -/// }, -/// child: Center( -/// child: Container( -/// width: 400, -/// height: 100, -/// alignment: Alignment.center, -/// color: hasFocus ? _color : Colors.white, -/// child: Text(hasFocus ? "I'm in color! Press R,G,B!" : 'Press to focus'), -/// ), -/// ), -/// ); -/// }, -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/focus_scope/focus.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_material} @@ -137,56 +65,7 @@ import 'inherited_notifier.dart'; /// consider using a [FocusableActionDetector], which combines several different /// widgets to provide those capabilities. /// -/// ```dart preamble -/// class FocusableText extends StatelessWidget { -/// const FocusableText(this.data, { -/// Key? key, -/// required this.autofocus, -/// }) : super(key: key); -/// -/// /// The string to display as the text for this widget. -/// final String data; -/// -/// /// Whether or not to focus this widget initially if nothing else is focused. -/// final bool autofocus; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Focus( -/// autofocus: autofocus, -/// child: Builder(builder: (BuildContext context) { -/// // The contents of this Builder are being made focusable. It is inside -/// // of a Builder because the builder provides the correct context -/// // variable for Focus.of() to be able to find the Focus widget that is -/// // the Builder's parent. Without the builder, the context variable used -/// // would be the one given the FocusableText build function, and that -/// // would start looking for a Focus widget ancestor of the FocusableText -/// // instead of finding the one inside of its build function. -/// return Container( -/// padding: const EdgeInsets.all(8.0), -/// // Change the color based on whether or not this Container has focus. -/// color: Focus.of(context).hasPrimaryFocus ? Colors.black12 : null, -/// child: Text(data), -/// ); -/// }), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: ListView.builder( -/// itemBuilder: (BuildContext context, int index) => FocusableText( -/// 'Item $index', -/// autofocus: index == 0, -/// ), -/// itemCount: 50, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/focus_scope/focus.1.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material} @@ -197,62 +76,7 @@ import 'inherited_notifier.dart'; /// which it has requested focus is drawn, so it is OK to call /// [FocusNode.requestFocus] on a node which is not yet in the focus tree. /// -/// ```dart -/// int focusedChild = 0; -/// List children = []; -/// List childFocusNodes = []; -/// -/// @override -/// void initState() { -/// super.initState(); -/// // Add the first child. -/// _addChild(); -/// } -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// for (final FocusNode node in childFocusNodes) { -/// node.dispose(); -/// } -/// } -/// -/// void _addChild() { -/// // Calling requestFocus here creates a deferred request for focus, since the -/// // node is not yet part of the focus tree. -/// childFocusNodes -/// .add(FocusNode(debugLabel: 'Child ${children.length}')..requestFocus()); -/// -/// children.add(Padding( -/// padding: const EdgeInsets.all(2.0), -/// child: ActionChip( -/// focusNode: childFocusNodes.last, -/// label: Text('CHILD ${children.length}'), -/// onPressed: () {}, -/// ), -/// )); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: Wrap( -/// children: children, -/// ), -/// ), -/// floatingActionButton: FloatingActionButton( -/// onPressed: () { -/// setState(() { -/// focusedChild = children.length; -/// _addChild(); -/// }); -/// }, -/// child: const Icon(Icons.add), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/focus_scope/focus.2.dart ** /// {@end-tool} /// /// See also: @@ -770,142 +594,7 @@ class _FocusState extends State { /// portion of the app. In this case, restricting focus to the visible part of a /// Stack. /// -/// ```dart preamble -/// /// A demonstration pane. -/// /// -/// /// This is just a separate widget to simplify the example. -/// class Pane extends StatelessWidget { -/// const Pane({ -/// Key? key, -/// required this.focusNode, -/// this.onPressed, -/// required this.backgroundColor, -/// required this.icon, -/// this.child, -/// }) : super(key: key); -/// -/// final FocusNode focusNode; -/// final VoidCallback? onPressed; -/// final Color backgroundColor; -/// final Widget icon; -/// final Widget? child; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Material( -/// color: backgroundColor, -/// child: Stack( -/// fit: StackFit.expand, -/// children: [ -/// Center( -/// child: child, -/// ), -/// Align( -/// alignment: Alignment.topLeft, -/// child: IconButton( -/// autofocus: true, -/// focusNode: focusNode, -/// onPressed: onPressed, -/// icon: icon, -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// bool backdropIsVisible = false; -/// FocusNode backdropNode = FocusNode(debugLabel: 'Close Backdrop Button'); -/// FocusNode foregroundNode = FocusNode(debugLabel: 'Option Button'); -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// backdropNode.dispose(); -/// foregroundNode.dispose(); -/// } -/// -/// Widget _buildStack(BuildContext context, BoxConstraints constraints) { -/// final Size stackSize = constraints.biggest; -/// return Stack( -/// fit: StackFit.expand, -/// // The backdrop is behind the front widget in the Stack, but the widgets -/// // would still be active and traversable without the FocusScope. -/// children: [ -/// // TRY THIS: Try removing this FocusScope entirely to see how it affects -/// // the behavior. Without this FocusScope, the "ANOTHER BUTTON TO FOCUS" -/// // button, and the IconButton in the backdrop Pane would be focusable -/// // even when the backdrop wasn't visible. -/// FocusScope( -/// // TRY THIS: Try commenting out this line. Notice that the focus -/// // starts on the backdrop and is stuck there? It seems like the app is -/// // non-responsive, but it actually isn't. This line makes sure that -/// // this focus scope and its children can't be focused when they're not -/// // visible. It might help to make the background color of the -/// // foreground pane semi-transparent to see it clearly. -/// canRequestFocus: backdropIsVisible, -/// child: Pane( -/// icon: const Icon(Icons.close), -/// focusNode: backdropNode, -/// backgroundColor: Colors.lightBlue, -/// onPressed: () => setState(() => backdropIsVisible = false), -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// // This button would be not visible, but still focusable from -/// // the foreground pane without the FocusScope. -/// ElevatedButton( -/// onPressed: () => print('You pressed the other button!'), -/// child: const Text('ANOTHER BUTTON TO FOCUS'), -/// ), -/// DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline2!, -/// child: const Text('BACKDROP')), -/// ], -/// ), -/// ), -/// ), -/// AnimatedPositioned( -/// curve: Curves.easeInOut, -/// duration: const Duration(milliseconds: 300), -/// top: backdropIsVisible ? stackSize.height * 0.9 : 0.0, -/// width: stackSize.width, -/// height: stackSize.height, -/// onEnd: () { -/// if (backdropIsVisible) { -/// backdropNode.requestFocus(); -/// } else { -/// foregroundNode.requestFocus(); -/// } -/// }, -/// child: Pane( -/// icon: const Icon(Icons.menu), -/// focusNode: foregroundNode, -/// // TRY THIS: Try changing this to Colors.green.withOpacity(0.8) to see for -/// // yourself that the hidden components do/don't get focus. -/// backgroundColor: Colors.green, -/// onPressed: backdropIsVisible -/// ? null -/// : () => setState(() => backdropIsVisible = true), -/// child: DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline2!, -/// child: const Text('FOREGROUND')), -/// ), -/// ), -/// ], -/// ); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// // Use a LayoutBuilder so that we can base the size of the stack on the size -/// // of its parent. -/// return LayoutBuilder(builder: _buildStack); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/focus_scope/focus_scope.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/focus_traversal.dart b/packages/flutter/lib/src/widgets/focus_traversal.dart index 09a6fcb25b..178b36e1d1 100644 --- a/packages/flutter/lib/src/widgets/focus_traversal.dart +++ b/packages/flutter/lib/src/widgets/focus_traversal.dart @@ -1272,71 +1272,7 @@ class _OrderedFocusInfo { /// example, the focus order goes from bottom right (the "One" button) to top /// left (the "Six" button). /// -/// ```dart preamble -/// class DemoButton extends StatelessWidget { -/// const DemoButton({ -/// Key? key, -/// required this.name, -/// this.autofocus = false, -/// required this.order, -/// }) : super(key: key); -/// -/// final String name; -/// final bool autofocus; -/// final double order; -/// -/// void _handleOnPressed() { -/// print('Button $name pressed.'); -/// debugDumpFocusTree(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return FocusTraversalOrder( -/// order: NumericFocusOrder(order), -/// child: TextButton( -/// autofocus: autofocus, -/// onPressed: () => _handleOnPressed(), -/// child: Text(name), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return FocusTraversalGroup( -/// policy: OrderedTraversalPolicy(), -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// Row( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: const [ -/// DemoButton(name: 'Six', order: 6), -/// ], -/// ), -/// Row( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: const [ -/// DemoButton(name: 'Five', order: 5), -/// DemoButton(name: 'Four', order: 4), -/// ], -/// ), -/// Row( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: const [ -/// DemoButton(name: 'Three', order: 3), -/// DemoButton(name: 'Two', order: 2), -/// DemoButton(name: 'One', order: 1, autofocus: true), -/// ], -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart ** /// {@end-tool} /// /// See also: @@ -1491,166 +1427,7 @@ class FocusTraversalOrder extends InheritedWidget { /// right to left), and the third ignores the numerical order assigned to it and /// traverses in widget order. /// -/// ```dart preamble -/// /// A button wrapper that adds either a numerical or lexical order, depending on -/// /// the type of T. -/// class OrderedButton extends StatefulWidget { -/// const OrderedButton({ -/// Key? key, -/// required this.name, -/// this.canRequestFocus = true, -/// this.autofocus = false, -/// required this.order, -/// }) : super(key: key); -/// -/// final String name; -/// final bool canRequestFocus; -/// final bool autofocus; -/// final T order; -/// -/// @override -/// State> createState() => _OrderedButtonState(); -/// } -/// -/// class _OrderedButtonState extends State> { -/// late FocusNode focusNode; -/// -/// @override -/// void initState() { -/// super.initState(); -/// focusNode = FocusNode( -/// debugLabel: widget.name, -/// canRequestFocus: widget.canRequestFocus, -/// ); -/// } -/// -/// @override -/// void dispose() { -/// focusNode.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// void didUpdateWidget(OrderedButton oldWidget) { -/// super.didUpdateWidget(oldWidget); -/// focusNode.canRequestFocus = widget.canRequestFocus; -/// } -/// -/// void _handleOnPressed() { -/// focusNode.requestFocus(); -/// print('Button ${widget.name} pressed.'); -/// debugDumpFocusTree(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// FocusOrder order; -/// if (widget.order is num) { -/// order = NumericFocusOrder((widget.order as num).toDouble()); -/// } else { -/// order = LexicalFocusOrder(widget.order.toString()); -/// } -/// -/// Color? overlayColor(Set states) { -/// if (states.contains(MaterialState.focused)) { -/// return Colors.red; -/// } -/// if (states.contains(MaterialState.hovered)) { -/// return Colors.blue; -/// } -/// return null; // defer to the default overlayColor -/// } -/// -/// Color? foregroundColor(Set states) { -/// if (states.contains(MaterialState.focused) || states.contains(MaterialState.hovered)) { -/// return Colors.white; -/// } -/// return null; // defer to the default foregroundColor -/// } -/// -/// return FocusTraversalOrder( -/// order: order, -/// child: Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: OutlinedButton( -/// focusNode: focusNode, -/// autofocus: widget.autofocus, -/// style: ButtonStyle( -/// overlayColor: MaterialStateProperty.resolveWith(overlayColor), -/// foregroundColor: MaterialStateProperty.resolveWith(foregroundColor), -/// ), -/// onPressed: () => _handleOnPressed(), -/// child: Text(widget.name), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.white, -/// child: FocusTraversalGroup( -/// policy: OrderedTraversalPolicy(), -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// // A group that is ordered with a numerical order, from left to right. -/// FocusTraversalGroup( -/// policy: OrderedTraversalPolicy(), -/// child: Row( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: List.generate(3, (int index) { -/// return OrderedButton( -/// name: 'num: $index', -/// // TRY THIS: change this to "3 - index" and see how the order changes. -/// order: index, -/// ); -/// }), -/// ), -/// ), -/// // A group that is ordered with a lexical order, from right to left. -/// FocusTraversalGroup( -/// policy: OrderedTraversalPolicy(), -/// child: Row( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: List.generate(3, (int index) { -/// // Order as "C" "B", "A". -/// final String order = -/// String.fromCharCode('A'.codeUnitAt(0) + (2 - index)); -/// return OrderedButton( -/// name: 'String: $order', -/// order: order, -/// ); -/// }), -/// ), -/// ), -/// // A group that orders in widget order, regardless of what the order is set to. -/// FocusTraversalGroup( -/// // Note that because this is NOT an OrderedTraversalPolicy, the -/// // assigned order of these OrderedButtons is ignored, and they -/// // are traversed in widget order. TRY THIS: change this to -/// // "OrderedTraversalPolicy()" and see that it now follows the -/// // numeric order set on them instead of the widget order. -/// policy: WidgetOrderTraversalPolicy(), -/// child: Row( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: List.generate(3, (int index) { -/// return OrderedButton( -/// name: 'ignored num: ${3 - index}', -/// order: 3 - index, -/// ); -/// }), -/// ), -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/form.dart b/packages/flutter/lib/src/widgets/form.dart index 90fd941b46..39175b5ddd 100644 --- a/packages/flutter/lib/src/widgets/form.dart +++ b/packages/flutter/lib/src/widgets/form.dart @@ -25,45 +25,7 @@ import 'will_pop_scope.dart'; /// /// ![](https://flutter.github.io/assets-for-api-docs/assets/widgets/form.png) /// -/// ```dart -/// final GlobalKey _formKey = GlobalKey(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return Form( -/// key: _formKey, -/// child: Column( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// children: [ -/// TextFormField( -/// decoration: const InputDecoration( -/// hintText: 'Enter your email', -/// ), -/// validator: (String? value) { -/// if (value == null || value.isEmpty) { -/// return 'Please enter some text'; -/// } -/// return null; -/// }, -/// ), -/// Padding( -/// padding: const EdgeInsets.symmetric(vertical: 16.0), -/// child: ElevatedButton( -/// onPressed: () { -/// // Validate will return true if the form is valid, or false if -/// // the form is invalid. -/// if (_formKey.currentState!.validate()) { -/// // Process data. -/// } -/// }, -/// child: const Text('Submit'), -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/form/form.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 5309a36811..5652210822 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -2336,49 +2336,7 @@ abstract class BuildContext { /// the layout size of the rendered tree. For some use cases, the simpler /// [Offstage] widget may be a better alternative to this approach. /// -/// ```dart imports -/// import 'package:flutter/rendering.dart'; -/// import 'package:flutter/widgets.dart'; -/// ``` -/// -/// ```dart -/// void main() { -/// WidgetsFlutterBinding.ensureInitialized(); -/// print(measureWidget(const SizedBox(width: 640, height: 480))); -/// } -/// -/// Size measureWidget(Widget widget) { -/// final PipelineOwner pipelineOwner = PipelineOwner(); -/// final MeasurementView rootView = pipelineOwner.rootNode = MeasurementView(); -/// final BuildOwner buildOwner = BuildOwner(focusManager: FocusManager()); -/// final RenderObjectToWidgetElement element = RenderObjectToWidgetAdapter( -/// container: rootView, -/// debugShortDescription: '[root]', -/// child: widget, -/// ).attachToRenderTree(buildOwner); -/// try { -/// rootView.scheduleInitialLayout(); -/// pipelineOwner.flushLayout(); -/// return rootView.size; -/// } finally { -/// // Clean up. -/// element.update(RenderObjectToWidgetAdapter(container: rootView)); -/// buildOwner.finalizeTree(); -/// } -/// } -/// -/// class MeasurementView extends RenderBox with RenderObjectWithChildMixin { -/// @override -/// void performLayout() { -/// assert(child != null); -/// child!.layout(const BoxConstraints(), parentUsesSize: true); -/// size = child!.size; -/// } -/// -/// @override -/// void debugAssertDoesMeetConstraints() => true; -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/framework/build_owner.0.dart ** /// {@end-tool} class BuildOwner { /// Creates an object that manages widgets. @@ -4416,37 +4374,9 @@ typedef ErrorWidgetBuilder = Widget Function(FlutterErrorDetails details); /// It is possible to override this widget. /// /// {@tool sample --template=freeform} -/// ```dart -/// import 'package:flutter/material.dart'; /// -/// void main() { -/// ErrorWidget.builder = (FlutterErrorDetails details) { -/// bool inDebug = false; -/// assert(() { inDebug = true; return true; }()); -/// // In debug mode, use the normal error widget which shows -/// // the error message: -/// if (inDebug) { -/// return ErrorWidget(details.exception); -/// } -/// // In release builds, show a yellow-on-blue message instead: -/// return Container( -/// alignment: Alignment.center, -/// child: const Text( -/// 'Error!', -/// style: TextStyle(color: Colors.yellow), -/// textDirection: TextDirection.ltr, -/// ), -/// ); -/// }; -/// // Here we would normally runApp() the root widget, but to demonstrate -/// // the error handling we artificially fail: -/// return runApp(Builder( -/// builder: (BuildContext context) { -/// throw 'oh no, an error'; -/// }, -/// )); -/// } -/// ``` +/// +/// ** See code in examples/api/lib/widgets/framework/error_widget.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/gesture_detector.dart b/packages/flutter/lib/src/widgets/gesture_detector.dart index d9caf37b8f..463f65b455 100644 --- a/packages/flutter/lib/src/widgets/gesture_detector.dart +++ b/packages/flutter/lib/src/widgets/gesture_detector.dart @@ -128,54 +128,14 @@ class GestureRecognizerFactoryWithHandlers extends /// of a [GestureDetector] for handling taps. /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This example contains a black light bulb wrapped in a [GestureDetector]. It /// turns the light bulb yellow when the "TURN LIGHT ON" button is tapped by /// setting the `_lights` field, and off again when "TURN LIGHT OFF" is tapped. /// -/// ```dart -/// bool _lightIsOn = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Container( -/// alignment: FractionalOffset.center, -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: Icon( -/// Icons.lightbulb_outline, -/// color: _lightIsOn ? Colors.yellow.shade600 : Colors.black, -/// size: 60, -/// ), -/// ), -/// GestureDetector( -/// onTap: () { -/// setState(() { -/// // Toggle light when tapped. -/// _lightIsOn = !_lightIsOn; -/// }); -/// }, -/// child: Container( -/// color: Colors.yellow.shade600, -/// padding: const EdgeInsets.all(8), -/// // Change button text when light changes state. -/// child: Text(_lightIsOn ? 'TURN LIGHT OFF' : 'TURN LIGHT ON'), -/// ), -/// ), -/// ], -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/gesture_detector/gesture_detector.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material} -/// /// This example uses a [Container] that wraps a [GestureDetector] widget which /// detects a tap. /// @@ -184,25 +144,7 @@ class GestureRecognizerFactoryWithHandlers extends /// tapped, the [Container] turns yellow by setting the `_color` field. When /// tapped again, it goes back to white. /// -/// ```dart -/// Color _color = Colors.white; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Container( -/// color: _color, -/// height: 200.0, -/// width: 200.0, -/// child: GestureDetector( -/// onTap: () { -/// setState(() { -/// _color == Colors.yellow ? _color = Colors.white : _color = Colors.yellow; -/// }); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/gesture_detector/gesture_detector.1.dart ** /// {@end-tool} /// /// ## Debugging diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index 0f82222907..00db1bdf1d 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -113,56 +113,7 @@ enum HeroFlightDirection { /// The Hero widget uses the matching tags to identify and execute this /// animation. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Column( -/// crossAxisAlignment: CrossAxisAlignment.start, -/// children: [ -/// const SizedBox( -/// height: 20.0, -/// ), -/// ListTile( -/// leading: Hero( -/// tag: 'hero-rectangle', -/// child: _blueRectangle(const Size(50, 50)), -/// ), -/// onTap: () => _gotoDetailsPage(context), -/// title: const Text('Tap on the icon to view hero animation transition.'), -/// ), -/// ], -/// ); -/// } -/// -/// Widget _blueRectangle(Size size) { -/// return Container( -/// width: size.width, -/// height: size.height, -/// color: Colors.blue, -/// ); -/// } -/// -/// void _gotoDetailsPage(BuildContext context) { -/// Navigator.of(context).push(MaterialPageRoute( -/// builder: (BuildContext context) => Scaffold( -/// appBar: AppBar( -/// title: const Text('second Page'), -/// ), -/// body: Center( -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// Hero( -/// tag: 'hero-rectangle', -/// child: _blueRectangle(const Size(200, 200)), -/// ), -/// ], -/// ), -/// ), -/// ), -/// )); -/// } -/// -/// ``` +/// ** See code in examples/api/lib/widgets/heroes/hero.0.dart ** /// {@end-tool} /// /// ## Discussion diff --git a/packages/flutter/lib/src/widgets/image.dart b/packages/flutter/lib/src/widgets/image.dart index f397d7fb94..614a3fc320 100644 --- a/packages/flutter/lib/src/widgets/image.dart +++ b/packages/flutter/lib/src/widgets/image.dart @@ -757,39 +757,13 @@ class Image extends StatefulWidget { /// {@endtemplate} /// /// {@tool dartpad --template=stateless_widget_material} - /// /// The following sample demonstrates how to use this builder to implement an /// image that fades in once it's been loaded. /// /// This sample contains a limited subset of the functionality that the /// [FadeInImage] widget provides out of the box. /// - /// ```dart - /// @override - /// Widget build(BuildContext context) { - /// return DecoratedBox( - /// decoration: BoxDecoration( - /// color: Colors.white, - /// border: Border.all(), - /// borderRadius: BorderRadius.circular(20), - /// ), - /// child: Image.network( - /// 'https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg', - /// frameBuilder: (BuildContext context, Widget child, int? frame, bool wasSynchronouslyLoaded) { - /// if (wasSynchronouslyLoaded) { - /// return child; - /// } - /// return AnimatedOpacity( - /// child: child, - /// opacity: frame == null ? 0 : 1, - /// duration: const Duration(seconds: 1), - /// curve: Curves.easeOut, - /// ); - /// }, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/image/image.frame_builder.0.dart ** /// {@end-tool} final ImageFrameBuilder? frameBuilder; @@ -823,36 +797,10 @@ class Image extends StatefulWidget { /// {@macro flutter.widgets.Image.frameBuilder.chainedBuildersExample} /// /// {@tool dartpad --template=stateless_widget_material} - /// /// The following sample uses [loadingBuilder] to show a /// [CircularProgressIndicator] while an image loads over the network. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return DecoratedBox( - /// decoration: BoxDecoration( - /// color: Colors.white, - /// border: Border.all(), - /// borderRadius: BorderRadius.circular(20), - /// ), - /// child: Image.network( - /// 'https://example.com/image.jpg', - /// loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) { - /// if (loadingProgress == null) { - /// return child; - /// } - /// return Center( - /// child: CircularProgressIndicator( - /// value: loadingProgress.expectedTotalBytes != null - /// ? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes! - /// : null, - /// ), - /// ); - /// }, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/image/image.loading_builder.0.dart ** /// {@end-tool} /// /// Run against a real-world image on a slow network, the previous example @@ -869,33 +817,10 @@ class Image extends StatefulWidget { /// the exception by providing a replacement widget, or rethrow the exception. /// /// {@tool dartpad --template=stateless_widget_material} - /// /// The following sample uses [errorBuilder] to show a '😢' in place of the /// image that fails to load, and prints the error to the console. /// - /// ```dart - /// Widget build(BuildContext context) { - /// return DecoratedBox( - /// decoration: BoxDecoration( - /// color: Colors.white, - /// border: Border.all(), - /// borderRadius: BorderRadius.circular(20), - /// ), - /// child: Image.network( - /// 'https://example.does.not.exist/image.jpg', - /// errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { - /// // Appropriate logging or analytics, e.g. - /// // myAnalytics.recordError( - /// // 'An error occurred loading "https://example.does.not.exist/image.jpg"', - /// // exception, - /// // stackTrace, - /// // ); - /// return const Text('😢'); - /// }, - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/image/image.error_builder.0.dart ** /// {@end-tool} final ImageErrorWidgetBuilder? errorBuilder; diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 87cfa3dfc3..a16fc21386 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -576,36 +576,11 @@ abstract class AnimatedWidgetBaseState exten /// {@youtube 560 315 https://www.youtube.com/watch?v=yI-8QHpGIP4} /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// The following example (depicted above) transitions an AnimatedContainer /// between two states. It adjusts the `height`, `width`, `color`, and /// [alignment] properties when tapped. /// -/// ```dart -/// bool selected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return GestureDetector( -/// onTap: () { -/// setState(() { -/// selected = !selected; -/// }); -/// }, -/// child: Center( -/// child: AnimatedContainer( -/// width: selected ? 200.0 : 100.0, -/// height: selected ? 100.0 : 200.0, -/// color: selected ? Colors.red : Colors.blue, -/// alignment: selected ? Alignment.center : AlignmentDirectional.topCenter, -/// duration: const Duration(seconds: 2), -/// curve: Curves.fastOutSlowIn, -/// child: const FlutterLogo(size: 75), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_container.0.dart ** /// {@end-tool} /// /// See also: @@ -815,44 +790,10 @@ class _AnimatedContainerState extends AnimatedWidgetBaseState /// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_padding.mp4} /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// The following code implements the [AnimatedPadding] widget, using a [curve] of /// [Curves.easeInOut]. /// -/// ```dart -/// double padValue = 0.0; -/// void _updatePadding(double value) { -/// setState(() { -/// padValue = value; -/// }); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// AnimatedPadding( -/// padding: EdgeInsets.all(padValue), -/// duration: const Duration(seconds: 2), -/// curve: Curves.easeInOut, -/// child: Container( -/// width: MediaQuery.of(context).size.width, -/// height: MediaQuery.of(context).size.height / 5, -/// color: Colors.blue, -/// ), -/// ), -/// Text('Padding: $padValue'), -/// ElevatedButton( -/// child: const Text('Change padding'), -/// onPressed: () { -/// _updatePadding(padValue == 0.0 ? 100.0 : 0.0); -/// } -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_padding.0.dart ** /// {@end-tool} /// /// See also: @@ -936,37 +877,10 @@ class _AnimatedPaddingState extends AnimatedWidgetBaseState { /// the lifecycle of the underlying [AnimationController]. /// /// {@tool dartpad --template=stateful_widget_scaffold} -/// /// The following code implements the [AnimatedAlign] widget, using a [curve] of /// [Curves.fastOutSlowIn]. /// -/// ```dart -/// bool selected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return GestureDetector( -/// onTap: () { -/// setState(() { -/// selected = !selected; -/// }); -/// }, -/// child: Center( -/// child: Container( -/// width: 250.0, -/// height: 250.0, -/// color: Colors.red, -/// child: AnimatedAlign( -/// alignment: selected ? Alignment.topRight : Alignment.bottomLeft, -/// duration: const Duration(seconds: 1), -/// curve: Curves.fastOutSlowIn, -/// child: const FlutterLogo(size: 50.0), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_align.0.dart ** /// {@end-tool} /// /// See also: @@ -1102,44 +1016,11 @@ class _AnimatedAlignState extends AnimatedWidgetBaseState { /// the lifecycle of the underlying [AnimationController]. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// The following example transitions an AnimatedPositioned /// between two states. It adjusts the `height`, `width`, and /// [Positioned] properties when tapped. /// -/// ```dart -/// bool selected = false; -/// -/// @override -/// Widget build(BuildContext context) { -/// return SizedBox( -/// width: 200, -/// height: 350, -/// child: Stack( -/// children: [ -/// AnimatedPositioned( -/// width: selected ? 200.0 : 50.0, -/// height: selected ? 50.0 : 200.0, -/// top: selected ? 50.0 : 150.0, -/// duration: const Duration(seconds: 2), -/// curve: Curves.fastOutSlowIn, -/// child: GestureDetector( -/// onTap: () { -/// setState(() { -/// selected = !selected; -/// }); -/// }, -/// child: Container( -/// color: Colors.blue, -/// child: const Center(child: Text('Tap me')), -/// ), -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_positioned.0.dart ** /// {@end-tool} /// /// See also: @@ -1682,47 +1563,10 @@ class _AnimatedRotationState extends ImplicitlyAnimatedWidgetState offset -= const Offset(0, 1)); -/// } -/// -/// void _slideDown() { -/// setState(() => offset += const Offset(0, 1)); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// ElevatedButton( -/// child: const Text('Slide up'), -/// onPressed: _slideUp, -/// ), -/// ElevatedButton( -/// child: const Text('Slide down'), -/// onPressed: _slideDown, -/// ), -/// Padding( -/// padding: const EdgeInsets.all(50), -/// child: AnimatedSlide( -/// offset: offset, -/// duration: const Duration(milliseconds: 500), -/// curve: Curves.easeInOut, -/// child: const FlutterLogo(), -/// ), -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/implicit_animations/animated_slide.0.dart ** /// {@end-tool} /// /// See also: @@ -1934,47 +1778,7 @@ class _AnimatedOpacityState extends ImplicitlyAnimatedWidgetState with SingleTickerProviderStateMixin { -/// bool _visible = true; -/// -/// @override -/// Widget build(BuildContext context) { -/// return CustomScrollView( -/// slivers: [ -/// SliverAnimatedOpacity( -/// opacity: _visible ? 1.0 : 0.0, -/// duration: const Duration(milliseconds: 500), -/// sliver: SliverFixedExtentList( -/// itemExtent: 100.0, -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// return Container( -/// color: index.isEven -/// ? Colors.indigo[200] -/// : Colors.orange[200], -/// ); -/// }, -/// childCount: 5, -/// ), -/// ), -/// ), -/// SliverToBoxAdapter( -/// child: FloatingActionButton( -/// onPressed: () { -/// setState(() { -/// _visible = !_visible; -/// }); -/// }, -/// tooltip: 'Toggle opacity', -/// child: const Icon(Icons.flip), -/// ) -/// ), -/// ] -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/implicit_animations/sliver_animated_opacity.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/inherited_notifier.dart b/packages/flutter/lib/src/widgets/inherited_notifier.dart index b45e274df2..136097cfef 100644 --- a/packages/flutter/lib/src/widgets/inherited_notifier.dart +++ b/packages/flutter/lib/src/widgets/inherited_notifier.dart @@ -29,7 +29,6 @@ import 'framework.dart'; /// rebuilt this frame. /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// This example shows three spinning squares that use the value of the notifier /// on an ancestor [InheritedNotifier] (`SpinModel`) to give them their /// rotation. The [InheritedNotifier] doesn't need to know about the children, @@ -43,76 +42,7 @@ import 'framework.dart'; /// just need to know that there is one in their ancestry. This can help with /// decoupling widgets from their models. /// -/// ```dart dartImports -/// import 'dart:math' as math; -/// ``` -/// -/// ```dart preamble -/// class SpinModel extends InheritedNotifier { -/// const SpinModel({ -/// Key? key, -/// AnimationController? notifier, -/// required Widget child, -/// }) : super(key: key, notifier: notifier, child: child); -/// -/// static double of(BuildContext context) { -/// return context.dependOnInheritedWidgetOfExactType()!.notifier!.value; -/// } -/// } -/// -/// class Spinner extends StatelessWidget { -/// const Spinner({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return Transform.rotate( -/// angle: SpinModel.of(context) * 2.0 * math.pi, -/// child: Container( -/// width: 100, -/// height: 100, -/// color: Colors.green, -/// child: const Center( -/// child: Text('Whee!'), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// late AnimationController _controller; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _controller = AnimationController( -/// duration: const Duration(seconds: 10), -/// vsync: this, -/// )..repeat(); -/// } -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return SpinModel( -/// notifier: _controller, -/// child: Row( -/// mainAxisAlignment: MainAxisAlignment.spaceAround, -/// children: const [ -/// Spinner(), -/// Spinner(), -/// Spinner(), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/inherited_notifier/inherited_notifier.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/inherited_theme.dart b/packages/flutter/lib/src/widgets/inherited_theme.dart index e1890e1352..bf0d47ee77 100644 --- a/packages/flutter/lib/src/widgets/inherited_theme.dart +++ b/packages/flutter/lib/src/widgets/inherited_theme.dart @@ -25,72 +25,7 @@ import 'framework.dart'; /// new route's Text widget will inherit the "something must be wrong" /// fallback text style, rather than the default text style defined in MyApp. /// -/// ```dart imports -/// import 'package:flutter/material.dart'; -/// ``` -/// -/// ```dart main -/// void main() { -/// runApp(const MyApp()); -/// } -/// ``` -/// -/// ```dart -/// class MyAppBody extends StatelessWidget { -/// const MyAppBody({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// final NavigatorState navigator = Navigator.of(context); -/// // This InheritedTheme.capture() saves references to themes that are -/// // found above the context provided to this widget's build method -/// // excluding themes are found above the navigator. Those themes do -/// // not have to be captured, because they will already be visible from -/// // the new route pushed onto said navigator. -/// // Themes are captured outside of the route's builder because when the -/// // builder executes, the context may not be valid anymore. -/// final CapturedThemes themes = InheritedTheme.capture(from: context, to: navigator.context); -/// return GestureDetector( -/// onTap: () { -/// Navigator.of(context).push( -/// MaterialPageRoute( -/// builder: (BuildContext _) { -/// // Wrap the actual child of the route in the previously -/// // captured themes. -/// return themes.wrap( -/// Container( -/// alignment: Alignment.center, -/// color: Colors.white, -/// child: const Text('Hello World'), -/// ), -/// ); -/// }, -/// ), -/// ); -/// }, -/// child: const Center(child: Text('Tap Here')), -/// ); -/// } -/// } -/// -/// class MyApp extends StatelessWidget { -/// const MyApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return const MaterialApp( -/// home: Scaffold( -/// // Override the DefaultTextStyle defined by the Scaffold. -/// // Descendant widgets will inherit this big blue text style. -/// body: DefaultTextStyle( -/// style: TextStyle(fontSize: 48, color: Colors.blue), -/// child: MyAppBody(), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/inherited_theme/inherited_theme.0.dart ** /// {@end-tool} abstract class InheritedTheme extends InheritedWidget { /// Abstract const constructor. This constructor enables subclasses to provide diff --git a/packages/flutter/lib/src/widgets/interactive_viewer.dart b/packages/flutter/lib/src/widgets/interactive_viewer.dart index 12fd35226c..b5ae9b04f7 100644 --- a/packages/flutter/lib/src/widgets/interactive_viewer.dart +++ b/packages/flutter/lib/src/widgets/interactive_viewer.dart @@ -50,27 +50,7 @@ typedef InteractiveViewerWidgetBuilder = Widget Function(BuildContext context, Q /// {@tool dartpad --template=stateless_widget_scaffold} /// This example shows a simple Container that can be panned and zoomed. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Center( -/// child: InteractiveViewer( -/// boundaryMargin: const EdgeInsets.all(20.0), -/// minScale: 0.1, -/// maxScale: 1.6, -/// child: Container( -/// decoration: const BoxDecoration( -/// gradient: LinearGradient( -/// begin: Alignment.topCenter, -/// end: Alignment.bottomCenter, -/// colors: [Colors.orange, Colors.red], -/// stops: [0.0, 1.0], -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.0.dart ** /// {@end-tool} @immutable class InteractiveViewer extends StatefulWidget { @@ -206,185 +186,11 @@ class InteractiveViewer extends StatefulWidget { /// [child] parameter must be passed directly, and this is null. /// /// {@tool dartpad --template=freeform} - /// /// This example shows how to use builder to create a [Table] whose cell /// contents are only built when they are visible. Built and remove cells are /// logged in the console for illustration. /// - /// ```dart main - /// import 'package:vector_math/vector_math_64.dart' show Quad, Vector3; - /// - /// import 'package:flutter/material.dart'; - /// import 'package:flutter/widgets.dart'; - /// - /// void main() => runApp(const IVBuilderExampleApp()); - /// - /// class IVBuilderExampleApp extends StatelessWidget { - /// const IVBuilderExampleApp({Key? key}) : super(key: key); - /// - /// @override - /// Widget build(BuildContext context) { - /// return MaterialApp( - /// home: Scaffold( - /// appBar: AppBar( - /// title: const Text('IV Builder Example'), - /// ), - /// body: _IVBuilderExample(), - /// ), - /// ); - /// } - /// } - /// - /// class _IVBuilderExample extends StatefulWidget { - /// @override - /// _IVBuilderExampleState createState() => _IVBuilderExampleState(); - /// } - /// - /// class _IVBuilderExampleState extends State<_IVBuilderExample> { - /// final TransformationController _transformationController = TransformationController(); - /// - /// static const double _cellWidth = 200.0; - /// static const double _cellHeight = 26.0; - /// - /// // Returns true iff the given cell is currently visible. Caches viewport - /// // calculations. - /// late Quad _cachedViewport; - /// late int _firstVisibleRow; - /// late int _firstVisibleColumn; - /// late int _lastVisibleRow; - /// late int _lastVisibleColumn; - /// bool _isCellVisible(int row, int column, Quad viewport) { - /// if (viewport != _cachedViewport) { - /// final Rect aabb = _axisAlignedBoundingBox(viewport); - /// _cachedViewport = viewport; - /// _firstVisibleRow = (aabb.top / _cellHeight).floor(); - /// _firstVisibleColumn = (aabb.left / _cellWidth).floor(); - /// _lastVisibleRow = (aabb.bottom / _cellHeight).floor(); - /// _lastVisibleColumn = (aabb.right / _cellWidth).floor(); - /// } - /// return row >= _firstVisibleRow && row <= _lastVisibleRow - /// && column >= _firstVisibleColumn && column <= _lastVisibleColumn; - /// } - /// - /// // Returns the axis aligned bounding box for the given Quad, which might not - /// // be axis aligned. - /// Rect _axisAlignedBoundingBox(Quad quad) { - /// double? xMin; - /// double? xMax; - /// double? yMin; - /// double? yMax; - /// for (final Vector3 point in [quad.point0, quad.point1, quad.point2, quad.point3]) { - /// if (xMin == null || point.x < xMin) { - /// xMin = point.x; - /// } - /// if (xMax == null || point.x > xMax) { - /// xMax = point.x; - /// } - /// if (yMin == null || point.y < yMin) { - /// yMin = point.y; - /// } - /// if (yMax == null || point.y > yMax) { - /// yMax = point.y; - /// } - /// } - /// return Rect.fromLTRB(xMin!, yMin!, xMax!, yMax!); - /// } - /// - /// void _onChangeTransformation() { - /// setState(() {}); - /// } - /// - /// @override - /// void initState() { - /// super.initState(); - /// _transformationController.addListener(_onChangeTransformation); - /// } - /// - /// @override - /// void dispose() { - /// _transformationController.removeListener(_onChangeTransformation); - /// super.dispose(); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Center( - /// child: LayoutBuilder( - /// builder: (BuildContext context, BoxConstraints constraints) { - /// return InteractiveViewer.builder( - /// alignPanAxis: true, - /// scaleEnabled: false, - /// transformationController: _transformationController, - /// builder: (BuildContext context, Quad viewport) { - /// // A simple extension of Table that builds cells. - /// return _TableBuilder( - /// rowCount: 60, - /// columnCount: 6, - /// cellWidth: _cellWidth, - /// builder: (BuildContext context, int row, int column) { - /// if (!_isCellVisible(row, column, viewport)) { - /// print('removing cell ($row, $column)'); - /// return Container(height: _cellHeight); - /// } - /// print('building cell ($row, $column)'); - /// return Container( - /// height: _cellHeight, - /// color: row % 2 + column % 2 == 1 ? Colors.white : Colors.grey.withOpacity(0.1), - /// child: Align( - /// alignment: Alignment.centerLeft, - /// child: Text('$row x $column'), - /// ), - /// ); - /// } - /// ); - /// }, - /// ); - /// }, - /// ), - /// ); - /// } - /// } - /// - /// typedef _CellBuilder = Widget Function(BuildContext context, int row, int column); - /// - /// class _TableBuilder extends StatelessWidget { - /// const _TableBuilder({ - /// required this.rowCount, - /// required this.columnCount, - /// required this.cellWidth, - /// required this.builder, - /// }) : assert(rowCount > 0), - /// assert(columnCount > 0); - /// - /// final int rowCount; - /// final int columnCount; - /// final double cellWidth; - /// final _CellBuilder builder; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Table( - /// // ignore: prefer_const_literals_to_create_immutables - /// columnWidths: { - /// for (int column = 0; column < columnCount; column++) - /// column: FixedColumnWidth(cellWidth), - /// }, - /// // ignore: prefer_const_literals_to_create_immutables - /// children: [ - /// for (int row = 0; row < rowCount; row++) - /// // ignore: prefer_const_constructors - /// TableRow( - /// // ignore: prefer_const_literals_to_create_immutables - /// children: [ - /// for (int column = 0; column < columnCount; column++) - /// builder(context, row, column), - /// ], - /// ), - /// ], - /// ); - /// } - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.builder.0.dart ** /// {@end-tool} /// /// See also: @@ -421,42 +227,7 @@ class InteractiveViewer extends StatefulWidget { /// to allow it to be drawn to its full size. The parts of the table that /// exceed the screen size can then be panned into view. /// - /// ```dart - /// Widget build(BuildContext context) { - /// const int _rowCount = 48; - /// const int _columnCount = 6; - /// - /// return InteractiveViewer( - /// alignPanAxis: true, - /// constrained: false, - /// scaleEnabled: false, - /// child: Table( - /// columnWidths: { - /// for (int column = 0; column < _columnCount; column += 1) - /// column: const FixedColumnWidth(200.0), - /// }, - /// children: [ - /// for (int row = 0; row < _rowCount; row += 1) - /// TableRow( - /// children: [ - /// for (int column = 0; column < _columnCount; column += 1) - /// Container( - /// height: 26, - /// color: row % 2 + column % 2 == 1 - /// ? Colors.white - /// : Colors.grey.withOpacity(0.1), - /// child: Align( - /// alignment: Alignment.centerLeft, - /// child: Text('$row x $column'), - /// ), - /// ), - /// ], - /// ), - /// ], - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.constrained.0.dart ** /// {@end-tool} final bool constrained; @@ -575,99 +346,7 @@ class InteractiveViewer extends StatefulWidget { /// This example shows how transformationController can be used to animate the /// transformation back to its starting position. /// - /// ```dart - /// final TransformationController _transformationController = TransformationController(); - /// Animation? _animationReset; - /// late final AnimationController _controllerReset; - /// - /// void _onAnimateReset() { - /// _transformationController.value = _animationReset!.value; - /// if (!_controllerReset.isAnimating) { - /// _animationReset!.removeListener(_onAnimateReset); - /// _animationReset = null; - /// _controllerReset.reset(); - /// } - /// } - /// - /// void _animateResetInitialize() { - /// _controllerReset.reset(); - /// _animationReset = Matrix4Tween( - /// begin: _transformationController.value, - /// end: Matrix4.identity(), - /// ).animate(_controllerReset); - /// _animationReset!.addListener(_onAnimateReset); - /// _controllerReset.forward(); - /// } - /// - /// // Stop a running reset to home transform animation. - /// void _animateResetStop() { - /// _controllerReset.stop(); - /// _animationReset?.removeListener(_onAnimateReset); - /// _animationReset = null; - /// _controllerReset.reset(); - /// } - /// - /// void _onInteractionStart(ScaleStartDetails details) { - /// // If the user tries to cause a transformation while the reset animation is - /// // running, cancel the reset animation. - /// if (_controllerReset.status == AnimationStatus.forward) { - /// _animateResetStop(); - /// } - /// } - /// - /// @override - /// void initState() { - /// super.initState(); - /// _controllerReset = AnimationController( - /// vsync: this, - /// duration: const Duration(milliseconds: 400), - /// ); - /// } - /// - /// @override - /// void dispose() { - /// _controllerReset.dispose(); - /// super.dispose(); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// backgroundColor: Theme.of(context).colorScheme.primary, - /// appBar: AppBar( - /// automaticallyImplyLeading: false, - /// title: const Text('Controller demo'), - /// ), - /// body: Center( - /// child: InteractiveViewer( - /// boundaryMargin: const EdgeInsets.all(double.infinity), - /// transformationController: _transformationController, - /// minScale: 0.1, - /// maxScale: 1.0, - /// onInteractionStart: _onInteractionStart, - /// child: Container( - /// decoration: const BoxDecoration( - /// gradient: LinearGradient( - /// begin: Alignment.topCenter, - /// end: Alignment.bottomCenter, - /// colors: [Colors.orange, Colors.red], - /// stops: [0.0, 1.0], - /// ), - /// ), - /// ), - /// ), - /// ), - /// persistentFooterButtons: [ - /// IconButton( - /// onPressed: _animateResetInitialize, - /// tooltip: 'Reset', - /// color: Theme.of(context).colorScheme.surface, - /// icon: const Icon(Icons.replay), - /// ), - /// ], - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/interactive_viewer/interactive_viewer.transformation_controller.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/layout_builder.dart b/packages/flutter/lib/src/widgets/layout_builder.dart index 22c52154ce..d8bdbcd4e2 100644 --- a/packages/flutter/lib/src/widgets/layout_builder.dart +++ b/packages/flutter/lib/src/widgets/layout_builder.dart @@ -247,56 +247,10 @@ mixin RenderConstrainedLayoutBuilder 600) { -/// return _buildWideContainers(); -/// } else { -/// return _buildNormalContainer(); -/// } -/// }, -/// ), -/// ); -/// } -/// -/// Widget _buildNormalContainer() { -/// return Center( -/// child: Container( -/// height: 100.0, -/// width: 100.0, -/// color: Colors.red, -/// ), -/// ); -/// } -/// -/// Widget _buildWideContainers() { -/// return Center( -/// child: Row( -/// mainAxisAlignment: MainAxisAlignment.spaceEvenly, -/// children: [ -/// Container( -/// height: 100.0, -/// width: 100.0, -/// color: Colors.red, -/// ), -/// Container( -/// height: 100.0, -/// width: 100.0, -/// color: Colors.yellow, -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/layout_builder/layout_builder.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/media_query.dart b/packages/flutter/lib/src/widgets/media_query.dart index 6952b4aa44..c8ee472340 100644 --- a/packages/flutter/lib/src/widgets/media_query.dart +++ b/packages/flutter/lib/src/widgets/media_query.dart @@ -256,7 +256,6 @@ class MediaQueryData { /// on Android starting with version Q. /// /// {@tool dartpad --template=stateful_widget_material} - /// /// For apps that might be deployed on Android Q devices with full gesture /// navigation enabled, use [systemGestureInsets] with [Padding] /// to avoid having the left and right edges of the [Slider] from appearing @@ -265,31 +264,7 @@ class MediaQueryData { /// By default, [Slider]s expand to fill the available width. So, we pad the /// left and right sides. /// - /// ```dart - /// double _currentValue = 0.2; - /// - /// @override - /// Widget build(BuildContext context) { - /// final EdgeInsets systemGestureInsets = MediaQuery.of(context).systemGestureInsets; - /// return Scaffold( - /// appBar: AppBar(title: const Text('Pad Slider to avoid systemGestureInsets')), - /// body: Padding( - /// padding: EdgeInsets.only( // only left and right padding are needed here - /// left: systemGestureInsets.left, - /// right: systemGestureInsets.right, - /// ), - /// child: Slider( - /// value: _currentValue, - /// onChanged: (double newValue) { - /// setState(() { - /// _currentValue = newValue; - /// }); - /// }, - /// ), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/media_query/media_query_data.system_gesture_insets.0.dart ** /// {@end-tool} final EdgeInsets systemGestureInsets; diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index efb2b329cc..acdc456785 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -759,45 +759,7 @@ abstract class RouteTransitionRecord { /// removes or adds routes without animated transitions and puts the removed /// routes at the top of the list. /// -/// ```dart imports -/// import 'package:flutter/widgets.dart'; -/// ``` -/// -/// ```dart -/// class NoAnimationTransitionDelegate extends TransitionDelegate { -/// @override -/// Iterable resolve({ -/// required List newPageRouteHistory, -/// required Map locationToExitingPageRoute, -/// required Map> pageRouteToPagelessRoutes, -/// }) { -/// final List results = []; -/// -/// for (final RouteTransitionRecord pageRoute in newPageRouteHistory) { -/// if (pageRoute.isWaitingForEnteringDecision) { -/// pageRoute.markForAdd(); -/// } -/// results.add(pageRoute); -/// -/// } -/// for (final RouteTransitionRecord exitingPageRoute in locationToExitingPageRoute.values) { -/// if (exitingPageRoute.isWaitingForExitingDecision) { -/// exitingPageRoute.markForRemove(); -/// final List? pagelessRoutes = pageRouteToPagelessRoutes[exitingPageRoute]; -/// if (pagelessRoutes != null) { -/// for (final RouteTransitionRecord pagelessRoute in pagelessRoutes) { -/// pagelessRoute.markForRemove(); -/// } -/// } -/// } -/// results.add(exitingPageRoute); -/// -/// } -/// return results; -/// } -/// } -/// -/// ``` +/// ** See code in examples/api/lib/widgets/navigator/transition_delegate.0.dart ** /// {@end-tool} /// /// See also: @@ -1297,136 +1259,7 @@ class DefaultTransitionDelegate extends TransitionDelegate { /// Run this example with `flutter run --route=/signup` to start it with /// the signup flow instead of on the home page. /// -/// ```dart imports -/// import 'package:flutter/material.dart'; -/// ``` -/// -/// ```dart main -/// void main() => runApp(const MyApp()); -/// ``` -/// -/// ```dart -/// class MyApp extends StatelessWidget { -/// const MyApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// title: 'Flutter Code Sample for Navigator', -/// // MaterialApp contains our top-level Navigator -/// initialRoute: '/', -/// routes: { -/// '/': (BuildContext context) => const HomePage(), -/// '/signup': (BuildContext context) => const SignUpPage(), -/// }, -/// ); -/// } -/// } -/// -/// class HomePage extends StatelessWidget { -/// const HomePage({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline4!, -/// child: Container( -/// color: Colors.white, -/// alignment: Alignment.center, -/// child: const Text('Home Page'), -/// ), -/// ); -/// } -/// } -/// -/// class CollectPersonalInfoPage extends StatelessWidget { -/// const CollectPersonalInfoPage({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline4!, -/// child: GestureDetector( -/// onTap: () { -/// // This moves from the personal info page to the credentials page, -/// // replacing this page with that one. -/// Navigator.of(context) -/// .pushReplacementNamed('signup/choose_credentials'); -/// }, -/// child: Container( -/// color: Colors.lightBlue, -/// alignment: Alignment.center, -/// child: const Text('Collect Personal Info Page'), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// class ChooseCredentialsPage extends StatelessWidget { -/// const ChooseCredentialsPage({ -/// Key? key, -/// required this.onSignupComplete, -/// }) : super(key: key); -/// -/// final VoidCallback onSignupComplete; -/// -/// @override -/// Widget build(BuildContext context) { -/// return GestureDetector( -/// onTap: onSignupComplete, -/// child: DefaultTextStyle( -/// style: Theme.of(context).textTheme.headline4!, -/// child: Container( -/// color: Colors.pinkAccent, -/// alignment: Alignment.center, -/// child: const Text('Choose Credentials Page'), -/// ), -/// ), -/// ); -/// } -/// } -/// -/// class SignUpPage extends StatelessWidget { -/// const SignUpPage({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// // SignUpPage builds its own Navigator which ends up being a nested -/// // Navigator in our app. -/// return Navigator( -/// initialRoute: 'signup/personal_info', -/// onGenerateRoute: (RouteSettings settings) { -/// WidgetBuilder builder; -/// switch (settings.name) { -/// case 'signup/personal_info': -/// // Assume CollectPersonalInfoPage collects personal info and then -/// // navigates to 'signup/choose_credentials'. -/// builder = (BuildContext context) => const CollectPersonalInfoPage(); -/// break; -/// case 'signup/choose_credentials': -/// // Assume ChooseCredentialsPage collects new credentials and then -/// // invokes 'onSignupComplete()'. -/// builder = (BuildContext _) => ChooseCredentialsPage( -/// onSignupComplete: () { -/// // Referencing Navigator.of(context) from here refers to the -/// // top level Navigator because SignUpPage is above the -/// // nested Navigator that it created. Therefore, this pop() -/// // will pop the entire "sign up" journey and return to the -/// // "/" route, AKA HomePage. -/// Navigator.of(context).pop(); -/// }, -/// ); -/// break; -/// default: -/// throw Exception('Invalid route: ${settings.name}'); -/// } -/// return MaterialPageRoute(builder: builder, settings: settings); -/// }, -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/navigator/navigator.0.dart ** /// {@end-tool} /// /// [Navigator.of] operates on the nearest ancestor [Navigator] from the given @@ -2162,30 +1995,9 @@ class Navigator extends StatefulWidget { /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} /// /// {@tool dartpad --template=stateful_widget_material} - /// /// Typical usage is as follows: /// - /// ```dart - /// static Route _myRouteBuilder(BuildContext context, Object? arguments) { - /// return MaterialPageRoute( - /// builder: (BuildContext context) => const MyStatefulWidget(), - /// ); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar( - /// title: const Text('Sample Code'), - /// ), - /// floatingActionButton: FloatingActionButton( - /// onPressed: () => Navigator.restorablePush(context, _myRouteBuilder), - /// tooltip: 'Increment Counter', - /// child: const Icon(Icons.add), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/navigator/navigator.restorable_push.0.dart ** /// {@end-tool} @optionalTypeArgs static String restorablePush(BuildContext context, RestorableRouteBuilder routeBuilder, {Object? arguments}) { @@ -2262,30 +2074,9 @@ class Navigator extends StatefulWidget { /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} /// /// {@tool dartpad --template=stateful_widget_material} - /// /// Typical usage is as follows: /// - /// ```dart - /// static Route _myRouteBuilder(BuildContext context, Object? arguments) { - /// return MaterialPageRoute( - /// builder: (BuildContext context) => const MyStatefulWidget(), - /// ); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar( - /// title: const Text('Sample Code'), - /// ), - /// floatingActionButton: FloatingActionButton( - /// onPressed: () => Navigator.restorablePushReplacement(context, _myRouteBuilder), - /// tooltip: 'Increment Counter', - /// child: const Icon(Icons.add), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/navigator/navigator.restorable_push_replacement.0.dart ** /// {@end-tool} @optionalTypeArgs static String restorablePushReplacement(BuildContext context, RestorableRouteBuilder routeBuilder, { TO? result, Object? arguments }) { @@ -2368,34 +2159,9 @@ class Navigator extends StatefulWidget { /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} /// /// {@tool dartpad --template=stateful_widget_material} - /// /// Typical usage is as follows: /// - /// ```dart - /// static Route _myRouteBuilder(BuildContext context, Object? arguments) { - /// return MaterialPageRoute( - /// builder: (BuildContext context) => const MyStatefulWidget(), - /// ); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar( - /// title: const Text('Sample Code'), - /// ), - /// floatingActionButton: FloatingActionButton( - /// onPressed: () => Navigator.restorablePushAndRemoveUntil( - /// context, - /// _myRouteBuilder, - /// ModalRoute.withName('/'), - /// ), - /// tooltip: 'Increment Counter', - /// child: const Icon(Icons.add), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/navigator/navigator.restorable_push_and_remove_until.0.dart ** /// {@end-tool} @optionalTypeArgs static String restorablePushAndRemoveUntil(BuildContext context, RestorableRouteBuilder newRouteBuilder, RoutePredicate predicate, {Object? arguments}) { @@ -4552,30 +4318,9 @@ class NavigatorState extends State with TickerProviderStateMixin, Res /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} /// /// {@tool dartpad --template=stateful_widget_material} - /// /// Typical usage is as follows: /// - /// ```dart - /// static Route _myRouteBuilder(BuildContext context, Object? arguments) { - /// return MaterialPageRoute( - /// builder: (BuildContext context) => const MyStatefulWidget(), - /// ); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar( - /// title: const Text('Sample Code'), - /// ), - /// floatingActionButton: FloatingActionButton( - /// onPressed: () => Navigator.of(context).restorablePush(_myRouteBuilder), - /// tooltip: 'Increment Counter', - /// child: const Icon(Icons.add), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/navigator/navigator_state.restorable_push.0.dart ** /// {@end-tool} @optionalTypeArgs String restorablePush(RestorableRouteBuilder routeBuilder, {Object? arguments}) { @@ -4695,32 +4440,9 @@ class NavigatorState extends State with TickerProviderStateMixin, Res /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} /// /// {@tool dartpad --template=stateful_widget_material} - /// /// Typical usage is as follows: /// - /// ```dart - /// static Route _myRouteBuilder(BuildContext context, Object? arguments) { - /// return MaterialPageRoute( - /// builder: (BuildContext context) => const MyStatefulWidget(), - /// ); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar( - /// title: const Text('Sample Code'), - /// ), - /// floatingActionButton: FloatingActionButton( - /// onPressed: () => Navigator.of(context).restorablePushReplacement( - /// _myRouteBuilder, - /// ), - /// tooltip: 'Increment Counter', - /// child: const Icon(Icons.add), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/navigator/navigator_state.restorable_push_replacement.0.dart ** /// {@end-tool} @optionalTypeArgs String restorablePushReplacement(RestorableRouteBuilder routeBuilder, { TO? result, Object? arguments }) { @@ -4803,33 +4525,9 @@ class NavigatorState extends State with TickerProviderStateMixin, Res /// {@macro flutter.widgets.Navigator.restorablePushNamed.returnValue} /// /// {@tool dartpad --template=stateful_widget_material} - /// /// Typical usage is as follows: /// - /// ```dart - /// static Route _myRouteBuilder(BuildContext context, Object? arguments) { - /// return MaterialPageRoute( - /// builder: (BuildContext context) => const MyStatefulWidget(), - /// ); - /// } - /// - /// @override - /// Widget build(BuildContext context) { - /// return Scaffold( - /// appBar: AppBar( - /// title: const Text('Sample Code'), - /// ), - /// floatingActionButton: FloatingActionButton( - /// onPressed: () => Navigator.of(context).restorablePushAndRemoveUntil( - /// _myRouteBuilder, - /// ModalRoute.withName('/'), - /// ), - /// tooltip: 'Increment Counter', - /// child: const Icon(Icons.add), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart ** /// {@end-tool} @optionalTypeArgs String restorablePushAndRemoveUntil(RestorableRouteBuilder newRouteBuilder, RoutePredicate predicate, {Object? arguments}) { @@ -5727,166 +5425,7 @@ typedef RouteCompletionCallback = void Function(T result); /// This example uses a [RestorableRouteFuture] in the `_MyHomeState` to push a /// new `MyCounter` route and to retrieve its return value. /// -/// ```dart imports -/// import 'package:flutter/material.dart'; -/// ``` -/// -/// ```dart main -/// void main() => runApp(const MyApp()); -/// ``` -/// -/// ```dart preamble -/// class MyApp extends StatelessWidget { -/// const MyApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// restorationScopeId: 'app', -/// home: Scaffold( -/// appBar: AppBar(title: const Text('RestorableRouteFuture Example')), -/// body: const MyHome(), -/// ), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// class MyHome extends StatefulWidget { -/// const MyHome({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _MyHomeState(); -/// } -/// -/// class _MyHomeState extends State with RestorationMixin { -/// final RestorableInt _lastCount = RestorableInt(0); -/// late RestorableRouteFuture _counterRoute; -/// -/// @override -/// String get restorationId => 'home'; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _counterRoute = RestorableRouteFuture( -/// onPresent: (NavigatorState navigator, Object? arguments) { -/// // Defines what route should be shown (and how it should be added -/// // to the navigator) when `RestorableRouteFuture.present` is called. -/// return navigator.restorablePush( -/// _counterRouteBuilder, -/// arguments: arguments, -/// ); -/// }, -/// onComplete: (int count) { -/// // Defines what should happen with the return value when the route -/// // completes. -/// setState(() { -/// _lastCount.value = count; -/// }); -/// } -/// ); -/// } -/// -/// @override -/// void restoreState(RestorationBucket? oldBucket, bool initialRestore) { -/// // Register the `RestorableRouteFuture` with the state restoration framework. -/// registerForRestoration(_counterRoute, 'route'); -/// registerForRestoration(_lastCount, 'count'); -/// } -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// _lastCount.dispose(); -/// _counterRoute.dispose(); -/// } -/// -/// // A static `RestorableRouteBuilder` that can re-create the route during -/// // state restoration. -/// static Route _counterRouteBuilder(BuildContext context, Object? arguments) { -/// return MaterialPageRoute( -/// builder: (BuildContext context) => MyCounter( -/// title: arguments!.toString(), -/// ), -/// ); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Center( -/// child: Column( -/// mainAxisSize: MainAxisSize.min, -/// children: [ -/// Text('Last count: ${_lastCount.value}'), -/// ElevatedButton( -/// onPressed: () { -/// // Show the route defined by the `RestorableRouteFuture`. -/// _counterRoute.present('Awesome Counter'); -/// }, -/// child: const Text('Open Counter'), -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// -/// // Widget for the route pushed by the `RestorableRouteFuture`. -/// class MyCounter extends StatefulWidget { -/// const MyCounter({Key? key, required this.title}) : super(key: key); -/// -/// final String title; -/// -/// @override -/// State createState() => _MyCounterState(); -/// } -/// -/// class _MyCounterState extends State with RestorationMixin { -/// final RestorableInt _count = RestorableInt(0); -/// -/// @override -/// String get restorationId => 'counter'; -/// -/// @override -/// void restoreState(RestorationBucket? oldBucket, bool initialRestore) { -/// registerForRestoration(_count, 'count'); -/// } -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// _count.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: Text(widget.title), -/// leading: BackButton( -/// onPressed: () { -/// // Return the current count of the counter from this route. -/// Navigator.of(context).pop(_count.value); -/// }, -/// ), -/// ), -/// body: Center( -/// child: Text('Count: ${_count.value}'), -/// ), -/// floatingActionButton: FloatingActionButton( -/// child: const Icon(Icons.add), -/// onPressed: () { -/// setState(() { -/// _count.value++; -/// }); -/// }, -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/navigator/restorable_route_future.0.dart ** /// {@end-tool} class RestorableRouteFuture extends RestorableProperty { /// Creates a [RestorableRouteFuture]. diff --git a/packages/flutter/lib/src/widgets/nested_scroll_view.dart b/packages/flutter/lib/src/widgets/nested_scroll_view.dart index e527fb4297..277df791de 100644 --- a/packages/flutter/lib/src/widgets/nested_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/nested_scroll_view.dart @@ -56,7 +56,6 @@ typedef NestedScrollViewHeaderSliversBuilder = List Function(BuildContex /// to the user, as one coherent scroll view. /// /// {@tool sample --template=stateless_widget_material} -/// /// This example shows a [NestedScrollView] whose header is the combination of a /// [TabBar] in a [SliverAppBar] and whose body is a [TabBarView]. It uses a /// [SliverOverlapAbsorber]/[SliverOverlapInjector] pair to make the inner lists @@ -65,113 +64,7 @@ typedef NestedScrollViewHeaderSliversBuilder = List Function(BuildContex /// [PageStorageKey]s are used to remember the scroll position of each tab's /// list. /// -/// ```dart -/// Widget build(BuildContext context) { -/// final List _tabs = ['Tab 1', 'Tab 2']; -/// return DefaultTabController( -/// length: _tabs.length, // This is the number of tabs. -/// child: Scaffold( -/// body: NestedScrollView( -/// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { -/// // These are the slivers that show up in the "outer" scroll view. -/// return [ -/// SliverOverlapAbsorber( -/// // This widget takes the overlapping behavior of the SliverAppBar, -/// // and redirects it to the SliverOverlapInjector below. If it is -/// // missing, then it is possible for the nested "inner" scroll view -/// // below to end up under the SliverAppBar even when the inner -/// // scroll view thinks it has not been scrolled. -/// // This is not necessary if the "headerSliverBuilder" only builds -/// // widgets that do not overlap the next sliver. -/// handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), -/// sliver: SliverAppBar( -/// title: const Text('Books'), // This is the title in the app bar. -/// pinned: true, -/// expandedHeight: 150.0, -/// // The "forceElevated" property causes the SliverAppBar to show -/// // a shadow. The "innerBoxIsScrolled" parameter is true when the -/// // inner scroll view is scrolled beyond its "zero" point, i.e. -/// // when it appears to be scrolled below the SliverAppBar. -/// // Without this, there are cases where the shadow would appear -/// // or not appear inappropriately, because the SliverAppBar is -/// // not actually aware of the precise position of the inner -/// // scroll views. -/// forceElevated: innerBoxIsScrolled, -/// bottom: TabBar( -/// // These are the widgets to put in each tab in the tab bar. -/// tabs: _tabs.map((String name) => Tab(text: name)).toList(), -/// ), -/// ), -/// ), -/// ]; -/// }, -/// body: TabBarView( -/// // These are the contents of the tab views, below the tabs. -/// children: _tabs.map((String name) { -/// return SafeArea( -/// top: false, -/// bottom: false, -/// child: Builder( -/// // This Builder is needed to provide a BuildContext that is -/// // "inside" the NestedScrollView, so that -/// // sliverOverlapAbsorberHandleFor() can find the -/// // NestedScrollView. -/// builder: (BuildContext context) { -/// return CustomScrollView( -/// // The "controller" and "primary" members should be left -/// // unset, so that the NestedScrollView can control this -/// // inner scroll view. -/// // If the "controller" property is set, then this scroll -/// // view will not be associated with the NestedScrollView. -/// // The PageStorageKey should be unique to this ScrollView; -/// // it allows the list to remember its scroll position when -/// // the tab view is not on the screen. -/// key: PageStorageKey(name), -/// slivers: [ -/// SliverOverlapInjector( -/// // This is the flip side of the SliverOverlapAbsorber -/// // above. -/// handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), -/// ), -/// SliverPadding( -/// padding: const EdgeInsets.all(8.0), -/// // In this example, the inner scroll view has -/// // fixed-height list items, hence the use of -/// // SliverFixedExtentList. However, one could use any -/// // sliver widget here, e.g. SliverList or SliverGrid. -/// sliver: SliverFixedExtentList( -/// // The items in this example are fixed to 48 pixels -/// // high. This matches the Material Design spec for -/// // ListTile widgets. -/// itemExtent: 48.0, -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// // This builder is called for each child. -/// // In this example, we just number each list item. -/// return ListTile( -/// title: Text('Item $index'), -/// ); -/// }, -/// // The childCount of the SliverChildBuilderDelegate -/// // specifies how many children this inner list -/// // has. In this example, each tab has a list of -/// // exactly 30 items, but this is arbitrary. -/// childCount: 30, -/// ), -/// ), -/// ), -/// ], -/// ); -/// }, -/// ), -/// ); -/// }).toList(), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.0.dart ** /// {@end-tool} /// /// ## [SliverAppBar]s with [NestedScrollView]s @@ -218,43 +111,12 @@ typedef NestedScrollViewHeaderSliversBuilder = List Function(BuildContex /// while the primary portion of the app bar remains pinned. /// /// {@tool sample --template=stateless_widget_material} -/// /// This simple example shows a [NestedScrollView] whose header contains a /// floating [SliverAppBar]. By using the [floatHeaderSlivers] property, the /// floating behavior is coordinated between the outer and inner [Scrollable]s, /// so it behaves as it would in a single scrollable. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: NestedScrollView( -/// // Setting floatHeaderSlivers to true is required in order to float -/// // the outer slivers over the inner scrollable. -/// floatHeaderSlivers: true, -/// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { -/// return [ -/// SliverAppBar( -/// title: const Text('Floating Nested SliverAppBar'), -/// floating: true, -/// expandedHeight: 200.0, -/// forceElevated: innerBoxIsScrolled, -/// ), -/// ]; -/// }, -/// body: ListView.builder( -/// padding: const EdgeInsets.all(8), -/// itemCount: 30, -/// itemBuilder: (BuildContext context, int index) { -/// return SizedBox( -/// height: 50, -/// child: Center(child: Text('Item $index')), -/// ); -/// } -/// ) -/// ) -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.1.dart ** /// {@end-tool} /// /// ### Snapping [SliverAppBar]s @@ -279,7 +141,6 @@ typedef NestedScrollViewHeaderSliversBuilder = List Function(BuildContex /// even when the inner scroll view thinks it has not been scrolled. /// /// {@tool sample --template=stateless_widget_material} -/// /// This simple example shows a [NestedScrollView] whose header contains a /// snapping, floating [SliverAppBar]. _Without_ setting any additional flags, /// e.g [NestedScrollView.floatHeaderSlivers], the [SliverAppBar] will animate @@ -287,49 +148,7 @@ typedef NestedScrollViewHeaderSliversBuilder = List Function(BuildContex /// [SliverOverlapInjector] maintain the proper alignment between the two /// separate scroll views. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: NestedScrollView( -/// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { -/// return [ -/// SliverOverlapAbsorber( -/// handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), -/// sliver: SliverAppBar( -/// title: const Text('Snapping Nested SliverAppBar'), -/// floating: true, -/// snap: true, -/// expandedHeight: 200.0, -/// forceElevated: innerBoxIsScrolled, -/// ), -/// ) -/// ]; -/// }, -/// body: Builder( -/// builder: (BuildContext context) { -/// return CustomScrollView( -/// // The "controller" and "primary" members should be left -/// // unset, so that the NestedScrollView can control this -/// // inner scroll view. -/// // If the "controller" property is set, then this scroll -/// // view will not be associated with the NestedScrollView. -/// slivers: [ -/// SliverOverlapInjector(handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context)), -/// SliverFixedExtentList( -/// itemExtent: 48.0, -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) => ListTile(title: Text('Item $index')), -/// childCount: 30, -/// ), -/// ), -/// ], -/// ); -/// } -/// ) -/// ) -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view.2.dart ** /// {@end-tool} /// /// ### Snapping and Floating [SliverAppBar]s @@ -521,31 +340,7 @@ class NestedScrollView extends StatefulWidget { /// Using the following setup, you can access the inner scroll controller /// using `globalKey.currentState.innerController`. /// -/// ```dart preamble -/// final GlobalKey globalKey = GlobalKey(); -/// ``` -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return NestedScrollView( -/// key: globalKey, -/// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { -/// return const [ -/// SliverAppBar( -/// title: Text('NestedScrollViewState Demo!'), -/// ), -/// ]; -/// }, -/// body: const CustomScrollView( -/// // Body slivers go here! -/// ), -/// ); -/// } -/// -/// ScrollController get innerController { -/// return globalKey.currentState!.innerController; -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/nested_scroll_view/nested_scroll_view_state.0.dart ** /// {@end-tool} class NestedScrollViewState extends State { final SliverOverlapAbsorberHandle _absorberHandle = SliverOverlapAbsorberHandle(); diff --git a/packages/flutter/lib/src/widgets/notification_listener.dart b/packages/flutter/lib/src/widgets/notification_listener.dart index b2bd075f98..906f282d76 100644 --- a/packages/flutter/lib/src/widgets/notification_listener.dart +++ b/packages/flutter/lib/src/widgets/notification_listener.dart @@ -29,68 +29,13 @@ typedef NotificationListenerCallback = bool Function(T n /// [BuildContext]. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This example shows a [NotificationListener] widget /// that listens for [ScrollNotification] notifications. When a scroll /// event occurs in the [NestedScrollView], /// this widget is notified. The events could be either a /// [ScrollStartNotification]or[ScrollEndNotification]. /// -/// ```dart -/// Widget build(BuildContext context) { -/// const List _tabs = ['Months', 'Days']; -/// const List _months = [ 'January','February','March', ]; -/// const List _days = [ 'Sunday', 'Monday','Tuesday', ]; -/// return DefaultTabController( -/// length: _tabs.length, -/// child: Scaffold( -/// // Listens to the scroll events and returns the current position. -/// body: NotificationListener( -/// onNotification: (ScrollNotification scrollNotification) { -/// if (scrollNotification is ScrollStartNotification) { -/// print('Scrolling has started'); -/// } else if (scrollNotification is ScrollEndNotification) { -/// print('Scrolling has ended'); -/// } -/// // Return true to cancel the notification bubbling. -/// return true; -/// }, -/// child: NestedScrollView( -/// headerSliverBuilder: -/// (BuildContext context, bool innerBoxIsScrolled) { -/// return [ -/// SliverAppBar( -/// title: const Text('Flutter Code Sample'), -/// pinned: true, -/// floating: true, -/// bottom: TabBar( -/// tabs: _tabs.map((String name) => Tab(text: name)).toList(), -/// ), -/// ), -/// ]; -/// }, -/// body: TabBarView( -/// children: [ -/// ListView.builder( -/// itemCount: _months.length, -/// itemBuilder: (BuildContext context, int index) { -/// return ListTile(title: Text(_months[index])); -/// }, -/// ), -/// ListView.builder( -/// itemCount: _days.length, -/// itemBuilder: (BuildContext context, int index) { -/// return ListTile(title: Text(_days[index])); -/// }, -/// ), -/// ], -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/notification_listener/notification.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/overflow_bar.dart b/packages/flutter/lib/src/widgets/overflow_bar.dart index e76e6d4f13..88d32859de 100644 --- a/packages/flutter/lib/src/widgets/overflow_bar.dart +++ b/packages/flutter/lib/src/widgets/overflow_bar.dart @@ -44,7 +44,6 @@ enum OverflowBarAlignment { /// column is specified by [overflowDirection] instead. /// /// {@tool dartpad --template=stateless_widget_scaffold_center} -/// /// This example defines a simple approximation of a dialog /// layout, where the layout of the dialog's action buttons are /// defined by an [OverflowBar]. The content is wrapped in a @@ -52,46 +51,7 @@ enum OverflowBarAlignment { /// action buttons will still be accessible by scrolling, /// no matter how much vertical space is available. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Container( -/// alignment: Alignment.center, -/// padding: const EdgeInsets.all(16), -/// color: Colors.black.withOpacity(0.15), -/// child: Material( -/// color: Colors.white, -/// elevation: 24, -/// shape: const RoundedRectangleBorder( -/// borderRadius: BorderRadius.all(Radius.circular(4)) -/// ), -/// child: Padding( -/// padding: const EdgeInsets.all(8), -/// child: SingleChildScrollView( -/// child: Column( -/// mainAxisSize: MainAxisSize.min, -/// crossAxisAlignment: CrossAxisAlignment.stretch, -/// children: [ -/// const SizedBox(height: 128, child: Placeholder()), -/// Align( -/// alignment: AlignmentDirectional.centerEnd, -/// child: OverflowBar( -/// spacing: 8, -/// overflowAlignment: OverflowBarAlignment.end, -/// children: [ -/// TextButton(child: const Text('Cancel'), onPressed: () { }), -/// TextButton(child: const Text('Really Really Cancel'), onPressed: () { }), -/// OutlinedButton(child: const Text('OK'), onPressed: () { }), -/// ], -/// ), -/// ), -/// ], -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/overflow_bar/overflow_bar.0.dart ** /// {@end-tool} class OverflowBar extends MultiChildRenderObjectWidget { /// Constructs an OverflowBar. diff --git a/packages/flutter/lib/src/widgets/overscroll_indicator.dart b/packages/flutter/lib/src/widgets/overscroll_indicator.dart index ce84791ede..3796963a2a 100644 --- a/packages/flutter/lib/src/widgets/overscroll_indicator.dart +++ b/packages/flutter/lib/src/widgets/overscroll_indicator.dart @@ -48,70 +48,21 @@ import 'transitions.dart'; /// notification, or use a [NestedScrollView]. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This example demonstrates how to use a [NotificationListener] to manipulate /// the placement of a [GlowingOverscrollIndicator] when building a /// [CustomScrollView]. Drag the scrollable to see the bounds of the overscroll /// indicator. /// -/// ```dart -/// Widget build(BuildContext context) { -/// final double leadingPaintOffset = MediaQuery.of(context).padding.top + AppBar().preferredSize.height; -/// return NotificationListener( -/// onNotification: (OverscrollIndicatorNotification notification) { -/// if (notification.leading) { -/// notification.paintOffset = leadingPaintOffset; -/// } -/// return false; -/// }, -/// child: CustomScrollView( -/// slivers: [ -/// const SliverAppBar(title: Text('Custom PaintOffset')), -/// SliverToBoxAdapter( -/// child: Container( -/// color: Colors.amberAccent, -/// height: 100, -/// child: const Center(child: Text('Glow all day!')), -/// ), -/// ), -/// const SliverFillRemaining(child: FlutterLogo()), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This example demonstrates how to use a [NestedScrollView] to manipulate the /// placement of a [GlowingOverscrollIndicator] when building a /// [CustomScrollView]. Drag the scrollable to see the bounds of the overscroll /// indicator. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return NestedScrollView( -/// headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { -/// return const [ -/// SliverAppBar(title: Text('Custom NestedScrollViews')), -/// ]; -/// }, -/// body: CustomScrollView( -/// slivers: [ -/// SliverToBoxAdapter( -/// child: Container( -/// color: Colors.amberAccent, -/// height: 100, -/// child: const Center(child: Text('Glow all day!')), -/// ), -/// ), -/// const SliverFillRemaining(child: FlutterLogo()), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/overscroll_indicator/glowing_overscroll_indicator.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/page_storage.dart b/packages/flutter/lib/src/widgets/page_storage.dart index 4025935ca0..ce834747ae 100644 --- a/packages/flutter/lib/src/widgets/page_storage.dart +++ b/packages/flutter/lib/src/widgets/page_storage.dart @@ -137,103 +137,12 @@ class PageStorageBucket { /// `keepScrollOffset` false to prevent saving. /// /// {@tool dartpad --template=freeform} -/// /// This sample shows how to explicitly use a [PageStorage] to /// store the states of its children pages. Each page includes a scrollable /// list, whose position is preserved when switching between the tabs thanks to /// the help of [PageStorageKey]. /// -/// ```dart imports -/// import 'package:flutter/material.dart'; -/// ``` -/// -/// ```dart main -/// void main() => runApp(const MyApp()); -/// ``` -/// -/// ```dart -/// class MyApp extends StatelessWidget { -/// const MyApp({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return const MaterialApp( -/// home: MyHomePage(), -/// ); -/// } -/// } -/// -/// class MyHomePage extends StatefulWidget { -/// const MyHomePage({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => _MyHomePageState(); -/// } -/// -/// class _MyHomePageState extends State { -/// final List pages = const [ -/// ColorBoxPage( -/// key: PageStorageKey('pageOne'), -/// ), -/// ColorBoxPage( -/// key: PageStorageKey('pageTwo'), -/// ) -/// ]; -/// int currentTab = 0; -/// final PageStorageBucket _bucket = PageStorageBucket(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Persistence Example'), -/// ), -/// body: PageStorage( -/// child: pages[currentTab], -/// bucket: _bucket, -/// ), -/// bottomNavigationBar: BottomNavigationBar( -/// currentIndex: currentTab, -/// onTap: (int index) { -/// setState(() { -/// currentTab = index; -/// }); -/// }, -/// items: const [ -/// BottomNavigationBarItem( -/// icon: Icon(Icons.home), -/// label: 'page 1', -/// ), -/// BottomNavigationBarItem( -/// icon: Icon(Icons.settings), -/// label: 'page2', -/// ), -/// ], -/// ), -/// ); -/// } -/// } -/// -/// class ColorBoxPage extends StatelessWidget { -/// const ColorBoxPage({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return ListView.builder( -/// itemExtent: 250.0, -/// itemBuilder: (BuildContext context, int index) => Container( -/// padding: const EdgeInsets.all(10.0), -/// child: Material( -/// color: index.isEven ? Colors.cyan : Colors.deepOrange, -/// child: Center( -/// child: Text(index.toString()), -/// ), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/page_storage/page_storage.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/page_view.dart b/packages/flutter/lib/src/widgets/page_view.dart index ed7e6a0e3d..dc778e5a99 100644 --- a/packages/flutter/lib/src/widgets/page_view.dart +++ b/packages/flutter/lib/src/widgets/page_view.dart @@ -570,32 +570,10 @@ const PageScrollPhysics _kPagePhysics = PageScrollPhysics(); /// {@youtube 560 315 https://www.youtube.com/watch?v=J1gE9xvph-A} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// Here is an example of [PageView]. It creates a centered [Text] in each of the three pages /// which scroll horizontally. /// -/// ```dart -/// Widget build(BuildContext context) { -/// final PageController controller = PageController(initialPage: 0); -/// return PageView( -/// /// [PageView.scrollDirection] defaults to [Axis.horizontal]. -/// /// Use [Axis.vertical] to scroll vertically. -/// scrollDirection: Axis.horizontal, -/// controller: controller, -/// children: const [ -/// Center( -/// child: Text('First Page'), -/// ), -/// Center( -/// child: Text('Second Page'), -/// ), -/// Center( -/// child: Text('Third Page'), -/// ) -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/page_view/page_view.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/preferred_size.dart b/packages/flutter/lib/src/widgets/preferred_size.dart index 358171ae62..1f5594b112 100644 --- a/packages/flutter/lib/src/widgets/preferred_size.dart +++ b/packages/flutter/lib/src/widgets/preferred_size.dart @@ -46,74 +46,12 @@ abstract class PreferredSizeWidget implements Widget { /// [PreferredSize] widget is not necessary for them. /// /// {@tool dartpad --template=stateless_widget_material} -/// /// This sample shows a custom widget, similar to an [AppBar], which uses a /// [PreferredSize] widget, with its height set to 80 logical pixels. /// Changing the [PreferredSize] can be used to change the height /// of the custom app bar. /// -/// ```dart preamble -/// class AppBarContent extends StatelessWidget { -/// const AppBarContent({Key? key}) : super(key: key); -/// -/// @override -/// Widget build(BuildContext context) { -/// return Column( -/// mainAxisAlignment: MainAxisAlignment.end, -/// children: [ -/// Padding( -/// padding: const EdgeInsets.symmetric(horizontal: 10), -/// child: Row( -/// children: [ -/// const Text( -/// 'PreferredSize Sample', -/// style: TextStyle(color: Colors.white), -/// ), -/// const Spacer(), -/// IconButton( -/// icon: const Icon( -/// Icons.search, -/// size: 20, -/// ), -/// color: Colors.white, -/// onPressed: () {}, -/// ), -/// IconButton( -/// icon: const Icon( -/// Icons.more_vert, -/// size: 20, -/// ), -/// color: Colors.white, -/// onPressed: () {}, -/// ), -/// ], -/// ), -/// ), -/// ], -/// ); -/// } -/// } -/// ``` -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// appBar: PreferredSize( -/// preferredSize: const Size.fromHeight(80.0), -/// child: Container( -/// decoration: const BoxDecoration( -/// gradient: LinearGradient( -/// colors: [Colors.blue, Colors.pink], -/// ), -/// ), -/// child: const AppBarContent(), -/// ), -/// ), -/// body: const Center( -/// child: Text('Content'), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/preferred_size/preferred_size.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/restoration_properties.dart b/packages/flutter/lib/src/widgets/restoration_properties.dart index 7e07eef7f3..e4d3a7aeff 100644 --- a/packages/flutter/lib/src/widgets/restoration_properties.dart +++ b/packages/flutter/lib/src/widgets/restoration_properties.dart @@ -22,44 +22,7 @@ import 'restoration.dart'; /// {@tool dartpad --template=stateful_widget_restoration} /// A [StatefulWidget] that has a restorable [int] property. /// -/// ```dart -/// // The current value of the answer is stored in a [RestorableProperty]. -/// // During state restoration it is automatically restored to its old value. -/// // If no restoration data is available to restore the answer from, it is -/// // initialized to the specified default value, in this case 42. -/// final RestorableInt _answer = RestorableInt(42); -/// -/// @override -/// void restoreState(RestorationBucket? oldBucket, bool initialRestore) { -/// // All restorable properties must be registered with the mixin. After -/// // registration, the answer either has its old value restored or is -/// // initialized to its default value. -/// registerForRestoration(_answer, 'answer'); -/// } -/// -/// void _incrementAnswer() { -/// setState(() { -/// // The current value of the property can be accessed and modified via -/// // the value getter and setter. -/// _answer.value += 1; -/// }); -/// } -/// -/// @override -/// void dispose() { -/// // Properties must be disposed when no longer used. -/// _answer.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return OutlinedButton( -/// child: Text('${_answer.value}'), -/// onPressed: _incrementAnswer, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/restoration_properties/restorable_value.0.dart ** /// {@end-tool} /// /// ## Creating a subclass diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index db45d24fda..6b3b230bbd 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -1982,7 +1982,6 @@ class RawDialogRoute extends PopupRoute { /// For more information about state restoration, see [RestorationManager]. /// /// {@tool sample --template=stateless_widget_restoration_material} -/// /// This sample demonstrates how to create a restorable dialog. This is /// accomplished by enabling state restoration by specifying /// [WidgetsApp.restorationScopeId] and using [Navigator.restorablePush] to @@ -1990,33 +1989,7 @@ class RawDialogRoute extends PopupRoute { /// /// {@macro flutter.widgets.RestorationManager} /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: OutlinedButton( -/// onPressed: () { -/// Navigator.of(context).restorablePush(_dialogBuilder); -/// }, -/// child: const Text('Open Dialog'), -/// ), -/// ), -/// ); -/// } -/// -/// static Route _dialogBuilder(BuildContext context, Object? arguments) { -/// return RawDialogRoute( -/// pageBuilder: ( -/// BuildContext context, -/// Animation animation, -/// Animation secondaryAnimation, -/// ) { -/// return const AlertDialog(title: Text('Alert!')); -/// }, -/// ); -/// } -/// ``` -/// +/// ** See code in examples/api/lib/widgets/routes/show_general_dialog.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/scroll_position.dart b/packages/flutter/lib/src/widgets/scroll_position.dart index ef5b96bb01..0b785d1391 100644 --- a/packages/flutter/lib/src/widgets/scroll_position.dart +++ b/packages/flutter/lib/src/widgets/scroll_position.dart @@ -994,61 +994,7 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics { /// the `windowSize` is changed. Press the floating action button to increase /// the scrollable window's size. /// -/// ```dart main -/// import 'package:flutter/material.dart'; -/// -/// void main() => runApp(const ScrollMetricsDemo()); -/// -/// class ScrollMetricsDemo extends StatefulWidget { -/// const ScrollMetricsDemo({Key? key}) : super(key: key); -/// -/// @override -/// State createState() => ScrollMetricsDemoState(); -/// } -/// -/// class ScrollMetricsDemoState extends State { -/// double windowSize = 200.0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Scaffold( -/// appBar: AppBar( -/// title: const Text('ScrollMetrics Demo'), -/// ), -/// floatingActionButton: FloatingActionButton( -/// child: const Icon(Icons.add), -/// onPressed: () => setState(() { -/// windowSize += 10.0; -/// }), -/// ), -/// body: NotificationListener( -/// onNotification: (ScrollMetricsNotification notification) { -/// ScaffoldMessenger.of(notification.context).showSnackBar( -/// const SnackBar( -/// content: Text('Scroll metrics changed!'), -/// ), -/// ); -/// return false; -/// }, -/// child: Scrollbar( -/// isAlwaysShown: true, -/// child: SizedBox( -/// height: windowSize, -/// width: double.infinity, -/// child: const SingleChildScrollView( -/// child: FlutterLogo( -/// size: 300.0, -/// ), -/// ), -/// ), -/// ), -/// ), -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/scroll_position/scroll_metrics_notification.0.dart ** /// {@end-tool} class ScrollMetricsNotification extends Notification with ViewportNotificationMixin { /// Creates a notification that the scrollable widget's [ScrollMetrics] have diff --git a/packages/flutter/lib/src/widgets/scroll_view.dart b/packages/flutter/lib/src/widgets/scroll_view.dart index f24c16ed80..d123533a86 100644 --- a/packages/flutter/lib/src/widgets/scroll_view.dart +++ b/packages/flutter/lib/src/widgets/scroll_view.dart @@ -500,7 +500,6 @@ abstract class ScrollView extends StatelessWidget { /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material} -/// /// By default, if items are inserted at the "top" of a scrolling container like /// [ListView] or [CustomScrollView], the top item and all of the items below it /// are scrolled downwards. In some applications, it's preferable to have the @@ -510,61 +509,7 @@ abstract class ScrollView extends StatelessWidget { /// of the bottom SliverList. The top one SliverList will grow upwards, and the /// bottom SliverList will grow downwards. /// -/// ```dart -/// List top = []; -/// List bottom = [0]; -/// -/// @override -/// Widget build(BuildContext context) { -/// const Key centerKey = ValueKey('bottom-sliver-list'); -/// return Scaffold( -/// appBar: AppBar( -/// title: const Text('Press on the plus to add items above and below'), -/// leading: IconButton( -/// icon: const Icon(Icons.add), -/// onPressed: () { -/// setState(() { -/// top.add(-top.length - 1); -/// bottom.add(bottom.length); -/// }); -/// }, -/// ), -/// ), -/// body: CustomScrollView( -/// center: centerKey, -/// slivers: [ -/// SliverList( -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// return Container( -/// alignment: Alignment.center, -/// color: Colors.blue[200 + top[index] % 4 * 100], -/// height: 100 + top[index] % 4 * 20.0, -/// child: Text('Item: ${top[index]}'), -/// ); -/// }, -/// childCount: top.length, -/// ), -/// ), -/// SliverList( -/// key: centerKey, -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// return Container( -/// alignment: Alignment.center, -/// color: Colors.blue[200 + bottom[index] % 4 * 100], -/// height: 100 + bottom[index] % 4 * 20.0, -/// child: Text('Item: ${bottom[index]}'), -/// ); -/// }, -/// childCount: bottom.length, -/// ), -/// ), -/// ], -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/scroll_view/custom_scroll_view.1.dart ** /// {@end-tool} /// /// ## Accessibility diff --git a/packages/flutter/lib/src/widgets/scrollbar.dart b/packages/flutter/lib/src/widgets/scrollbar.dart index 9ecd6ae8a4..261bebd60d 100644 --- a/packages/flutter/lib/src/widgets/scrollbar.dart +++ b/packages/flutter/lib/src/widgets/scrollbar.dart @@ -716,64 +716,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter { /// Alternatively, a new PrimaryScrollController could be created above one of /// the [ListView]s. /// -/// ```dart -/// final ScrollController _firstController = ScrollController(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return LayoutBuilder( -/// builder: (BuildContext context, BoxConstraints constraints) { -/// return Row( -/// children: [ -/// SizedBox( -/// width: constraints.maxWidth / 2, -/// // Only one scroll position can be attached to the -/// // PrimaryScrollController if using Scrollbars. Providing a -/// // unique scroll controller to this scroll view prevents it -/// // from attaching to the PrimaryScrollController. -/// child: Scrollbar( -/// isAlwaysShown: true, -/// controller: _firstController, -/// child: ListView.builder( -/// controller: _firstController, -/// itemCount: 100, -/// itemBuilder: (BuildContext context, int index) { -/// return Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: Text('Scrollable 1 : Index $index'), -/// ); -/// } -/// ), -/// ) -/// ), -/// SizedBox( -/// width: constraints.maxWidth / 2, -/// // This vertical scroll view has not been provided a -/// // ScrollController, so it is using the -/// // PrimaryScrollController. -/// child: Scrollbar( -/// isAlwaysShown: true, -/// child: ListView.builder( -/// itemCount: 100, -/// itemBuilder: (BuildContext context, int index) { -/// return Container( -/// height: 50, -/// color: index.isEven ? Colors.amberAccent : Colors.blueAccent, -/// child: Padding( -/// padding: const EdgeInsets.all(8.0), -/// child: Text('Scrollable 2 : Index $index'), -/// ) -/// ); -/// } -/// ), -/// ) -/// ), -/// ], -/// ); -/// } -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart ** /// {@end-tool} /// /// ### Automatic Scrollbars on Desktop Platforms @@ -803,22 +746,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter { /// [PrimaryScrollController] since it has an [Axis.vertical] scroll direction /// and has not been provided a [ScrollController]. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return RawScrollbar( -/// child: GridView.builder( -/// itemCount: 120, -/// gridDelegate: -/// const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), -/// itemBuilder: (BuildContext context, int index) { -/// return Center( -/// child: Text('item $index'), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.1.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_scaffold} @@ -828,28 +756,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter { /// Alternatively, the [PrimaryScrollController] can be used automatically so long /// as it is attached to the singular [ScrollPosition] associated with the GridView. /// -/// ```dart -/// final ScrollController _controllerOne = ScrollController(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return RawScrollbar( -/// controller: _controllerOne, -/// isAlwaysShown: true, -/// child: GridView.builder( -/// controller: _controllerOne, -/// itemCount: 120, -/// gridDelegate: -/// const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), -/// itemBuilder: (BuildContext context, int index) { -/// return Center( -/// child: Text('item $index'), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/shortcuts.dart b/packages/flutter/lib/src/widgets/shortcuts.dart index 941f7e96e6..dce0ebff4c 100644 --- a/packages/flutter/lib/src/widgets/shortcuts.dart +++ b/packages/flutter/lib/src/widgets/shortcuts.dart @@ -241,46 +241,7 @@ abstract class ShortcutActivator { /// /// * Control left, then A, then C. /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart preamble -/// class IncrementIntent extends Intent { -/// const IncrementIntent(); -/// } -/// ``` -/// -/// ```dart -/// int count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Shortcuts( -/// shortcuts: { -/// LogicalKeySet(LogicalKeyboardKey.keyC, LogicalKeyboardKey.controlLeft): const IncrementIntent(), -/// }, -/// child: Actions( -/// actions: >{ -/// IncrementIntent: CallbackAction( -/// onInvoke: (IncrementIntent intent) => setState(() { -/// count = count + 1; -/// }), -/// ), -/// }, -/// child: Focus( -/// autofocus: true, -/// child: Column( -/// children: [ -/// const Text('Add to the counter by pressing Ctrl+C'), -/// Text('count: $count'), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/shortcuts/logical_key_set.0.dart ** /// {@end-tool} /// /// This is also a thin wrapper around a [Set], but changes the equality @@ -443,46 +404,7 @@ class SingleActivator with Diagnosticable implements ShortcutActivator { /// {@tool dartpad --template=stateful_widget_scaffold_center} /// In the following example, the shortcut `Control + C` increases the counter: /// - /// ```dart imports - /// import 'package:flutter/services.dart'; - /// ``` - /// - /// ```dart preamble - /// class IncrementIntent extends Intent { - /// const IncrementIntent(); - /// } - /// ``` - /// - /// ```dart - /// int count = 0; - /// - /// @override - /// Widget build(BuildContext context) { - /// return Shortcuts( - /// shortcuts: const { - /// SingleActivator(LogicalKeyboardKey.keyC, control: true): IncrementIntent(), - /// }, - /// child: Actions( - /// actions: >{ - /// IncrementIntent: CallbackAction( - /// onInvoke: (IncrementIntent intent) => setState(() { - /// count = count + 1; - /// }), - /// ), - /// }, - /// child: Focus( - /// autofocus: true, - /// child: Column( - /// children: [ - /// const Text('Add to the counter by pressing Ctrl+C'), - /// Text('count: $count'), - /// ], - /// ), - /// ), - /// ), - /// ); - /// } - /// ``` + /// ** See code in examples/api/lib/widgets/shortcuts/single_activator.single_activator.0.dart ** /// {@end-tool} const SingleActivator( this.trigger, { @@ -622,42 +544,7 @@ class SingleActivator with Diagnosticable implements ShortcutActivator { /// In the following example, when a key combination results in a question mark, /// the counter is increased: /// -/// ```dart preamble -/// class HelpMenuIntent extends Intent { -/// const HelpMenuIntent(); -/// } -/// ``` -/// -/// ```dart -/// @override -/// Widget build(BuildContext context) { -/// return Shortcuts( -/// shortcuts: const { -/// CharacterActivator('?'): HelpMenuIntent(), -/// }, -/// child: Actions( -/// actions: >{ -/// HelpMenuIntent: CallbackAction( -/// onInvoke: (HelpMenuIntent intent) { -/// ScaffoldMessenger.of(context).showSnackBar( -/// const SnackBar(content: Text('Keep calm and carry on!')), -/// ); -/// return null; -/// }, -/// ), -/// }, -/// child: Focus( -/// autofocus: true, -/// child: Column( -/// children: const [ -/// Text('Press question mark for help'), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/shortcuts/character_activator.0.dart ** /// {@end-tool} /// /// See also: @@ -853,7 +740,6 @@ class ShortcutManager extends ChangeNotifier with Diagnosticable { /// [Intent]. /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// Here, we will use the [Shortcuts] and [Actions] widgets to add and subtract /// from a counter. When the child widget has keyboard focus, and a user presses /// the keys that have been defined in [Shortcuts], the action that is bound @@ -862,62 +748,10 @@ class ShortcutManager extends ChangeNotifier with Diagnosticable { /// It also shows the use of a [CallbackAction] to avoid creating a new [Action] /// subclass. /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart preamble -/// class IncrementIntent extends Intent { -/// const IncrementIntent(); -/// } -/// -/// class DecrementIntent extends Intent { -/// const DecrementIntent(); -/// } -/// ``` -/// -/// ```dart -/// int count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Shortcuts( -/// shortcuts: { -/// LogicalKeySet(LogicalKeyboardKey.arrowUp): const IncrementIntent(), -/// LogicalKeySet(LogicalKeyboardKey.arrowDown): const DecrementIntent(), -/// }, -/// child: Actions( -/// actions: >{ -/// IncrementIntent: CallbackAction( -/// onInvoke: (IncrementIntent intent) => setState(() { -/// count = count + 1; -/// }), -/// ), -/// DecrementIntent: CallbackAction( -/// onInvoke: (DecrementIntent intent) => setState(() { -/// count = count - 1; -/// }), -/// ), -/// }, -/// child: Focus( -/// autofocus: true, -/// child: Column( -/// children: [ -/// const Text('Add to the counter by pressing the up arrow key'), -/// const Text( -/// 'Subtract from the counter by pressing the down arrow key'), -/// Text('count: $count'), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/shortcuts/shortcuts.0.dart ** /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_scaffold_center} -/// /// This slightly more complicated, but more flexible, example creates a custom /// [Action] subclass to increment and decrement within a widget (a [Column]) /// that has keyboard focus. When the user presses the up and down arrow keys, @@ -930,94 +764,7 @@ class ShortcutManager extends ChangeNotifier with Diagnosticable { /// intent passed to them when invoked (like the increment `amount` in this /// example). /// -/// ```dart imports -/// import 'package:flutter/services.dart'; -/// ``` -/// -/// ```dart preamble -/// class Model with ChangeNotifier { -/// int count = 0; -/// void incrementBy(int amount) { -/// count += amount; -/// notifyListeners(); -/// } -/// -/// void decrementBy(int amount) { -/// count -= amount; -/// notifyListeners(); -/// } -/// } -/// -/// class IncrementIntent extends Intent { -/// const IncrementIntent(this.amount); -/// -/// final int amount; -/// } -/// -/// class DecrementIntent extends Intent { -/// const DecrementIntent(this.amount); -/// -/// final int amount; -/// } -/// -/// class IncrementAction extends Action { -/// IncrementAction(this.model); -/// -/// final Model model; -/// -/// @override -/// void invoke(covariant IncrementIntent intent) { -/// model.incrementBy(intent.amount); -/// } -/// } -/// -/// class DecrementAction extends Action { -/// DecrementAction(this.model); -/// -/// final Model model; -/// -/// @override -/// void invoke(covariant DecrementIntent intent) { -/// model.decrementBy(intent.amount); -/// } -/// } -/// ``` -/// -/// ```dart -/// Model model = Model(); -/// -/// @override -/// Widget build(BuildContext context) { -/// return Shortcuts( -/// shortcuts: { -/// LogicalKeySet(LogicalKeyboardKey.arrowUp): const IncrementIntent(2), -/// LogicalKeySet(LogicalKeyboardKey.arrowDown): const DecrementIntent(2), -/// }, -/// child: Actions( -/// actions: >{ -/// IncrementIntent: IncrementAction(model), -/// DecrementIntent: DecrementAction(model), -/// }, -/// child: Focus( -/// autofocus: true, -/// child: Column( -/// children: [ -/// const Text('Add to the counter by pressing the up arrow key'), -/// const Text( -/// 'Subtract from the counter by pressing the down arrow key'), -/// AnimatedBuilder( -/// animation: model, -/// builder: (BuildContext context, Widget? child) { -/// return Text('count: ${model.count}'); -/// }, -/// ), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/shortcuts/shortcuts.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart index 336f3804bf..79ea89b7a5 100644 --- a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart @@ -93,44 +93,7 @@ import 'scrollable.dart'; /// in both cases the "available space" is infinite (since this is in a viewport). /// The next section describes a technique for providing a maximum height constraint. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return DefaultTextStyle( -/// style: Theme.of(context).textTheme.bodyText2!, -/// child: LayoutBuilder( -/// builder: (BuildContext context, BoxConstraints viewportConstraints) { -/// return SingleChildScrollView( -/// child: ConstrainedBox( -/// constraints: BoxConstraints( -/// minHeight: viewportConstraints.maxHeight, -/// ), -/// child: Column( -/// mainAxisSize: MainAxisSize.min, -/// mainAxisAlignment: MainAxisAlignment.spaceAround, -/// children: [ -/// Container( -/// // A fixed-height child. -/// color: const Color(0xffeeee00), // Yellow -/// height: 120.0, -/// alignment: Alignment.center, -/// child: const Text('Fixed Height Content'), -/// ), -/// Container( -/// // Another fixed-height child. -/// color: const Color(0xff008000), // Green -/// height: 120.0, -/// alignment: Alignment.center, -/// child: const Text('Fixed Height Content'), -/// ), -/// ], -/// ), -/// ), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.0.dart ** /// {@end-tool} /// /// ### Expanding content to fit the viewport @@ -163,47 +126,7 @@ import 'scrollable.dart'; /// In this example, the column becomes either as big as viewport, or as big as /// the contents, whichever is biggest. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return DefaultTextStyle( -/// style: Theme.of(context).textTheme.bodyText2!, -/// child: LayoutBuilder( -/// builder: (BuildContext context, BoxConstraints viewportConstraints) { -/// return SingleChildScrollView( -/// child: ConstrainedBox( -/// constraints: BoxConstraints( -/// minHeight: viewportConstraints.maxHeight, -/// ), -/// child: IntrinsicHeight( -/// child: Column( -/// children: [ -/// Container( -/// // A fixed-height child. -/// color: const Color(0xffeeee00), // Yellow -/// height: 120.0, -/// alignment: Alignment.center, -/// child: const Text('Fixed Height Content'), -/// ), -/// Expanded( -/// // A flexible child that will grow to fit the viewport but -/// // still be at least as big as necessary to fit its contents. -/// child: Container( -/// color: const Color(0xffee0000), // Red -/// height: 120.0, -/// alignment: Alignment.center, -/// child: const Text('Flexible Content'), -/// ), -/// ), -/// ], -/// ), -/// ), -/// ), -/// ); -/// }, -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/single_child_scroll_view/single_child_scroll_view.1.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/sliver_fill.dart b/packages/flutter/lib/src/widgets/sliver_fill.dart index 97ecbd5618..e9ef99423c 100644 --- a/packages/flutter/lib/src/widgets/sliver_fill.dart +++ b/packages/flutter/lib/src/widgets/sliver_fill.dart @@ -203,121 +203,33 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding { /// extent of the viewport. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// In this sample the [SliverFillRemaining] sizes its [child] to fill the /// remaining extent of the viewport in both axes. The icon is centered in the /// sliver, and would be in any computed extent for the sliver. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return CustomScrollView( -/// slivers: [ -/// SliverToBoxAdapter( -/// child: Container( -/// color: Colors.amber[300], -/// height: 150.0, -/// ), -/// ), -/// SliverFillRemaining( -/// hasScrollBody: false, -/// child: Container( -/// color: Colors.blue[100], -/// child: Icon( -/// Icons.sentiment_very_satisfied, -/// size: 75, -/// color: Colors.blue[900], -/// ), -/// ), -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.0.dart ** /// {@end-tool} /// /// [SliverFillRemaining] will defer to the size of its [child] if the /// child's size exceeds the remaining space in the viewport. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// In this sample the [SliverFillRemaining] defers to the size of its [child] /// because the child's extent exceeds that of the remaining extent of the /// viewport's main axis. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return CustomScrollView( -/// slivers: [ -/// SliverFixedExtentList( -/// itemExtent: 100.0, -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// return Container( -/// color: index.isEven -/// ? Colors.amber[200] -/// : Colors.blue[200], -/// ); -/// }, -/// childCount: 3, -/// ), -/// ), -/// SliverFillRemaining( -/// hasScrollBody: false, -/// child: Container( -/// color: Colors.orange[300], -/// child: const Padding( -/// padding: EdgeInsets.all(50.0), -/// child: FlutterLogo(size: 100), -/// ), -/// ), -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.1.dart ** /// {@end-tool} /// /// [SliverFillRemaining] will defer to the size of its [child] if the /// [SliverConstraints.precedingScrollExtent] exceeded the length of the viewport's main axis. /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// In this sample the [SliverFillRemaining] defers to the size of its [child] /// because the [SliverConstraints.precedingScrollExtent] has gone /// beyond that of the viewport's main axis. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return CustomScrollView( -/// slivers: [ -/// SliverFixedExtentList( -/// itemExtent: 130.0, -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// return Container( -/// color: index.isEven -/// ? Colors.indigo[200] -/// : Colors.orange[200], -/// ); -/// }, -/// childCount: 5, -/// ), -/// ), -/// const SliverFillRemaining( -/// hasScrollBody: false, -/// child: Padding( -/// padding: EdgeInsets.all(50.0), -/// child: Icon( -/// Icons.pan_tool, -/// size: 60, -/// color: Colors.blueGrey, -/// ), -/// ), -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.2.dart ** /// {@end-tool} /// /// For [ScrollPhysics] that allow overscroll, such as @@ -328,7 +240,6 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding { /// {@animation 250 500 https://flutter.github.io/assets-for-api-docs/assets/widgets/sliver_fill_remaining_fill_overscroll.mp4} /// /// {@tool sample --template=stateless_widget_scaffold} -/// /// In this sample the [SliverFillRemaining]'s child stretches to fill the /// overscroll area when [fillOverscroll] is true. This sample also features a /// button that is pinned to the bottom of the sliver, regardless of size or @@ -337,51 +248,7 @@ class _RenderSliverFractionalPadding extends RenderSliverEdgeInsetsPadding { /// This sample only shows the overscroll behavior on devices that support /// overscroll. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return CustomScrollView( -/// // The ScrollPhysics are overridden here to illustrate the functionality -/// // of fillOverscroll on all devices this sample may be run on. -/// // fillOverscroll only changes the behavior of your layout when applied -/// // to Scrollables that allow for overscroll. BouncingScrollPhysics are -/// // one example, which are provided by default on the iOS platform. -/// // BouncingScrollPhysics is combined with AlwaysScrollableScrollPhysics -/// // to allow for the overscroll, regardless of the depth of the -/// // scrollable. -/// physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), -/// slivers: [ -/// SliverToBoxAdapter( -/// child: Container( -/// color: Colors.tealAccent[700], -/// height: 150.0, -/// ), -/// ), -/// SliverFillRemaining( -/// hasScrollBody: false, -/// // Switch for different overscroll behavior in your layout. -/// // If your ScrollPhysics do not allow for overscroll, setting -/// // fillOverscroll to true will have no effect. -/// fillOverscroll: true, -/// child: Container( -/// color: Colors.teal[100], -/// child: Align( -/// alignment: Alignment.bottomCenter, -/// child: Padding( -/// padding: const EdgeInsets.all(16.0), -/// child: ElevatedButton( -/// onPressed: () { -/// /* Place your onPressed code here! */ -/// }, -/// child: const Text('Bottom Pinned Button!'), -/// ), -/// ), -/// ), -/// ), -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/sliver_fill/sliver_fill_remaining.3.dart ** /// {@end-tool} /// /// diff --git a/packages/flutter/lib/src/widgets/table.dart b/packages/flutter/lib/src/widgets/table.dart index 85eeb9acdb..88a4fe6f48 100644 --- a/packages/flutter/lib/src/widgets/table.dart +++ b/packages/flutter/lib/src/widgets/table.dart @@ -82,67 +82,9 @@ class _TableElementRow { /// {@youtube 560 315 https://www.youtube.com/watch?v=_lbE0wsVZSw} /// /// {@tool dartpad --template=stateless_widget_scaffold} -/// /// This sample shows a `Table` with borders, multiple types of column widths and different vertical cell alignments. /// -/// ```dart -/// Widget build(BuildContext context) { -/// return Table( -/// border: TableBorder.all(), -/// columnWidths: const { -/// 0: IntrinsicColumnWidth(), -/// 1: FlexColumnWidth(), -/// 2: FixedColumnWidth(64), -/// }, -/// defaultVerticalAlignment: TableCellVerticalAlignment.middle, -/// children: [ -/// TableRow( -/// children: [ -/// Container( -/// height: 32, -/// color: Colors.green, -/// ), -/// TableCell( -/// verticalAlignment: TableCellVerticalAlignment.top, -/// child: Container( -/// height: 32, -/// width: 32, -/// color: Colors.red, -/// ), -/// ), -/// Container( -/// height: 64, -/// color: Colors.blue, -/// ), -/// ], -/// ), -/// TableRow( -/// decoration: const BoxDecoration( -/// color: Colors.grey, -/// ), -/// children: [ -/// Container( -/// height: 64, -/// width: 128, -/// color: Colors.purple, -/// ), -/// Container( -/// height: 32, -/// color: Colors.yellow, -/// ), -/// Center( -/// child: Container( -/// height: 32, -/// width: 32, -/// color: Colors.orange, -/// ), -/// ), -/// ], -/// ), -/// ], -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/table/table.0.dart ** /// {@end-tool} /// /// If you only have one row, the [Row] widget is more appropriate. If you only diff --git a/packages/flutter/lib/src/widgets/transitions.dart b/packages/flutter/lib/src/widgets/transitions.dart index a16ac179fd..29e69bf242 100644 --- a/packages/flutter/lib/src/widgets/transitions.dart +++ b/packages/flutter/lib/src/widgets/transitions.dart @@ -25,50 +25,10 @@ export 'package:flutter/rendering.dart' show RelativeRect; /// use [AnimatedWidget], simply subclass it and implement the build function. /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// This code defines a widget called `Spinner` that spins a green square /// continually. It is built with an [AnimatedWidget]. /// -/// ```dart dartImports -/// import 'dart:math' as math; -/// ``` -/// -/// ```dart preamble -/// class SpinningContainer extends AnimatedWidget { -/// const SpinningContainer({ -/// Key? key, -/// required AnimationController controller, -/// }) : super(key: key, listenable: controller); -/// -/// Animation get _progress => listenable as Animation; -/// -/// @override -/// Widget build(BuildContext context) { -/// return Transform.rotate( -/// angle: _progress.value * 2.0 * math.pi, -/// child: Container(width: 200.0, height: 200.0, color: Colors.green), -/// ); -/// } -/// } -/// ``` -/// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 10), -/// vsync: this, -/// )..repeat(); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return SpinningContainer(controller: _controller); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/animated_widget.0.dart ** /// {@end-tool} /// /// For more complex case involving additional state, consider using @@ -194,38 +154,7 @@ class _AnimatedState extends State { /// The following code implements the [SlideTransition] as seen in the video /// above: /// -/// ```dart -/// class _MyStatefulWidgetState extends State with SingleTickerProviderStateMixin { -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// late final Animation _offsetAnimation = Tween( -/// begin: Offset.zero, -/// end: const Offset(1.5, 0.0), -/// ).animate(CurvedAnimation( -/// parent: _controller, -/// curve: Curves.elasticIn, -/// )); -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// _controller.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return SlideTransition( -/// position: _offsetAnimation, -/// child: const Padding( -/// padding: EdgeInsets.all(8.0), -/// child: FlutterLogo(size: 150.0), -/// ), -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/slide_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -302,41 +231,10 @@ class SlideTransition extends AnimatedWidget { /// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/scale_transition.mp4} /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// The following code implements the [ScaleTransition] as seen in the video /// above: /// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// late final Animation _animation = CurvedAnimation( -/// parent: _controller, -/// curve: Curves.fastOutSlowIn, -/// ); -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// _controller.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: ScaleTransition( -/// scale: _animation, -/// child: const Padding( -/// padding: EdgeInsets.all(8.0), -/// child: FlutterLogo(size: 150.0), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/scale_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -402,41 +300,10 @@ class ScaleTransition extends AnimatedWidget { /// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/rotation_transition.mp4} /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// The following code implements the [RotationTransition] as seen in the video /// above: /// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// late final Animation _animation = CurvedAnimation( -/// parent: _controller, -/// curve: Curves.elasticOut, -/// ); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: Center( -/// child: RotationTransition( -/// turns: _animation, -/// child: const Padding( -/// padding: EdgeInsets.all(8.0), -/// child: FlutterLogo(size: 150.0), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/rotation_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -509,41 +376,11 @@ class RotationTransition extends AnimatedWidget { /// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/size_transition.mp4} /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// This code defines a widget that uses [SizeTransition] to change the size /// of [FlutterLogo] continually. It is built with a [Scaffold] /// where the internal widget has space to change its size. /// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 3), -/// vsync: this, -/// )..repeat(); -/// late final Animation _animation = CurvedAnimation( -/// parent: _controller, -/// curve: Curves.fastOutSlowIn, -/// ); -/// -/// @override -/// void dispose() { -/// super.dispose(); -/// _controller.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Scaffold( -/// body: SizeTransition( -/// sizeFactor: _animation, -/// axis: Axis.horizontal, -/// axisAlignment: -1, -/// child: const Center( -/// child: FlutterLogo(size: 200.0), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/size_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -635,40 +472,10 @@ class SizeTransition extends AnimatedWidget { /// animated by a [CurvedAnimation] set to [Curves.fastOutSlowIn]: /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// The following code implements the [FadeTransition] using /// the Flutter logo: /// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// late final Animation _animation = CurvedAnimation( -/// parent: _controller, -/// curve: Curves.easeIn, -/// ); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.white, -/// child: FadeTransition( -/// opacity: _animation, -/// child: const Padding( -/// padding: EdgeInsets.all(8), -/// child: FlutterLogo() -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/fade_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -735,55 +542,7 @@ class FadeTransition extends SingleChildRenderObjectWidget { /// Creates a [CustomScrollView] with a [SliverFixedExtentList] that uses a /// [SliverFadeTransition] to fade the list in and out. /// -/// ```dart -/// class _MyStatefulWidgetState extends State with SingleTickerProviderStateMixin { -/// late final AnimationController controller = AnimationController( -/// duration: const Duration(milliseconds: 1000), -/// vsync: this, -/// ); -/// late final Animation animation = CurvedAnimation( -/// parent: controller, -/// curve: Curves.easeIn, -/// ); -/// -/// @override -/// void initState() { -/// super.initState(); -/// animation.addStatusListener((AnimationStatus status) { -/// if (status == AnimationStatus.completed) { -/// controller.reverse(); -/// } else if (status == AnimationStatus.dismissed) { -/// controller.forward(); -/// } -/// }); -/// controller.forward(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return CustomScrollView( -/// slivers: [ -/// SliverFadeTransition( -/// opacity: animation, -/// sliver: SliverFixedExtentList( -/// itemExtent: 100.0, -/// delegate: SliverChildBuilderDelegate( -/// (BuildContext context, int index) { -/// return Container( -/// color: index.isEven -/// ? Colors.indigo[200] -/// : Colors.orange[200], -/// ); -/// }, -/// childCount: 5, -/// ), -/// ), -/// ) -/// ] -/// ); -/// } -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/sliver_fade_transition.0.dart ** /// {@end-tool} /// /// Here's an illustration of the [FadeTransition] widget, the [RenderBox] @@ -878,51 +637,10 @@ class RelativeRectTween extends Tween { /// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/positioned_transition.mp4} /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// The following code implements the [PositionedTransition] as seen in the video /// above: /// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// const double smallLogo = 100; -/// const double bigLogo = 200; -/// -/// return LayoutBuilder( -/// builder: (BuildContext context, BoxConstraints constraints) { -/// final Size biggest = constraints.biggest; -/// return Stack( -/// children: [ -/// PositionedTransition( -/// rect: RelativeRectTween( -/// begin: RelativeRect.fromSize(const Rect.fromLTWH(0, 0, smallLogo, smallLogo), biggest), -/// end: RelativeRect.fromSize(Rect.fromLTWH(biggest.width - bigLogo, biggest.height - bigLogo, bigLogo, bigLogo), biggest), -/// ).animate(CurvedAnimation( -/// parent: _controller, -/// curve: Curves.elasticInOut, -/// )), -/// child: const Padding( -/// padding: EdgeInsets.all(8), -/// child: FlutterLogo() -/// ), -/// ), -/// ], -/// ); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/positioned_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -978,52 +696,10 @@ class PositionedTransition extends AnimatedWidget { /// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/relative_positioned_transition.mp4} /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// The following code implements the [RelativePositionedTransition] as seen in the video /// above: /// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// const double smallLogo = 100; -/// const double bigLogo = 200; -/// -/// return LayoutBuilder( -/// builder: (BuildContext context, BoxConstraints constraints) { -/// final Size biggest = constraints.biggest; -/// return Stack( -/// children: [ -/// RelativePositionedTransition( -/// size: biggest, -/// rect: RectTween( -/// begin: const Rect.fromLTWH(0, 0, bigLogo, bigLogo), -/// end: Rect.fromLTWH(biggest.width - smallLogo, biggest.height - smallLogo, smallLogo, smallLogo), -/// ).animate(CurvedAnimation( -/// parent: _controller, -/// curve: Curves.elasticInOut, -/// )) as Animation, -/// child: const Padding( -/// padding: EdgeInsets.all(8), -/// child: FlutterLogo() -/// ), -/// ), -/// ], -/// ); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/relative_positioned_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -1095,62 +771,7 @@ class RelativePositionedTransition extends AnimatedWidget { /// The following code implements the [DecoratedBoxTransition] as seen in the video /// above: /// -/// ```dart -/// final DecorationTween decorationTween = DecorationTween( -/// begin: BoxDecoration( -/// color: const Color(0xFFFFFFFF), -/// border: Border.all(style: BorderStyle.none), -/// borderRadius: BorderRadius.circular(60.0), -/// shape: BoxShape.rectangle, -/// boxShadow: const [ -/// BoxShadow( -/// color: Color(0x66666666), -/// blurRadius: 10.0, -/// spreadRadius: 3.0, -/// offset: Offset(0, 6.0), -/// ) -/// ], -/// ), -/// end: BoxDecoration( -/// color: const Color(0xFFFFFFFF), -/// border: Border.all( -/// style: BorderStyle.none, -/// ), -/// borderRadius: BorderRadius.zero, -/// // No shadow. -/// ), -/// ); -/// -/// late final AnimationController _controller = AnimationController( -/// vsync: this, -/// duration: const Duration(seconds: 3), -/// )..repeat(reverse: true); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.white, -/// child: Center( -/// child: DecoratedBoxTransition( -/// position: DecorationPosition.background, -/// decoration: decorationTween.animate(_controller), -/// child: Container( -/// width: 200, -/// height: 200, -/// padding: const EdgeInsets.all(10), -/// child: const FlutterLogo(), -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/decorated_box_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -1212,42 +833,7 @@ class DecoratedBoxTransition extends AnimatedWidget { /// The following code implements the [AlignTransition] as seen in the video /// above: /// -/// ```dart -/// // Using `late final` for [lazy initialization](https://dart.dev/null-safety/understanding-null-safety#lazy-initialization). -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// late final Animation _animation = Tween( -/// begin: Alignment.bottomLeft, -/// end: Alignment.center, -/// ).animate( -/// CurvedAnimation( -/// parent: _controller, -/// curve: Curves.decelerate, -/// ), -/// ); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Container( -/// color: Colors.white, -/// child: AlignTransition( -/// alignment: _animation, -/// child: const Padding( -/// padding: EdgeInsets.all(8), -/// child: FlutterLogo(size: 150.0), -/// ), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/align_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -1308,48 +894,10 @@ class AlignTransition extends AnimatedWidget { /// of its [TextStyle]. /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// The following code implements the [DefaultTextStyleTransition] that shows /// a transition between thick blue font and thin red font. /// -/// ```dart -/// late AnimationController _controller; -/// late TextStyleTween _styleTween; -/// late CurvedAnimation _curvedAnimation; -/// -/// @override -/// void initState() { -/// super.initState(); -/// _controller = AnimationController( -/// duration: const Duration(seconds: 2), -/// vsync: this, -/// )..repeat(reverse: true); -/// _styleTween = TextStyleTween( -/// begin: const TextStyle(fontSize: 50, color: Colors.blue, fontWeight: FontWeight.w900), -/// end: const TextStyle(fontSize: 50, color: Colors.red, fontWeight: FontWeight.w100), -/// ); -/// _curvedAnimation = CurvedAnimation( -/// parent: _controller, -/// curve: Curves.elasticInOut, -/// ); -/// } -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return Center( -/// child: DefaultTextStyleTransition( -/// style: _styleTween.animate(_curvedAnimation), -/// child: const Text('Flutter'), -/// ), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/default_text_style_transition.0.dart ** /// {@end-tool} /// /// See also: @@ -1436,48 +984,11 @@ class DefaultTextStyleTransition extends AnimatedWidget { /// performance significantly in some cases and is therefore a good practice. /// /// {@tool dartpad --template=stateful_widget_material_ticker} -/// /// This code defines a widget that spins a green square continually. It is /// built with an [AnimatedBuilder] and makes use of the [child] feature to /// avoid having to rebuild the [Container] each time. /// -/// ```dart dartImports -/// import 'dart:math' as math; -/// ``` -/// -/// ```dart -/// late final AnimationController _controller = AnimationController( -/// duration: const Duration(seconds: 10), -/// vsync: this, -/// )..repeat(); -/// -/// @override -/// void dispose() { -/// _controller.dispose(); -/// super.dispose(); -/// } -/// -/// @override -/// Widget build(BuildContext context) { -/// return AnimatedBuilder( -/// animation: _controller, -/// child: Container( -/// width: 200.0, -/// height: 200.0, -/// color: Colors.green, -/// child: const Center( -/// child: Text('Whee!'), -/// ), -/// ), -/// builder: (BuildContext context, Widget? child) { -/// return Transform.rotate( -/// angle: _controller.value * 2.0 * math.pi, -/// child: child, -/// ); -/// }, -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/transitions/animated_builder.0.dart ** /// {@end-tool} /// /// See also: diff --git a/packages/flutter/lib/src/widgets/tween_animation_builder.dart b/packages/flutter/lib/src/widgets/tween_animation_builder.dart index 46477069c5..8e7b988e8c 100644 --- a/packages/flutter/lib/src/widgets/tween_animation_builder.dart +++ b/packages/flutter/lib/src/widgets/tween_animation_builder.dart @@ -67,30 +67,7 @@ import 'value_listenable_builder.dart'; /// is pressed, it smoothly changes its size to the new target value of either /// 48 or 24. /// -/// ```dart -/// double targetValue = 24.0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return TweenAnimationBuilder( -/// tween: Tween(begin: 0, end: targetValue), -/// duration: const Duration(seconds: 1), -/// builder: (BuildContext context, double size, Widget? child) { -/// return IconButton( -/// iconSize: size, -/// color: Colors.blue, -/// icon: child!, -/// onPressed: () { -/// setState(() { -/// targetValue = targetValue == 24.0 ? 48.0 : 24.0; -/// }); -/// }, -/// ); -/// }, -/// child: const Icon(Icons.aspect_ratio), -/// ); -/// } -/// ``` +/// ** See code in examples/api/lib/widgets/tween_animation_builder/tween_animation_builder.0.dart ** /// {@end-tool} /// /// ## Relationship to [ImplicitlyAnimatedWidget]s and [AnimatedWidget]s diff --git a/packages/flutter/lib/src/widgets/will_pop_scope.dart b/packages/flutter/lib/src/widgets/will_pop_scope.dart index 8445fb40af..3dd14b55e3 100644 --- a/packages/flutter/lib/src/widgets/will_pop_scope.dart +++ b/packages/flutter/lib/src/widgets/will_pop_scope.dart @@ -30,56 +30,9 @@ import 'routes.dart'; /// {@end-tool} /// /// {@tool dartpad --template=stateful_widget_material} -/// ```dart -/// bool shouldPop = true; -/// @override -/// Widget build(BuildContext context) { -/// return WillPopScope( -/// onWillPop: () async { -/// return shouldPop; -/// }, -/// child: Scaffold( -/// appBar: AppBar( -/// title: const Text('Flutter WillPopScope demo'), -/// ), -/// body: Center( -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// OutlinedButton( -/// child: const Text('Push'), -/// onPressed: () { -/// Navigator.of(context).push( -/// MaterialPageRoute( -/// builder: (BuildContext context) { -/// return const MyStatefulWidget(); -/// }, -/// ), -/// ); -/// }, -/// ), -/// OutlinedButton( -/// child: Text('shouldPop: $shouldPop'), -/// onPressed: () { -/// setState( -/// () { -/// shouldPop = !shouldPop; -/// }, -/// ); -/// }, -/// ), -/// const Text('Push to a new screen, then tap on shouldPop ' -/// 'button to toggle its value. Press the back ' -/// 'button in the appBar to check its behaviour ' -/// 'for different values of shouldPop'), -/// ], -/// ), -/// ), -/// ), -/// ); -/// } -/// ``` /// +/// +/// ** See code in examples/api/lib/widgets/will_pop_scope/will_pop_scope.1.dart ** /// {@end-tool} /// /// See also: