Google I/O 刚过去,有没有想法入 Flutter 呢?Samples 收录了大量 Flutter 编写的示例,你可以学习下来 pick Flutter 的最佳实践。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Go to file
dependabot[bot] 1ccce7c9e1
Bump jasmine-core from 5.4.0 to 5.5.0 in /web_embedding/ng-flutter (#2545)
3 weeks ago
.github Bump subosito/flutter-action from 2.17.0 to 2.18.0 (#2537) 3 weeks ago
add_to_app Clean up SDK constraints and lints (#2471) 3 months ago
ai_recipe_generation Remove io sample (#2490) 1 month ago
analysis_defaults Clean up SDK constraints and lints (#2471) 3 months ago
android_splash_screen Clean up SDK constraints and lints (#2471) 3 months ago
animations Clean up SDK constraints and lints (#2471) 3 months ago
asset_transformation Clean up SDK constraints and lints (#2471) 3 months ago
background_isolate_channels Bump intl from 0.19.0 to 0.20.0 in /background_isolate_channels (#2484) 1 month ago
code_sharing Clean up SDK constraints and lints (#2471) 3 months ago
compass_app refactor Result class, remove asOk and asError (#2542) 3 weeks ago
context_menus Clean up SDK constraints and lints (#2471) 3 months ago
deeplink_store_example Clean up SDK constraints and lints (#2471) 3 months ago
desktop_photo_search Clean up SDK constraints and lints (#2471) 3 months ago
dynamic_theme Clean up SDK constraints and lints (#2471) 3 months ago
experimental Bump ffigen from 15.0.0 to 16.0.0 in /experimental/pedometer (#2489) 1 month ago
flutter_maps_firestore Clean up SDK constraints and lints (#2471) 3 months ago
form_app Bump intl from 0.19.0 to 0.20.0 in /form_app (#2485) 1 month ago
game_template Clean up SDK constraints and lints (#2471) 3 months ago
gemini_tasks Clean up SDK constraints and lints (#2471) 3 months ago
google_maps Clean up SDK constraints and lints (#2471) 3 months ago
infinite_list Clean up SDK constraints and lints (#2471) 3 months ago
ios_app_clip Clean up SDK constraints and lints (#2471) 3 months ago
isolate_example Clean up SDK constraints and lints (#2471) 3 months ago
jsonexample Drop `jsonexample` (#2089) 1 year ago
material_3_demo Clean up SDK constraints and lints (#2471) 3 months ago
navigation_and_routing Clean up SDK constraints and lints (#2471) 3 months ago
place_tracker Clean up SDK constraints and lints (#2471) 3 months ago
platform_channels Clean up SDK constraints and lints (#2471) 3 months ago
platform_design Clean up SDK constraints and lints (#2471) 3 months ago
platform_view_swift Clean up SDK constraints and lints (#2471) 3 months ago
provider_counter Clean up SDK constraints and lints (#2471) 3 months ago
provider_shopper Clean up SDK constraints and lints (#2471) 3 months ago
simple_shader Clean up SDK constraints and lints (#2471) 3 months ago
simplistic_calculator Clean up SDK constraints and lints (#2471) 3 months ago
simplistic_editor Clean up SDK constraints and lints (#2471) 3 months ago
testing_app Clean up SDK constraints and lints (#2471) 3 months ago
tool Remove io sample (#2490) 1 month ago
veggieseasons Bump intl from 0.19.0 to 0.20.0 in /veggieseasons (#2486) 1 month ago
web Clean up SDK constraints and lints (#2471) 3 months ago
web_embedding Bump jasmine-core from 5.4.0 to 5.5.0 in /web_embedding/ng-flutter (#2545) 3 weeks ago
.gitattributes Add a .gitattributes file (#929) 3 years ago
.gitignore Drop lock files from repo (#1282) 3 years ago
AUTHORS Add game_template (#1180) 3 years ago
CHANGELOG.md Update readme, add changelog (#2535) 3 weeks ago
CONTRIBUTING.md Update contributing guidelines for repository (#2500) 4 weeks ago
LICENSE Adding Rally App to Flutter Samples (#135) 5 years ago
PATENTS Initial commit 7 years ago
README.md Update readme, add changelog (#2535) 3 weeks ago

README.md

Flutter samples

Build Status

A collection of open source samples that illustrate best practices for Flutter.

Index

Quickstarts

  • asset_transformation - Demonstrates how to transform images' color scales and formats.
  • background_isolate_channels - Demonstrates how to use long-lived isolates.
  • code_sharing - Demonstrates how to share business logic between Flutter client and Dart server using package:shelf )
  • context_menus - This sample shows how to create and customize cross-platform context menus, such as the text selection toolbar on mobile or the right click menu on desktop.
  • desktop_photo_search - Demonstrates desktop features in both Material and FluentUI design systems.
  • dynamic_theme - A developer sample demonstrating how to call on-device Flutter APIs based on output from the Gemini API.
  • form_app - A sample demonstrating different types of forms and best practices.
  • game_template - (note: deprecated!) A starter game in Flutter with all the bells and whistles of a mobile (iOS & Android) game.
  • gemini_tasks - A developer sample written in Flutter demonstrating how to interact with a to-do list in natural language using the Gemini API.
  • google_maps - Demonstrates the Google Maps for Flutter plugin.
  • infinite_list - A Flutter sample app that shows an implementation of the "infinite list" UX pattern.
  • isolate_example - A sample application that demonstrate best practices when using isolates.
  • navigation_and_routing - A sample that shows how to use go_router API to handle common navigation scenarios.
  • place_tracker - A sample place tracking app that uses the google_maps_flutter plugin.
  • platform_design - This sample project shows a Flutter app that maximizes application code reuse while adhering to different design patterns on Android and iOS.
  • provider_counter - The starter Flutter application, but using package:provider to manage state.
  • provider_shopper - A Flutter sample app that shows a state management approach using package:provider.
  • simple_shader - A simple Flutter fragment shaders sample project.
  • simplistic_calculator - A calculator to demonstrate a simple start for a desktop Flutter app.
  • simplistic_editor - This sample text editor showcases the use of TextEditingDeltas and a DeltaTextInputClient to expand and contract styled ranges of text.
  • testing_app - A sample app that shows different types of testing in Flutter.
  • web_embedding - This directory contains examples of how to embed Flutter in web apps (without iframes).
    • element_embedding_demo - Modifies the index.html of a flutter app so it is launched in a custom hostElement. This is the most basic embedding example.
    • ng-flutter - A simple Angular app (and component) that replicates the above example, but in an Angular style.

Native platform samples

  • add-to-app - Collection of samples that demonstrate embedding Flutter a view into a native app.
    • fullscreen — Embeds a full screen instance of Flutter into an existing iOS or Android app.
    • prebuilt_module — Embeds a full screen instance of Flutter as a prebuilt library that can be loaded into an existing iOS or Android app.
    • plugin — Embeds a full screen Flutter instance that is using plugins into an existing iOS or Android app.
    • books — Mimics a real world use-case of embedding Flutter into an existing Android app and demonstrates using Pigeon to communicate between Flutter and the host application.
    • multiple_flutters — Shows the usage of the Flutter Engine Group APIs to embed multiple instances of Flutter into an existing app with low memory cost.
    • android_view — Shows how to integrate a Flutter add-to-app module at a view level for Android.
  • android_splash_screen
  • ios_app_clip
  • platform_channels - A sample app which demonstrates how to use MethodChannel, EventChannel, BasicMessageChannel and MessageCodec in Flutter.
  • platform_view_swift - A Flutter sample app that combines a native iOS UIViewController with a full-screen Flutter view.

Demo galleries

Demo apps

Flutter sample code

Samples are correct and concise code that developers can quickly understand and easily reuse with minimal side effects. Samples teach developers how to be successful using Flutter and Dart. They are maintained on an ongoing basis to reflect changing APIs and best practices.

Types of samples

There are two types of sample code in this repository:

  • Quickstarts provide a starting point to extend. They answer the question, "What is the minimal amount of code needed to implement this feature?"
  • Demo apps are meant to be built and ran. They demo the product, not how to write code.

A majority of samples in this repository are quickstarts.

Usage

Every sample in this repo is fully runnable. To run an example, use flutter run inside that example's directory. See the getting started guide to install the flutter tool.

[!IMPORTANT]
If you want to run an add-to-app sample, there are additional requirements. We suggest reading the add-to-app documentation.

Tip: minimize download size

As this repository is quite big, you can use svn to download a single example. For example:

svn co https://github.com/flutter/samples/trunk/provider_shopper

You can also use a partial clone to skip blob objects that aren't currently checked out, while including the full commit history:

git clone --filter=blob:none https://github.com/flutter/samples.git

Interested in contributing?

See the [contributor's guide]!

Questions or issues?

If you have a general question about one of these samples or how to adapt its techniques for one of your own apps, try one of these resources:

If you run into a bug in one of the samples, please file an issue in the flutter/samples issue tracker.