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 19:23:39 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3a4dced526199585a6fd1325c031271f09e85092
3a4dced5
1 parent
2f2d128e
fix dismissible tests
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
156 deletions
example/lib/main.dart
lib/get_navigation/src/root/get_root.dart
lib/get_navigation/src/snackbar/snackbar.dart
lib/get_navigation/src/snackbar/snackbar_controller.dart
test/navigation/snackbar_test.dart
example/lib/main.dart
View file @
3a4dced
import
'package:flutter/material.dart'
;
import
'package:get/get.dart'
;
// void main() {
// runApp(const MyApp());
// }
// class MyApp extends StatelessWidget {
// const MyApp({Key? key}) : super(key: key);
// @override
// Widget build(BuildContext context) {
// return GetMaterialApp(
// theme: ThemeData(useMaterial3: true),
// debugShowCheckedModeBanner: false,
// enableLog: true,
// logWriterCallback: Logger.write,
// initialRoute: AppPages.INITIAL,
// getPages: AppPages.routes,
// locale: TranslationService.locale,
// fallbackLocale: TranslationService.fallbackLocale,
// translations: TranslationService(),
// );
// }
// }
/// Nav 2 snippet
void
main
(
)
{
runApp
(
const
MyApp
());
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
// This widget is the root of your application.
@override
Widget
build
(
BuildContext
context
)
{
return
GetMaterialApp
(
getPages:
[
GetPage
(
participatesInRootNavigator:
true
,
name:
'/first'
,
page:
()
=>
const
First
()),
GetPage
(
name:
'/second'
,
page:
()
=>
const
Second
(),
transition:
Transition
.
downToUp
,
),
GetPage
(
name:
'/third'
,
page:
()
=>
const
Third
(),
),
],
title:
'Scaffold demo'
,
theme:
ThemeData
(
primarySwatch:
Colors
.
blue
,
),
home:
MyHomePage
(),
debugShowCheckedModeBanner:
false
,
);
}
}
class
FirstController
extends
GetxController
{
@override
void
onClose
()
{
print
(
'on close first'
);
super
.
onClose
();
}
}
class
First
extends
StatelessWidget
{
const
First
({
Key
?
key
})
:
super
(
key:
key
);
class
MyHomePage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
print
(
'First rebuild'
);
Get
.
put
(
FirstController
());
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'page one'
),
leading:
IconButton
(
icon:
const
Icon
(
Icons
.
more
),
title:
Text
(
'Test'
),
centerTitle:
true
,
backgroundColor:
Colors
.
green
,
),
bottomNavigationBar:
SizedBox
(
width:
double
.
infinity
,
child:
ElevatedButton
(
child:
Text
(
'Tap me when Snackbar appears'
),
onPressed:
()
{
Get
.
snackbar
(
'title'
,
"message"
,
mainButton:
TextButton
(
onPressed:
()
{},
child:
const
Text
(
'button'
)),
isDismissible:
false
,
);
// print('THEME CHANGED');
// Get.changeTheme(
// Get.isDarkMode ? ThemeData.light() : ThemeData.dark());
print
(
'This should clicked'
);
},
),
),
body:
Center
(
child:
SizedBox
(
height:
300
,
width:
300
,
child:
ElevatedButton
(
onPressed:
()
{
Get
.
toNamed
(
'/second?id=123'
);
},
child:
const
Text
(
'next screen'
),
),
),
),
);
}
}
class
SecondController
extends
GetxController
{
final
textEdit
=
TextEditingController
();
@override
void
onClose
()
{
print
(
'on close second'
);
textEdit
.
dispose
();
super
.
onClose
();
}
}
class
Second
extends
StatelessWidget
{
const
Second
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
final
controller
=
Get
.
put
(
SecondController
());
print
(
'second rebuild'
);
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'page two
${Get.parameters["id"]}
'
),
),
body:
Center
(
child:
Column
(
children:
[
Expanded
(
child:
TextField
(
controller:
controller
.
textEdit
,
)),
SizedBox
(
height:
300
,
width:
300
,
child:
ElevatedButton
(
onPressed:
()
{},
child:
const
Text
(
'next screen'
),
),
),
],
),
),
);
}
}
class
Third
extends
StatelessWidget
{
const
Third
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
backgroundColor:
Colors
.
red
,
appBar:
AppBar
(
title:
const
Text
(
'page three'
),
),
body:
Center
(
child:
SizedBox
(
height:
300
,
width:
300
,
child:
ElevatedButton
(
onPressed:
()
{},
child:
const
Text
(
'go to first screen'
),
),
child:
ElevatedButton
(
child:
Text
(
'Open Snackbar'
),
onPressed:
()
{
Get
.
snackbar
(
"Snackbar Showed"
,
"Please click the button on BottomNavigationBar"
,
icon:
Icon
(
Icons
.
check
,
color:
Colors
.
green
),
backgroundColor:
Colors
.
white
,
snackStyle:
SnackStyle
.
floating
,
borderRadius:
20
,
isDismissible:
false
,
snackPosition:
SnackPosition
.
bottom
,
margin:
EdgeInsets
.
fromLTRB
(
50
,
15
,
50
,
15
),
);
},
),
),
);
...
...
lib/get_navigation/src/root/get_root.dart
View file @
3a4dced
...
...
@@ -341,13 +341,12 @@ class GetRootState extends State<GetRoot> with WidgetsBindingObserver {
void
onClose
()
{
config
.
onDispose
?.
call
();
Get
.
clearTranslations
();
config
.
snackBarQueue
.
disposeControllers
();
RouterReportManager
.
instance
.
clearRouteKeys
();
RouterReportManager
.
dispose
();
Get
.
resetInstance
(
clearRouteBindings:
true
);
_controller
=
null
;
ambiguate
(
Engine
.
instance
)!.
removeObserver
(
this
);
config
.
snackBarQueue
.
cancelAllJobs
();
config
.
snackBarQueue
.
disposeControllers
();
}
@override
...
...
lib/get_navigation/src/snackbar/snackbar.dart
View file @
3a4dced
...
...
@@ -19,6 +19,13 @@ class GetSnackBar extends StatefulWidget {
/// The title displayed to the user
final
String
?
title
;
/// Defines how the snack bar area, including margin, will behave during hit testing.
///
/// If this property is null and [margin] is not null, then [HitTestBehavior.deferToChild] is used by default.
///
/// Please refer to [HitTestBehavior] for a detailed explanation of every behavior.
final
HitTestBehavior
?
hitTestBehavior
;
/// The direction in which the SnackBar can be dismissed.
///
/// Default is [DismissDirection.down] when
...
...
@@ -203,6 +210,7 @@ class GetSnackBar extends StatefulWidget {
this
.
overlayColor
=
Colors
.
transparent
,
this
.
userInputForm
,
this
.
snackbarStatus
,
this
.
hitTestBehavior
,
})
:
super
(
key:
key
);
@override
...
...
lib/get_navigation/src/snackbar/snackbar_controller.dart
View file @
3a4dced
...
...
@@ -245,6 +245,7 @@ class SnackbarController {
snackbar
.
onHover
?.
call
(
snackbar
,
SnackHoverState
.
entered
),
onExit:
(
_
)
=>
snackbar
.
onHover
?.
call
(
snackbar
,
SnackHoverState
.
exited
),
child:
GestureDetector
(
behavior:
snackbar
.
hitTestBehavior
??
HitTestBehavior
.
deferToChild
,
onTap:
snackbar
.
onTap
!=
null
?
()
=>
snackbar
.
onTap
?.
call
(
snackbar
)
:
null
,
...
...
@@ -263,6 +264,7 @@ class SnackbarController {
Widget
_getDismissibleSnack
(
Widget
child
)
{
return
Dismissible
(
behavior:
snackbar
.
hitTestBehavior
??
HitTestBehavior
.
opaque
,
direction:
snackbar
.
dismissDirection
??
_getDefaultDismissDirection
(),
resizeDuration:
null
,
confirmDismiss:
(
_
)
{
...
...
@@ -382,10 +384,19 @@ class SnackBarQueue {
_snackbarList
.
clear
();
}
Future
<
void
>
disposeControllers
()
async
{
void
disposeControllers
()
{
if
(
_currentSnackbar
!=
null
)
{
_currentSnackbar
?.
_removeOverlay
();
_currentSnackbar
?.
_controller
.
dispose
();
_snackbarList
.
remove
(
_currentSnackbar
);
}
_queue
.
cancelAllJobs
();
for
(
var
element
in
_snackbarList
)
{
element
.
_controller
.
dispose
();
}
_snackbarList
.
clear
();
}
Future
<
void
>
closeCurrentJob
()
async
{
...
...
test/navigation/snackbar_test.dart
View file @
3a4dced
...
...
@@ -107,13 +107,15 @@ void main() {
});
testWidgets
(
"test snackbar dismissible"
,
(
tester
)
async
{
const
dismissDirection
=
DismissDirection
.
vertical
;
const
dismissDirection
=
DismissDirection
.
down
;
const
snackBarTapTarget
=
Key
(
'snackbar-tap-target'
);
const
GetSnackBar
getBar
=
GetSnackBar
(
key:
ValueKey
(
'dismissible'
),
message:
'bar1'
,
duration:
Duration
(
seconds:
2
),
isDismissible:
true
,
snackPosition:
SnackPosition
.
bottom
,
dismissDirection:
dismissDirection
,
);
...
...
@@ -149,14 +151,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, false);
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
.
byType
(
Dismissible
),
const
Offset
(
0.0
,
50.0
));
await
tester
.
pumpAndSettle
();
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
expect
(
Get
.
isSnackbarOpen
,
false
);
});
testWidgets
(
"test snackbar onTap"
,
(
tester
)
async
{
...
...
Please
register
or
login
to post a comment