-
Notifications
You must be signed in to change notification settings - Fork 1
Experimental: Add Flutter Fragment ViewPager
Everything in this doc and linked from this doc is experimental. These details WILL change. Do not use these instructions or APIs in production code because we will break you.
Tabbed navigation often expects the presence of a ViewPager
, such that the user can swipe left/right to navigate between tabbed pages. This guide shows you how to integrate Flutter as one or more of the pages in your ViewPager
.
Start by implementing standard tabbed navigation in Android with a ViewPager
. Consider following this guide.
Next, alter your FragmentPagerAdapter
to return a FlutterFragment
for the desired page(s).
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if (position == FLUTTER_PAGE_INDEX) {
// In this case we construct a FlutterFragment that will run
// our main() method in Dart and start with an initial route of "/".
return new FlutterFragment.createDefault();
} else {
// return some other page's Fragment
}
}
@Override
public int getCount() {
// You need to define PAGE_COUNT
return PAGE_COUNT;
}
}
You should now have a Flutter UI as one or more pages within your tabbed navigation.
You may notice a delay between creation of your FlutterFragment
and the display of your Flutter UI. This delay is caused by the warm-up time for the FlutterEngine
. This warm-up issue a standard concern that applies to all uses of Flutter, including FlutterActivity
. The way to minimize this visual delay is to use pre-warmed FlutterEngine
s. Please see the page about pre-warming FlutterEngines.
- Home of the Wiki
- Roadmap
- API Reference (stable)
- API Reference (master)
- Glossary
- Contributor Guide
- Chat on Discord
- Code of Conduct
- Issue triage reports
- Our Values
- Tree hygiene
- Issue hygiene and Triage
- Style guide for Flutter repo
- Project teams
- Contributor access
- What should I work on?
- Running and writing tests
- Release process
- Rolling Dart
- Manual Engine Roll with Breaking Commits
- Updating Material Design Fonts & Icons
- Postmortems
- Setting up the Framework development environment
- The Framework architecture
- The flutter tool
- API Docs code block generation
- Running examples
- Using the Dart analyzer
- The flutter run variants
- Test coverage for package:flutter
- Writing a golden-file test for package:flutter
- Setting up the Engine development environment
- Compiling the engine
- Debugging the engine
- Using Sanitizers with the Flutter Engine
- Testing the engine
- The Engine architecture
- Flutter's modes
- Engine disk footprint
- Comparing AOT Snapshot Sizes
- Custom Flutter engine embedders
- Custom Flutter Engine Embedding in AOT Mode
- Flutter engine operation in AOT Mode
- Engine-specific Service Protocol extensions
- Crashes
- Supporting legacy platforms
- Metal on iOS FAQ
- Engine Clang Tidy Linter
- Why we have a separate engine repo
- Reduce Flutter engine size with MLGO
- Setting up the Plugins development environment
- Setting up the Packages development environment
- Plugins and Packages repository structure
- Plugin Tests
- Contributing to Plugins and Packages
- Releasing a Plugin or Package
- Unexpected Plugins and Packages failures