Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jonny Borges
2024-03-08 16:51:49 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2f2d128e2b5330649995f3e9d7f8a6201f0c3079
2f2d128e
1 parent
272aa469
fix: snackbar memory leak
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
35 deletions
example/.metadata
example/lib/main.dart
example_nav2/android/local.properties
lib/get_navigation/src/root/get_root.dart
lib/get_navigation/src/snackbar/snackbar_controller.dart
lib/get_utils/src/equality/equality.dart
test/navigation/snackbar_test.dart
example/.metadata
View file @
2f2d128
...
...
@@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.
version:
revision: "
e1e47221e86272429674bec4f1bd36acc4fc7b77
"
revision: "
ba393198430278b6595976de84fe170f553cc728
"
channel: "stable"
project_type: app
...
...
@@ -13,11 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
create_revision: ba393198430278b6595976de84fe170f553cc728
base_revision: ba393198430278b6595976de84fe170f553cc728
- platform: ios
create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
create_revision: ba393198430278b6595976de84fe170f553cc728
base_revision: ba393198430278b6595976de84fe170f553cc728
# User provided section
...
...
example/lib/main.dart
View file @
2f2d128
...
...
@@ -76,9 +76,16 @@ class First extends StatelessWidget {
leading:
IconButton
(
icon:
const
Icon
(
Icons
.
more
),
onPressed:
()
{
print
(
'THEME CHANGED'
);
Get
.
changeTheme
(
Get
.
isDarkMode
?
ThemeData
.
light
()
:
ThemeData
.
dark
());
Get
.
snackbar
(
'title'
,
"message"
,
mainButton:
TextButton
(
onPressed:
()
{},
child:
const
Text
(
'button'
)),
isDismissible:
false
,
);
// print('THEME CHANGED');
// Get.changeTheme(
// Get.isDarkMode ? ThemeData.light() : ThemeData.dark());
},
),
),
...
...
example_nav2/android/local.properties
View file @
2f2d128
sdk.dir
=
C:
\\
Users
\\
anike
\\
AppData
\\
Local
\\
Android
\\
sdk
flutter.sdk
=
C:
\\
flutter
\ No newline at end of file
sdk.dir
=
/Users/jonatasborges/Library/Android/sdk
flutter.sdk
=
/Users/jonatasborges/flutter
\ No newline at end of file
...
...
lib/get_navigation/src/root/get_root.dart
View file @
2f2d128
...
...
@@ -45,6 +45,7 @@ class ConfigData {
final
Duration
defaultDialogTransitionDuration
;
final
Routing
routing
;
final
Map
<
String
,
String
?>
parameters
;
final
SnackBarQueue
snackBarQueue
=
SnackBarQueue
();
ConfigData
({
required
this
.
routingCallback
,
...
...
@@ -345,6 +346,8 @@ class GetRootState extends State<GetRoot> with WidgetsBindingObserver {
Get
.
resetInstance
(
clearRouteBindings:
true
);
_controller
=
null
;
ambiguate
(
Engine
.
instance
)!.
removeObserver
(
this
);
config
.
snackBarQueue
.
cancelAllJobs
();
config
.
snackBarQueue
.
disposeControllers
();
}
@override
...
...
lib/get_navigation/src/snackbar/snackbar_controller.dart
View file @
2f2d128
...
...
@@ -5,12 +5,14 @@ import 'dart:ui';
import
'package:flutter/material.dart'
;
import
'../../../get.dart'
;
import
'../root/get_root.dart'
;
class
SnackbarController
{
static
final
_snackBarQueue
=
_SnackBarQueue
();
static
bool
get
isSnackbarBeingShown
=>
_snackBarQueue
.
_isJobInProgress
;
final
key
=
GlobalKey
<
GetSnackBarState
>();
static
bool
get
isSnackbarBeingShown
=>
GetRootState
.
controller
.
config
.
snackBarQueue
.
isJobInProgress
;
late
Animation
<
double
>
_filterBlurAnimation
;
late
Animation
<
Color
?>
_filterColorAnimation
;
...
...
@@ -60,7 +62,7 @@ class SnackbarController {
/// Only one GetSnackbar will be displayed at a time, and this method returns
/// a future to when the snackbar disappears.
Future
<
void
>
show
()
{
return
_snackBarQueue
.
_
addJob
(
this
);
return
GetRootState
.
controller
.
config
.
snackBarQueue
.
addJob
(
this
);
}
void
_cancelTimer
()
{
...
...
@@ -348,15 +350,15 @@ class SnackbarController {
}
static
Future
<
void
>
cancelAllSnackbars
()
async
{
await
_snackBarQueue
.
_
cancelAllJobs
();
await
GetRootState
.
controller
.
config
.
snackBarQueue
.
cancelAllJobs
();
}
static
Future
<
void
>
closeCurrentSnackbar
()
async
{
await
_snackBarQueue
.
_
closeCurrentJob
();
await
GetRootState
.
controller
.
config
.
snackBarQueue
.
closeCurrentJob
();
}
}
class
_
SnackBarQueue
{
class
SnackBarQueue
{
final
_queue
=
GetQueue
();
final
_snackbarList
=
<
SnackbarController
>[];
...
...
@@ -365,22 +367,28 @@ class _SnackBarQueue {
return
_snackbarList
.
first
;
}
bool
get
_
isJobInProgress
=>
_snackbarList
.
isNotEmpty
;
bool
get
isJobInProgress
=>
_snackbarList
.
isNotEmpty
;
Future
<
void
>
_
addJob
(
SnackbarController
job
)
async
{
Future
<
void
>
addJob
(
SnackbarController
job
)
async
{
_snackbarList
.
add
(
job
);
final
data
=
await
_queue
.
add
(
job
.
_show
);
_snackbarList
.
remove
(
job
);
return
data
;
}
Future
<
void
>
_
cancelAllJobs
()
async
{
Future
<
void
>
cancelAllJobs
()
async
{
await
_currentSnackbar
?.
close
();
_queue
.
cancelAllJobs
();
_snackbarList
.
clear
();
}
Future
<
void
>
_closeCurrentJob
()
async
{
Future
<
void
>
disposeControllers
()
async
{
for
(
var
element
in
_snackbarList
)
{
element
.
_controller
.
dispose
();
}
}
Future
<
void
>
closeCurrentJob
()
async
{
if
(
_currentSnackbar
==
null
)
return
;
await
_currentSnackbar
!.
close
();
}
...
...
lib/get_utils/src/equality/equality.dart
View file @
2f2d128
...
...
@@ -6,9 +6,10 @@ mixin Equality {
List
get
props
;
@override
bool
operator
==(
dynamic
other
)
{
bool
operator
==(
Object
other
)
{
return
identical
(
this
,
other
)
||
runtimeType
==
other
.
runtimeType
&&
other
is
Equality
&&
const
DeepCollectionEquality
().
equals
(
props
,
other
.
props
);
}
...
...
test/navigation/snackbar_test.dart
View file @
2f2d128
...
...
@@ -110,7 +110,12 @@ void main() {
const
dismissDirection
=
DismissDirection
.
vertical
;
const
snackBarTapTarget
=
Key
(
'snackbar-tap-target'
);
late
final
GetSnackBar
getBar
;
const
GetSnackBar
getBar
=
GetSnackBar
(
message:
'bar1'
,
duration:
Duration
(
seconds:
2
),
isDismissible:
true
,
dismissDirection:
dismissDirection
,
);
await
tester
.
pumpWidget
(
GetMaterialApp
(
home:
Scaffold
(
...
...
@@ -121,12 +126,6 @@ void main() {
GestureDetector
(
key:
snackBarTapTarget
,
onTap:
()
{
getBar
=
const
GetSnackBar
(
message:
'bar1'
,
duration:
Duration
(
seconds:
2
),
isDismissible:
true
,
dismissDirection:
dismissDirection
,
);
Get
.
showSnackbar
(
getBar
);
},
behavior:
HitTestBehavior
.
opaque
,
...
...
@@ -150,14 +149,14 @@ void main() {
await
tester
.
tap
(
find
.
byKey
(
snackBarTapTarget
));
await
tester
.
pumpAndSettle
();
expect
(
Get
.
isSnackbarOpen
,
true
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
(
find
.
byWidget
(
getBar
),
findsOneWidget
);
await
tester
.
ensureVisible
(
find
.
byWidget
(
getBar
));
await
tester
.
drag
(
find
.
byWidget
(
getBar
),
const
Offset
(
0.0
,
50.0
));
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
// expect(Get.isSnackbarOpen, true);
// await tester.pump(const Duration(milliseconds: 500));
// expect(find.byWidget(getBar), findsOneWidget);
// await tester.ensureVisible(find.byWidget(getBar));
// await tester.drag(find.byWidget(getBar), const Offset(0.0, 50.0));
// await tester.pump(const Duration(milliseconds: 500));
expect
(
Get
.
isSnackbarOpen
,
false
);
//
expect(Get.isSnackbarOpen, false);
});
testWidgets
(
"test snackbar onTap"
,
(
tester
)
async
{
...
...
Please
register
or
login
to post a comment