Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ecb5f805
Unverified
Commit
ecb5f805
authored
Jun 28, 2018
by
Mikkel Nygaard Ravn
Committed by
GitHub
Jun 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Flutter module template use FlutterView with less assumptions (#18883)
parent
108da013
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
33 deletions
+64
-33
build.gradle.tmpl
...s/templates/module/android/Flutter.tmpl/build.gradle.tmpl
+1
-0
Flutter.java
...Flutter.tmpl/src/main/java/io/flutter/facade/Flutter.java
+58
-29
FlutterFragment.java
...tmpl/src/main/java/io/flutter/facade/FlutterFragment.java
+5
-4
No files found.
packages/flutter_tools/templates/module/android/Flutter.tmpl/build.gradle.tmpl
View file @
ecb5f805
...
...
@@ -45,4 +45,5 @@ flutter {
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
}
packages/flutter_tools/templates/module/android/Flutter.tmpl/src/main/java/io/flutter/facade/Flutter.java
View file @
ecb5f805
...
...
@@ -6,10 +6,10 @@ import android.arch.lifecycle.LifecycleObserver;
import
android.arch.lifecycle.OnLifecycleEvent
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.support.v4.app.Fragment
;
import
android.view.View
;
import
android.support.annotation.NonNull
;
import
io.flutter.app.FlutterActivityDelegate
;
import
io.flutter.plugin.common.BasicMessageChannel
;
import
io.flutter.plugin.common.StringCodec
;
import
io.flutter.view.FlutterMain
;
import
io.flutter.view.FlutterNativeView
;
import
io.flutter.view.FlutterView
;
...
...
@@ -27,72 +27,101 @@ public final class Flutter {
// to prevent instantiation
}
public
static
void
startInitialization
(
Context
applicationContext
)
{
/**
* Initiates the Dart VM. Calling this method at an early point may help decreasing time to first
* frame for a subsequently created {@link FlutterView}.
*
* @param applicationContext the application's {@link Context}
*/
public
static
void
startInitialization
(
@NonNull
Context
applicationContext
)
{
FlutterMain
.
startInitialization
(
applicationContext
,
null
);
}
public
static
Fragment
createFragment
(
String
route
)
{
/**
* Creates a {@link FlutterFragment} managing a {@link FlutterView}. The optional
* initial route string will be made available to the Dart code
* (via {@code window.defaultRouteName}) and may be used to determine which widget
* should be displayed in the view. The default initialRoute is "/".
*
* @param initialRoute an initial route {@link String}, or null
* @return a {@link FlutterFragment}
*/
@NonNull
public
static
FlutterFragment
createFragment
(
String
initialRoute
)
{
final
FlutterFragment
fragment
=
new
FlutterFragment
();
final
Bundle
args
=
new
Bundle
();
args
.
putString
(
FlutterFragment
.
ARG_ROUTE
,
r
oute
);
args
.
putString
(
FlutterFragment
.
ARG_ROUTE
,
initialR
oute
);
fragment
.
setArguments
(
args
);
return
fragment
;
}
public
static
View
createView
(
final
Activity
activity
,
final
Lifecycle
lifecycle
,
final
String
route
)
{
/**
* Creates a {@link FlutterView} linked to the specified {@link Activity} and {@link Lifecycle}.
* The optional initial route string will be made available to the Dart code (via
* {@code window.defaultRouteName}) and may be used to determine which widget should be displayed
* in the view. The default initialRoute is "/".
*
* @param activity an {@link Activity}
* @param lifecycle a {@link Lifecycle}
* @param initialRoute an initial route {@link String}, or null
* @return a {@link FlutterView}
*/
@NonNull
public
static
FlutterView
createView
(
@NonNull
final
Activity
activity
,
@NonNull
final
Lifecycle
lifecycle
,
final
String
initialRoute
)
{
FlutterMain
.
startInitialization
(
activity
.
getApplicationContext
());
FlutterMain
.
ensureInitializationComplete
(
activity
.
getApplicationContext
(),
null
);
final
FlutterActivityDelegate
delegate
=
new
FlutterActivityDelegate
(
activity
,
new
FlutterActivityDelegate
.
ViewFactory
()
{
final
FlutterNativeView
nativeView
=
new
FlutterNativeView
(
activity
);
final
FlutterView
flutterView
=
new
FlutterView
(
activity
,
null
,
nativeView
)
{
private
final
BasicMessageChannel
<
String
>
lifecycleMessages
=
new
BasicMessageChannel
<>(
this
,
"flutter/lifecycle"
,
StringCodec
.
INSTANCE
);
@Override
public
FlutterView
createFlutterView
(
Context
context
)
{
final
FlutterNativeView
nativeView
=
new
FlutterNativeView
(
context
);
final
FlutterView
flutterView
=
new
FlutterView
(
activity
,
null
,
nativeView
);
flutterView
.
setInitialRoute
(
route
);
return
flutterView
;
public
void
onFirstFrame
()
{
super
.
onFirstFrame
();
setAlpha
(
1.0f
);
}
@Override
public
boolean
retainFlutterNativeView
()
{
return
false
;
public
void
onPostResume
()
{
// Overriding default behavior to avoid dictating system UI via PlatformPlugin.
lifecycleMessages
.
send
(
"AppLifecycleState.resumed"
);
}
@Override
public
FlutterNativeView
createFlutterNativeView
()
{
throw
new
UnsupportedOperationException
();
}
});
};
if
(
initialRoute
!=
null
)
{
flutterView
.
setInitialRoute
(
initialRoute
);
}
lifecycle
.
addObserver
(
new
LifecycleObserver
()
{
@OnLifecycleEvent
(
Lifecycle
.
Event
.
ON_CREATE
)
public
void
onCreate
()
{
delegate
.
onCreate
(
null
);
GeneratedPluginRegistrant
.
registerWith
(
delegate
);
final
String
appBundlePath
=
FlutterMain
.
findAppBundlePath
(
activity
.
getApplicationContext
());
flutterView
.
runFromBundle
(
appBundlePath
,
null
,
"main"
,
true
);
GeneratedPluginRegistrant
.
registerWith
(
flutterView
.
getPluginRegistry
());
}
@OnLifecycleEvent
(
Lifecycle
.
Event
.
ON_START
)
public
void
onStart
()
{
delegate
.
onStart
();
flutterView
.
onStart
();
}
@OnLifecycleEvent
(
Lifecycle
.
Event
.
ON_RESUME
)
public
void
onResume
()
{
delegate
.
on
Resume
();
flutterView
.
onPost
Resume
();
}
@OnLifecycleEvent
(
Lifecycle
.
Event
.
ON_PAUSE
)
public
void
onPause
()
{
delegate
.
onPause
();
flutterView
.
onPause
();
}
@OnLifecycleEvent
(
Lifecycle
.
Event
.
ON_STOP
)
public
void
onStop
()
{
delegate
.
onStop
();
flutterView
.
onStop
();
}
@OnLifecycleEvent
(
Lifecycle
.
Event
.
ON_DESTROY
)
public
void
onDestroy
()
{
delegate
.
onD
estroy
();
flutterView
.
d
estroy
();
}
});
return
delegate
.
getFlutterView
();
flutterView
.
setAlpha
(
0.0f
);
return
flutterView
;
}
}
packages/flutter_tools/templates/module/android/Flutter.tmpl/src/main/java/io/flutter/facade/FlutterFragment.java
View file @
ecb5f805
...
...
@@ -2,14 +2,16 @@ package io.flutter.facade;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.Fragment
;
import
android.util.AttributeSet
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
io.flutter.view.FlutterView
;
/**
* A {@link Fragment} managing a
Flutter view
.
* A {@link Fragment} managing a
{@link FlutterView}
.
*
* <p><strong>Warning:</strong> This file is auto-generated by Flutter tooling. Do not edit.
* It may be moved into flutter.jar or another library dependency of the Flutter module project
...
...
@@ -33,8 +35,7 @@ public class FlutterFragment extends Fragment {
}
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
public
FlutterView
onCreateView
(
@NonNull
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
return
Flutter
.
createView
(
getActivity
(),
getLifecycle
(),
mRoute
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment