Flutter Samples
repository·main·Indexed 12 days ago
https://github.com/flutter/samplesA collection of open-source Flutter samples illustrating best practices, feature implementations, and platform integration patterns, with a focus on 'Add-to-App' workflows for Android and iOS.
What's inside Flutter Samples
- This sample project demonstrates how to integrate iOS App Clips with Flutter. The App Clip target is rendered using the Flutter engine and utilizes a plugin to handle App Clip-specific functionality. It is intended as a canonical example for developers following the official Flutter guide for App Clip integration.
Overview of the Flutter Dynamic Theme Sample
mainThe Flutter Dynamic Theme Sample is a developer demonstration project that shows how to bridge natural language processing with local device settings. It demonstrates how to use the Gemini API to interpret user intent via a chat session and subsequently trigger specific on-device Flutter API calls to modify theme properties like font scale and colors dynamically while the app is running.Overview of the Date Planner sample app
mainDate Planner is an in-progress exploration of an iOS-style application, modeled after the Apple SwiftUI Tutorial app. It serves as a reference implementation for building date-related planning interfaces in Flutter.Overview of Photo Search app dependencies
mainThe Photo Search app is a desktop application (Windows, macOS, Linux) that uses several specific plugins and libraries:
Desktop Plugins
fluent_ui: Provides the Fluent UI widget set.file_chooser: Enables users to select local destinations to save photos.menubar: Exposes Image Search functionality through the system menu bar.url_launcher: Used to open external links.
API Implementation
The Unsplash API client is implemented via the
Unsplashclass (located inlib/src/unsplash/unsplash.dart) and relies on the following for JSON REST API access:httpbuilt_valuebuilt_collection
Explore Material 3 features in the Material 3 Demo app
mainThe Material 3 Demo app is a sample project designed to showcase the implementation of Material 3 features within the Flutter Material library. It demonstrates updated components, typography, the color system, and elevation support.
Key capabilities demonstrated include:
- Theme Switching: Toggling between light and dark themes.
- Material Version Switching: Switching between Material 2 and Material 3 component styles.
- Dynamic Color Generation: Using a single 'color seed' to generate entire light and dark color schemes.
- Adaptive Layouts: Automatically switching between a
NavigationBar(for narrow screens like mobile) and aNavigationRail(for wide screens like desktop or web). - New Components: Implementation of
IconButtons,Chips,TextFields,Switches,Checkboxes,Radio buttons, andProgressIndicatorsusing M3 specifications.
Embed Flutter with plugins into existing Android or iOS apps
mainThepluginsample demonstrates how to embed a full-screen Flutter instance that utilizes native plugins into an existing native Android or iOS application. Unlike standard Flutter samples, these projects include the specific native code (Kotlin for Android, Swift for iOS) required to initialize plugins during the Flutter engine creation process. This is useful for developers learning the additional steps required to support a Flutter module that relies on platform-specific plugins.Embed Flutter in web apps without iframes
mainThe
web_embeddingdirectory provides examples of embedding Flutter into existing web applications using techniques that do not rely on iframes. This allows Flutter to be launched within a specific host element of a web page.Available examples include:
- element_embedding_demo: The most basic implementation. It demonstrates modifying the
index.htmlof a Flutter app so that it launches within a customhostElement. - ng-flutter: An implementation using the Angular framework. It provides an Angular component that replicates the element embedding pattern.
For specific instructions on how to run these examples and detailed implementation notes, refer to the
README.mdfile located within each specific example directory.- element_embedding_demo: The most basic implementation. It demonstrates modifying the
Use the flutter_module_using_plugin sample
mainThe
flutter_module_using_pluginis a specialized Flutter module designed for 'Add-to-App' scenarios. It demonstrates how a Flutter module can interact with native platform code via a plugin. This sample is intended to be integrated into existing native Android or iOS applications rather than being run as a standalone Flutter app.To understand how to integrate this module into a native host application, refer to the parent directory's README or the official Flutter documentation.
Browse the Flutter samples index
mainThe repository is organized into several categories of samples:
Quickstarts
Focus on specific features like:
asset_transformation: Image color scales and formats.background_isolate_channels: Long-lived isolates.navigation_and_routing: Using thego_routerAPI.simple_shader: Using the FragmentShader API with Signed Distance Functions.web_embedding: Embedding Flutter in web apps (e.g.,element_embedding_demo,ng-flutter).
Native Platform Samples
Focus on integrating Flutter with existing native code:
add-to-app: Embedding Flutter views into iOS or Android (e.g.,fullscreen,prebuilt_module,booksusingPigeon).platform_channels: UsingMethodChannel,EventChannel,BasicMessageChannel, andMessageCodec.platform_view_swift: Combining native iOSUIViewControllerwith Flutter.
Demo Galleries & Apps
- Galleries: Visual showcases like
animationsandmaterial_3_demo. - Apps: Full applications like
compass_app(implementing MVVM architecture).
Combine native iOS UIViewController with Flutter views
mainThe
platform_view_swiftsample demonstrates how to integrate a native iOSUIViewControllerwith a full-screen Flutter view. This is achieved by using a platform channel to communicate between the Flutter layer and the native Swift layer.Implementation Details
- Flutter Layer (
lib/main.dart): Contains the Flutter application logic and interacts with the native side via platform channels. - Native iOS Layer (
ios/Runner/PlatformViewController.swiftandAppDelegate.swift): Contains the Swift code responsible for:- Setting up a platform channel.
- Launching a native
UIViewController. - Returning control back to the Flutter application once the native view interaction is finished.
- Flutter Layer (
Use the android_fullscreen sample in Flutter add-to-app
mainThe
android_fullscreensample is an Android application designed to demonstrate how to integrate Flutter modules into an existing native Android application. This specific sample focuses on implementing a fullscreen experience within the native Android host.To understand the general patterns for integrating Flutter into native applications, refer to the main add_to_app directory in this repository or follow the official Flutter documentation.
Explore Photo Search app UI implementations
mainThe Photo Search app demonstrates how to build the same application using two different Flutter widget sets:
- Material: Uses standard Material widgets.
- Fluent UI: Uses fluent_ui widgets, designed for a Windows-native look and feel.