A Flutter add-to-app demo you can try with your own apps

Overview

Put Flutter to Work 🏠

Hello!

This project is a demo intended to help people test drive Flutter by integrating it into their existing applications.

Included in this repo is a Flutter add-to-app module, which contains the UI and logic for displaying a popup to capture user feedback (a "net promoter score"). Alongside the module are three newsfeed applications for iOS, Android, and web, built with SwiftUI, Kotlin, and Angular, respectively.

The applications demonstrate how to import a Flutter module and display it using native platform code. If you're looking to learn, for example, how to wire up a UI element in Swift to navigate to content displayed with Flutter, the iOS newsfeed app can show you.

If you'd like to try Flutter in your own applications, you can download a prebuilt copy of the Flutter module for Android, iOS, or web from this repo, and follow the instructions below to integrate it into your own apps. Note that you don't need the Flutter SDK installed on your development machine for these to work!

Downloading and using the pre-compiled Flutter module

iOS

Full instructions for adding a module to an existing iOS app are available in the add-to-app documentation at flutter.dev, but you can find the short version for both Swift and Objective-C below.

Link the Flutter module into your application

  • Download a recent framework build of the Flutter module from this repo.

  • Unzip the archive into the root of your project directory. It will create a directory there called flutter-framework containing the compiled Flutter module.

  • Open the flutter-framework/Release directory and drag App.xcframework and Flutter.xcframework to the General > Frameworks, Libraries, and Embedded Content section of your app target in Xcode.

Update your app's code to show Flutter

Once the Flutter module is linked into your application, you're ready to fire up an instance of the Flutter engine and present the Flutter view controller.

Swift

In AppDelegate.swift, add the following three lines marked as "NEW":

import UIKit
import Flutter // NEW!

@UIApplicationMain
class AppDelegate: FlutterAppDelegate {
  lazy var flutterEngine = FlutterEngine(name: "my flutter engine")  // NEW!

  override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    flutterEngine.run();  // NEW!
    return super.application(application, didFinishLaunchingWithOptions: launchOptions);
  }
}

Then, in a ViewController class somewhere in your app, call these three lines of code to present the Flutter module's UI:

let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
let flutterViewController =
    FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
present(flutterViewController, animated: true, completion: nil)

For a demo, it's usually best to call these in response to a UI event like a button press. Once they're executed, the net promoter score UI will appear in your app!

Objective-C

In AppDelegate.h, add this import:

@import Flutter;

and this property to the AppDelegate interface:

@property (nonatomic,strong) FlutterEngine *flutterEngine;

Next, in AppDelegate.m, add these two lines to didFinishLaunchingWithOptions:

  self.flutterEngine = [[FlutterEngine alloc] initWithName:@"my flutter engine"];
  [self.flutterEngine run];

Then, somewhere in a UIViewController class in your app, @import Flutter and call these lines of code:

FlutterEngine *flutterEngine =
    ((AppDelegate *)UIApplication.sharedApplication.delegate).flutterEngine;
FlutterViewController *flutterViewController =
    [[FlutterViewController alloc] initWithEngine:flutterEngine nibName:nil bundle:nil];
[self presentViewController:flutterViewController animated:YES completion:nil];

For a demo, it's usually best to call these in response to a UI event like a button press. Once they're executed, the net promoter score UI will appear in your app!

Android

Full instructions for adding a module to an existing Android app are available in the add-to-app documentation at flutter.dev, but you can find the short version for both Kotlin and Java below.

Import the Flutter module into your app's codebase

First, download a recent aar build of the Flutter module from this repo. Then, create a directory in the root of your project called flutter and unzip the archive into that directory.

Next, add the following entries to the repositories and dependencies sections to your app/build.gradle file:

repositories {
  // Add these two maven entries.
  maven {
    url '../flutter'
  }
  maven {
    url 'https://storage.googleapis.com/download.flutter.io'
  }
}

