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
054b5669
Commit
054b5669
authored
Mar 15, 2017
by
Jason Simmons
Committed by
GitHub
Mar 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Framework callback for engine memory pressure events (#8778)
parent
7843afd4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
0 deletions
+62
-0
app.dart
packages/flutter/lib/src/widgets/app.dart
+3
-0
binding.dart
packages/flutter/lib/src/widgets/binding.dart
+13
-0
binding_test.dart
packages/flutter/test/widgets/binding_test.dart
+46
-0
No files found.
packages/flutter/lib/src/widgets/app.dart
View file @
054b5669
...
...
@@ -179,6 +179,9 @@ class _WidgetsAppState extends State<WidgetsApp> implements WidgetsBindingObserv
@override
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
}
@override
void
didHaveMemoryPressure
()
{
}
@override
Widget
build
(
BuildContext
context
)
{
if
(
config
.
onLocaleChanged
!=
null
&&
_localeData
==
null
)
{
...
...
packages/flutter/lib/src/widgets/binding.dart
View file @
054b5669
...
...
@@ -48,6 +48,9 @@ abstract class WidgetsBindingObserver {
/// Called when the system puts the app in the background or returns
/// the app to the foreground.
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
}
/// Called when the system is running low on memory.
void
didHaveMemoryPressure
()
{
}
}
/// The glue between the widgets layer and the Flutter engine.
...
...
@@ -60,6 +63,7 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren
ui
.
window
.
onLocaleChanged
=
handleLocaleChanged
;
PlatformMessages
.
setJSONMessageHandler
(
'flutter/navigation'
,
_handleNavigationMessage
);
PlatformMessages
.
setStringMessageHandler
(
'flutter/lifecycle'
,
_handleLifecycleMessage
);
PlatformMessages
.
setJSONMessageHandler
(
'flutter/system'
,
_handleSystemMessage
);
}
/// The current [WidgetsBinding], if one has been created.
...
...
@@ -213,6 +217,15 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren
return
null
;
}
Future
<
dynamic
>
_handleSystemMessage
(
Map
<
String
,
dynamic
>
message
)
async
{
final
String
type
=
message
[
'type'
];
if
(
type
==
'memoryPressure'
)
{
for
(
WidgetsBindingObserver
observer
in
_observers
)
observer
.
didHaveMemoryPressure
();
}
return
null
;
}
bool
_needToReportFirstFrame
=
true
;
bool
_thisFrameWasUseful
=
true
;
...
...
packages/flutter/test/widgets/binding_test.dart
0 → 100644
View file @
054b5669
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:typed_data'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
class
MemoryPressureObserver
implements
WidgetsBindingObserver
{
bool
sawMemoryPressure
=
false
;
@override
void
didHaveMemoryPressure
()
{
sawMemoryPressure
=
true
;
}
@override
Future
<
bool
>
didPopRoute
()
=>
new
Future
<
bool
>.
value
(
false
);
@override
void
didChangeMetrics
()
{
}
@override
void
didChangeLocale
(
Locale
locale
)
{
}
@override
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
}
}
void
main
(
)
{
setUp
(()
{
WidgetsFlutterBinding
.
ensureInitialized
();
});
testWidgets
(
'didHaveMemoryPressure callback'
,
(
WidgetTester
tester
)
async
{
final
MemoryPressureObserver
observer
=
new
MemoryPressureObserver
();
WidgetsBinding
.
instance
.
addObserver
(
observer
);
final
ByteData
message
=
const
JSONMessageCodec
().
encodeMessage
(
<
String
,
dynamic
>{
'type'
:
'memoryPressure'
});
await
PlatformMessages
.
handlePlatformMessage
(
'flutter/system'
,
message
,
(
_
)
{});
expect
(
observer
.
sawMemoryPressure
,
true
);
WidgetsBinding
.
instance
.
removeObserver
(
observer
);
});
}
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