dependencies {
  // Add these three entries.
  debugImplementation 'com.example.flutter_module:flutter_debug:1.0'
  profileImplementation 'com.example.flutter_module:flutter_profile:1.0'
  releaseImplementation 'com.example.flutter_module:flutter_release:1.0'
}

Update your app's code to show Flutter

Once the Flutter module is linked into your application, fire up an instance of the Flutter engine and present the Flutter Activity.

Kotlin

In your app's Application class, add a property for a Flutter engine:

lateinit var flutterEngine : FlutterEngine

In onCreate, instantiate and cache a running Flutter engine with this code:

// Instantiate a FlutterEngine.
flutterEngine = FlutterEngine(this)

// Start executing Dart code to pre-warm the FlutterEngine.
flutterEngine.dartExecutor.executeDartEntrypoint(
  DartExecutor.DartEntrypoint.createDefault()
)

// Cache the FlutterEngine to be used by FlutterActivity.
FlutterEngineCache
  .getInstance()
  .put("my_engine_id", flutterEngine)

Then, in an Activity class somewhere in your app, call these four lines of code to launch the Flutter module's UI:

startActivity(
  FlutterActivity
    .withCachedEngine("my_engine_id")
    .build(this)
)

For a demo, it's usually best to call these in response to a UI event like a button press. Once they're executed, the net promoter score UI will appear in your app!

Java

In your app's Application class, add a property for a Flutter engine:

public FlutterEngine flutterEngine;

In onCreate, instantiate and cache a running Flutter engine with this code:

// Instantiate a FlutterEngine.
flutterEngine = new FlutterEngine(this);

// Start executing Dart code to pre-warm the FlutterEngine.
flutterEngine.getDartExecutor().executeDartEntrypoint(
  DartEntrypoint.createDefault()
);

// Cache the FlutterEngine to be used by FlutterActivity.
FlutterEngineCache
    .getInstance()
    .put("my_engine_id", flutterEngine);

Then, in an Activity class somewhere in your app, call these four lines of code to launch the Flutter module's UI:

startActivity(
  FlutterActivity
    .withCachedEngine("my_engine_id")
    .build(currentActivity)
  );

For a demo, it's usually best to call these in response to a UI event like a button press. Once they're executed, the net promoter score UI will appear in your app!

Web

There are nearly as many ways to build a website as there are published websites, so to a certain extent the "right" way to integrate the Flutter module into your site will depend on the particular client-side technologies you're using (Angular, React, Vue, etc.) and the server you're using to host your content (Firebase Hosting, nginx, etc.).

It's not possible to cover all of the possibilities here, but the basic approach is roughly the same for any of them:

  • Download a recent web build of the Flutter module from this repo.

  • Unzip the archive into a folder somewhere within your project's source tree where it will be picked up and served by the server technology you're using (in the "public" folder of a Firebase Hosting project, for example).

  • Add an iframe to one of the pages in your site, and set its src URL to point to the index.html file inside the web-project-flutter folder created when unzipping the archive in the previous step.

  • Add client-side code to the same page to display the iframe in response to a convenient UI event, such as a button press.

Angular

The sample web application in this repo is built with Angular, and can serve as a model for web integrations. If you're also running Angular, follow the steps below to integrate the model into your project.

First, download a recent web build of the Flutter module and unzip it into the src directory of your project.

Next, change <base href="/"> to <base href="./"> in src/web-project-flutter/index.html.

Then update angular.json to include the new files:

"assets": [
    "src/favicon.ico",
    "src/assets",
    "src/web-project-flutter"
],

Add an iframe

<iframe src="./web-project-flutter/index.html"> </iframe>

Move to your Angular project directory and run:

npm install or npm install --legacy-peed-deps depending on your npm dependencies.

Finally, run ng serve to start the application.

Comments
  • Tidy up

    Tidy up

    Bringing repo up to current versions

    Type of Change

    • [ ] ✨ New feature (non-breaking change which adds functionality)
    • [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
    • [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] 🧹 Code refactor
    • [ ] ✅ Build configuration change
    • [ ] 📝 Documentation
    • [x] 🗑️ Chore
    opened by domesticmouse 5
  • chore(deps): bump subosito/flutter-action from 2.6.2 to 2.7.0

    chore(deps): bump subosito/flutter-action from 2.6.2 to 2.7.0

    Bumps subosito/flutter-action from 2.6.2 to 2.7.0.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 5
  • 3.1 - Implement Data Layer

    3.1 - Implement Data Layer

    We need to have a Firebase data layer that starts working immediately after the user updates the Firebase credentials. It will be mocked until those are changed.

    Child Tasks: #45, #35

    opened by BeatriceMitchell 5
  • build: cannot launch module on iOS

    build: cannot launch module on iOS

    Following the instructions in the README and running the app on iOS results in the following error when starting the Flutter Engine

    2022-04-18 15:30:29.359139-0500 newsfeed_app[10857:1383976] Failed to find assets path for "Frameworks/App.framework/flutter_assets"
    2022-04-18 15:30:29.359564-0500 newsfeed_app[10857:1383976] Metal API Validation Enabled
    2022-04-18 15:30:29.408371-0500 newsfeed_app[10857:1384246] [VERBOSE-2:engine.cc(197)] Engine run configuration was invalid.
    2022-04-18 15:30:29.408579-0500 newsfeed_app[10857:1384246] [VERBOSE-2:shell.cc(580)] Could not launch engine with configuration.
    2022-04-18 15:30:29.497715-0500 newsfeed_app[10857:1384272] flutter: Observatory listening on http://127.0.0.1:49572/-IguXrqyB5Y=/
    
    bug 
    opened by felangel 4
  • feat: newsfeed android app

    feat: newsfeed android app

    Description

    Working Android newsfeed app with embedded Flutter application.

    These changes introduce an infinite RecyclerView that, after hitting the first loading break, it will launch the NPS module written in Flutter

    https://user-images.githubusercontent.com/3237451/159703482-6557125c-5388-4bf7-8eab-a94a1ba35406.mov

    This PR doesn't contain naming/ project structure changes - its to be done in separate PR

    Type of Change

    • [x] ✨ New feature (non-breaking change which adds functionality)
    • [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
    • [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
    • [x] 🧹 Code refactor
    • [ ] ✅ Build configuration change
    • [ ] 📝 Documentation
    • [ ] 🗑️ Chore
    opened by Jan-Stepien 4
  • chore(deps): bump actions/checkout from 3.1.0 to 3.2.0

    chore(deps): bump actions/checkout from 3.1.0 to 3.2.0

    Bumps actions/checkout from 3.1.0 to 3.2.0.

    Release notes

    Sourced from actions/checkout's releases.

    v3.2.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/checkout/compare/v3...v3.2.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 3
  • Fix code scanning alert - License

    Fix code scanning alert - License

    After implementing code scanning alerts, it seems as though there isn't a license for this. Adding a license for this repo would be beneficial because it would give users information on how they can use this repo!

    Tracking issue for:

    • [ ] https://github.com/flutter/put-flutter-to-work/security/code-scanning/3
    opened by drewroengoogle 3
  • Some Swift and SwiftUI cleanup to make it more iOS idiomatic

    Some Swift and SwiftUI cleanup to make it more iOS idiomatic

    Description

    The main thing is dependency injection in SwiftUI. We typically use environmentObject instead of singleton approach. Also FlutterEngine does not have to be @Published.

    Type of Change

    • [ ] ✨ New feature (non-breaking change which adds functionality)
    • [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
    • [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
    • [x] 🧹 Code refactor
    • [ ] ✅ Build configuration change
    • [ ] 📝 Documentation
    • [ ] 🗑️ Chore
    opened by hellohuanlin 3
  • feat: web-angular counter app

    feat: web-angular counter app

    Description

    Angular implementation of Flutter Counter app

    Type of Change

    • [x] ✨ New feature (non-breaking change which adds functionality)
    • [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
    • [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] 🧹 Code refactor
    • [ ] ✅ Build configuration change
    • [ ] 📝 Documentation
    • [ ] 🗑️ Chore
    opened by Jan-Stepien 3
  • 1.2 - Define App NPS Required Feature Set

    1.2 - Define App NPS Required Feature Set

    The App NPS will have

    1. An initial rating button panel - 1 through 5
    2. A secondary suite of buttons that appear after the first selection
    3. A "Report An Issue" button
    4. A submit button
    5. A Thank You screen after submission
    opened by BeatriceMitchell 3
  • feat: native ios counter app

    feat: native ios counter app

    Description

    Implementation of ios native counter app with opening Flutter module

    Type of Change

    • [x] ✨ New feature (non-breaking change which adds functionality)
    • [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
    • [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] 🧹 Code refactor
    • [x] ✅ Build configuration change
    • [ ] 📝 Documentation
    • [ ] 🗑️ Chore
    opened by Jan-Stepien 2
  • chore(deps): bump actions/checkout from 3.1.0 to 3.3.0

    chore(deps): bump actions/checkout from 3.1.0 to 3.3.0

    Bumps actions/checkout from 3.1.0 to 3.3.0.

    Release notes

    Sourced from actions/checkout's releases.

    v3.3.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/checkout/compare/v3.2.0...v3.3.0

    v3.2.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/checkout/compare/v3.1.0...v3.2.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 1
  • [DEMO] Add FlutterAppDelegate to SwiftUI project

    [DEMO] Add FlutterAppDelegate to SwiftUI project

    Description

    The current implementation is a default SwiftUI project without an App Delegate.

    This PR contains 2 commits:

    1. use FlutterAppDelegate for add-to-app SwiftUI project;
    2. use a AppDelegate conforming to FlutterAppLifeCycleProvider (if developers can't subclass from FlutterAppDelegate)

    EDIT:

    This is for DEMO (and documentation) purpose, but in the future we probably want to keep 3 separate implementations:

    • SwiftUI without App Delegate
    • SwiftUI with FlutterAppDelegate subclass (1st commit of this PR)
    • SwiftUI with a App Delegate conforming to FlutterAppLifeCycleProvider (2nd commit of this PR)

    Type of Change

    • [ ] ✨ New feature (non-breaking change which adds functionality)
    • [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
    • [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
    • [x] 🧹 Code refactor
    • [ ] ✅ Build configuration change
    • [] 📝 Documentation
    • [ ] 🗑️ Chore
    opened by hellohuanlin 1
  • Use FlutterAppDelegate in iOS demo

    Use FlutterAppDelegate in iOS demo

    By default, SwiftUI does not come with an AppDelegate. However it's very possible that developers may add an AppDelegate so that they can listen to app lifecycle events. So it may make sense to showcase both with and without FlutterAppDelegate.

    opened by hellohuanlin 1
  • Move recommended location for Flutter module in Angular

    Move recommended location for Flutter module in Angular

    Ideally, the compiled version of the Flutter module used with the Angular project would be maintained in the assets rather than the src folder. This is because Angular considers /src to be the root for source files it needs to examine and compile, while /assets is for those things that are to be included by not compiled.

    We should update the README to present this as the happy path for doing the integration, and update the Angular app in the repo to use that approach.

    opened by RedBrogdon 0
Owner
Flutter
Flutter is Google's UI toolkit for building beautiful, natively compiled applications for mobile, web, desktop, and embedded devices from a single codebase.
Flutter
A Flutter Augmented Reality based Furniture App which can help users to virtually try on furniture to their smartphone with personalized instructions

A Flutter Augmented Reality based Furniture App which can help users to virtually try on furniture to their smartphone with personalized instructions

Saksham Jain 9 Dec 10, 2022
Flashcard App where you can learn different topics and create your own flashcards in Google Drive.

flashcard_project Flashcard app connected with Google Spreadsheet Getting Started This is a Flutter Project that works on iOS, Android, Web and MacOS.

Max Weber 11 Oct 24, 2022
null 1 Jan 8, 2022
In this project, we will design a travel app UI with a parallax effect for a unique scroll experience. You will learn how to create your own parallax effect without using external libraries.

Travel App UI In this part, we will design a travel app UI with a parallax effect for a unique scroll experience. You will learn how to create your ow

DebugErrorX 5 Dec 5, 2022
A library that makes it easy for you to create your own custom wizard.

Flutter Wizard Author: Jop Middelkamp A library that makes it easy for you to create your custom wizard. You'll have 100% control over the appearance

Baseflow 13 Dec 2, 2022
Sūpāhīrō is a demo app for the talk/write on super charging your navigation 1.0 in flutter apps

navhero A simple experiment to give nav1.0 super powers. Named routing in Nav 1.0 could get messy, with large router files here and there. This projec

Samuel Abada 9 Dec 3, 2022
Web3-demo-flutter - A demo for the flutter web3 library.

web3_demo_flutter A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you starte

Tommaso Azzalin 0 Oct 7, 2022
This demo shows how you can open an expansion tile while closing an already open expansion tile.

Expansion Tile Open/Close Demo This demo shows you how to open an expansion tile while simultaneously closing an already open tile while maintaining a

Trey Thomas 3 Oct 21, 2022
dos downloader app is developed for downloading video. You can download video from YouTube and Facebook. You can also play video on background

dosdownloader Dos downloader app is developed for downloading video. You can download video from YouTube and Facebook. You can also play video on back

Md Abir Ahsan Tahmim 1 Dec 8, 2021
Stream Chat official Flutter SDK. Build your own chat experience using Dart and Flutter.

Official Flutter packages for Stream Chat Quick Links Register to get an API key for Stream Chat Flutter Chat SDK Tutorial Chat UI Kit Sample apps Thi

Stream 659 Dec 25, 2022
Destini flutter - A choose your own adventure game in flutter

destini_flutter A choose your own adventure game made with flutter. Getting Star

Joel Nickson 1 Jan 2, 2022
Starter app for Flutter that includes many different production app features; some not typically included in demo apps.

first_app: Starter app for a Flutter production app Maintainer: Greger Wedel, https://github.com/gregertw Listed on: Latest build and artifacts: ** La

Greger Teigre Wedel 371 Dec 28, 2022
An extended version of Flutter Colors with more swatches and more flexibility to generate your own custom swatch.

Colours An extended version of Flutter Colors with more swatches and more flexibility to generate your own custom swatch. Getting Started In your flut

Salman S 4 Nov 23, 2021
New trick on how to create your own custom icons in flutter with bottom bar navigation

Customized Bottom Navigation Bar in Flutter | Tech With Sam Customized Bottom Navigation Bar in Flutter - Watch on youtube ✌   App Preview App Screens

Samuel Adekunle 10 Oct 26, 2022
Easily integrate GitHub's Octicons in your own Flutter project

flutter_octicons Use the Octicon icons developed by GitHub and released under the MIT license in Flutter. flutter_octicons automatically updates itsel

Rubin Raithel 6 Nov 21, 2022
validate JSON against your own Blueprint 👑🧬

PART OF QUEEN ?? Validate JSON Against Your Own Blueprint ?? ?? Content Validate JSON Against Your Own Blueprint ?? ?? Content Motivation NOTE Feature

FlutterQueen 12 Oct 29, 2022
Use the template to create your own repository, complete the project and verify

Proyecto Nivelación MisionTic Usar el template para crear un repositorio propio,

nockturb 0 Dec 20, 2021
A JSON serialize class to convert 'to' and 'from' JSON format Enums, DateTime and any of your own classes.

A JSON serialize class to convert 'to' and 'from' JSON format Enums, DateTime and any of your own classes. Introduction Jsonize solves the problem of

null 2 Nov 17, 2022
Today we will show you how you can create your developer portfolio website and app using flutter.

Responsive and Animated Portfolio Website & App - Flutter UI Live Preview Watch it on YouTube Packages we are using: flutter_svg: link goole_fonts: li

Abu Anwar 198 Dec 30, 2022