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
3 years ago
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f271b3dcc1c82dc8bfa5e7e9dbc26a8b839044c7
f271b3dc
1 parent
307effac
added Get.closeAllSnackbars, Get.closeCurrentSnackbar, fix tests
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
177 additions
and
122 deletions
example/lib/main.dart
lib/get_navigation/src/extension_navigation.dart
lib/get_navigation/src/snackbar/snackbar_controller.dart
lib/get_utils/src/queue/get_queue.dart
example/lib/main.dart
View file @
f271b3d
...
...
@@ -2,51 +2,28 @@ import 'package:flutter/foundation.dart';
import
'package:flutter/material.dart'
;
import
'package:get/get.dart'
;
import
'lang/translation_service.dart'
;
import
'routes/app_pages.dart'
;
import
'shared/logger/logger_utils.dart'
;
void
main
(
)
{
runApp
(
MyApp
());
}
// class MyApp extends StatelessWidget {
// const MyApp({Key? key}) : super(key: key);
// @override
// Widget build(BuildContext context) {
// return GetMaterialApp.router(
// debugShowCheckedModeBanner: false,
// enableLog: true,
// logWriterCallback: Logger.write,
// // initialRoute: AppPages.INITIAL,
// getPages: AppPages.routes,
// locale: TranslationService.locale,
// fallbackLocale: TranslationService.fallbackLocale,
// translations: TranslationService(),
// );
// }
// }
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
class
First
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'page one'
),
leading:
IconButton
(
icon:
Icon
(
Icons
.
more
),
onPressed:
()
async
{
var
controller
=
Get
.
snackbar
(
'dsdsds'
,
'sdsdsdsds'
);
},
),
),
body:
Center
(
child:
Container
(
height:
300
,
width:
300
,
child:
ElevatedButton
(
onPressed:
()
{},
child:
Text
(
'next screen'
),
),
),
),
return
GetMaterialApp
.
router
(
debugShowCheckedModeBanner:
false
,
enableLog:
true
,
logWriterCallback:
Logger
.
write
,
// initialRoute: AppPages.INITIAL,
getPages:
AppPages
.
routes
,
locale:
TranslationService
.
locale
,
fallbackLocale:
TranslationService
.
fallbackLocale
,
translations:
TranslationService
(),
);
}
}
...
...
@@ -56,68 +33,98 @@ class First extends StatelessWidget {
// runApp(MyApp());
// }
class
MyApp
extends
StatelessWidget
{
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
// class MyApp extends StatelessWidget {
// MyApp({Key? key}) : super(key: key);
@override
Widget
build
(
BuildContext
context
)
{
return
GetMaterialApp
.
router
(
getPages:
[
GetPage
(
participatesInRootNavigator:
true
,
name:
'/'
,
page:
()
=>
First
()),
GetPage
(
name:
'/second'
,
page:
()
=>
Second
(),
),
GetPage
(
name:
'/third'
,
page:
()
=>
Third
(),
),
],
debugShowCheckedModeBanner:
false
,
);
}
}
// @override
// Widget build(BuildContext context) {
// return GetMaterialApp.router(
// getPages: [
// GetPage(
// participatesInRootNavigator: true,
// name: '/first',
// page: () => First()),
// GetPage(
// name: '/second',
// page: () => Second(),
// ),
// GetPage(
// name: '/third',
// page: () => Third(),
// ),
// ],
// debugShowCheckedModeBanner: false,
// );
// }
// }
class
Second
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'page two
${Get.parameters["id"]}
'
),
),
body:
Center
(
child:
Container
(
height:
300
,
width:
300
,
child:
ElevatedButton
(
onPressed:
()
{},
child:
Text
(
'next screen'
),
),
),
),
);
}
}
// class First extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: Text('page one'),
// leading: IconButton(
// icon: Icon(Icons.more),
// onPressed: () {
// Get.changeTheme(
// context.isDarkMode ? ThemeData.light() : ThemeData.dark());
// },
// ),
// ),
// body: Center(
// child: Container(
// height: 300,
// width: 300,
// child: ElevatedButton(
// onPressed: () {},
// child: Text('next screen'),
// ),
// ),
// ),
// );
// }
// }
class
Third
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
backgroundColor:
Colors
.
red
,
appBar:
AppBar
(
title:
Text
(
'page three'
),
),
body:
Center
(
child:
Container
(
height:
300
,
width:
300
,
child:
ElevatedButton
(
onPressed:
()
{},
child:
Text
(
'go to first screen'
),
),
),
),
);
}
}
// class Second extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: Text('page two ${Get.parameters["id"]}'),
// ),
// body: Center(
// child: Container(
// height: 300,
// width: 300,
// child: ElevatedButton(
// onPressed: () {},
// child: Text('next screen'),
// ),
// ),
// ),
// );
// }
// }
// class Third extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// backgroundColor: Colors.red,
// appBar: AppBar(
// title: Text('page three'),
// ),
// body: Center(
// child: Container(
// height: 300,
// width: 300,
// child: ElevatedButton(
// onPressed: () {},
// child: Text('go to first screen'),
// ),
// ),
// ),
// );
// }
// }
...
...
lib/get_navigation/src/extension_navigation.dart
View file @
f271b3d
...
...
@@ -792,11 +792,11 @@ you can only use widgets and widget functions here''';
/// Returns true if a Snackbar, Dialog or BottomSheet is currently OPEN
bool
get
isOverlaysOpen
=>
(
isSnackbarOpen
!
||
isDialogOpen
!
||
isBottomSheetOpen
!);
(
isSnackbarOpen
||
isDialogOpen
!
||
isBottomSheetOpen
!);
/// Returns true if there is no Snackbar, Dialog or BottomSheet open
bool
get
isOverlaysClosed
=>
(!
isSnackbarOpen
!
&&
!
isDialogOpen
!
&&
!
isBottomSheetOpen
!);
(!
isSnackbarOpen
&&
!
isDialogOpen
!
&&
!
isBottomSheetOpen
!);
/// **Navigation.popUntil()** shortcut.<br><br>
///
...
...
@@ -817,8 +817,11 @@ you can only use widgets and widget functions here''';
int
?
id
,
})
{
if
(
closeOverlays
&&
isOverlaysOpen
)
{
if
(
isSnackbarOpen
)
{
closeAllSnackbars
();
}
navigator
?.
popUntil
((
route
)
{
return
(
isOverlaysClosed
);
return
(
!
isDialogOpen
!
&&
!
isBottomSheetOpen
!
);
});
}
if
(
canPop
)
{
...
...
@@ -1100,9 +1103,17 @@ you can only use widgets and widget functions here''';
/// give name from previous route
String
get
previousRoute
=>
routing
.
previous
;
///TODO: made snackbar 2.0 trackeables
/// check if snackbar is open
bool
?
get
isSnackbarOpen
=>
true
;
//routing.isSnackbar;
bool
get
isSnackbarOpen
=>
SnackbarController
.
isSnackbarBeingShown
;
//routing.isSnackbar;
void
closeAllSnackbars
()
{
SnackbarController
.
cancelAllSnackbars
();
}
void
closeCurrentSnackbar
()
{
SnackbarController
.
closeCurrentSnackbar
();
}
/// check if dialog is open
bool
?
get
isDialogOpen
=>
routing
.
isDialog
;
...
...
lib/get_navigation/src/snackbar/snackbar_controller.dart
View file @
f271b3d
...
...
@@ -6,7 +6,9 @@ import 'package:flutter/material.dart';
import
'../../../get.dart'
;
class
SnackbarController
{
static
final
_queue
=
GetQueue
();
static
final
_snackBarQueue
=
_SnackBarQueue
();
static
bool
get
isSnackbarBeingShown
=>
_snackBarQueue
.
isJobInProgress
;
late
Animation
<
double
>
_filterBlurAnimation
;
late
Animation
<
Color
?>
_filterColorAnimation
;
...
...
@@ -15,9 +17,10 @@ class SnackbarController {
late
SnackbarStatusCallback
?
_snackbarStatus
;
late
final
Alignment
?
_initialAlignment
;
late
final
Alignment
?
_endAlignment
;
bool
_wasDismissedBySwipe
=
false
;
bool
_onTappedDismiss
=
false
;
Timer
?
_timer
;
...
...
@@ -41,24 +44,22 @@ class SnackbarController {
Future
<
SnackbarController
>
get
future
=>
_transitionCompleter
.
future
;
bool
get
isSnackbarBeingShown
=>
_currentStatus
!=
SnackbarStatus
.
CLOSED
;
Future
<
void
>
close
()
async
{
_removeEntry
();
await
future
;
}
Future
<
void
>
show
()
{
return
_
queue
.
add
(
_show
);
return
_
snackBarQueue
.
addJob
(
this
);
}
// ignore: avoid_returning_this
void
_cancelTimer
()
{
if
(
_timer
!=
null
&&
_timer
!.
isActive
)
{
_timer
!.
cancel
();
}
}
// ignore: avoid_returning_this
void
_configureAlignment
(
SnackPosition
snackPosition
)
{
switch
(
snack
.
snackPosition
)
{
case
SnackPosition
.
TOP
:
...
...
@@ -289,8 +290,6 @@ class SnackbarController {
_removeEntry
();
}
void
_registerSnackbar
()
{}
void
_removeEntry
()
{
assert
(
!
_transitionCompleter
.
isCompleted
,
...
...
@@ -324,5 +323,39 @@ class SnackbarController {
return
future
;
}
void
_unRegisterSnackbar
()
{}
static
void
cancelAllSnackbars
()
{
_snackBarQueue
.
cancelAllJobs
();
}
static
void
closeCurrentSnackbar
()
{
_snackBarQueue
.
closeCurrentJob
();
}
}
class
_SnackBarQueue
{
final
_queue
=
GetQueue
();
bool
_isJobInProgress
=
false
;
SnackbarController
?
_currentSnackbar
;
bool
get
isJobInProgress
=>
_isJobInProgress
;
Future
<
void
>
addJob
(
SnackbarController
job
)
async
{
_isJobInProgress
=
true
;
_currentSnackbar
=
job
;
final
data
=
await
_queue
.
add
(
job
.
_show
);
_isJobInProgress
=
false
;
_currentSnackbar
=
null
;
return
data
;
}
void
cancelAllJobs
()
{
_currentSnackbar
?.
close
();
_queue
.
cancelAllJobs
();
}
void
closeCurrentJob
()
{
_currentSnackbar
?.
close
();
}
}
...
...
lib/get_utils/src/queue/get_queue.dart
View file @
f271b3d
...
...
@@ -4,8 +4,8 @@ class GetMicrotask {
int
_version
=
0
;
int
_microtask
=
0
;
int
get
version
=>
_version
;
int
get
microtask
=>
_microtask
;
int
get
version
=>
_version
;
void
exec
(
Function
callback
)
{
if
(
_microtask
==
_version
)
{
...
...
@@ -23,6 +23,17 @@ class GetQueue {
final
List
<
_Item
>
_queue
=
[];
bool
_active
=
false
;
Future
<
T
>
add
<
T
>(
Function
job
)
{
var
completer
=
Completer
<
T
>();
_queue
.
add
(
_Item
(
completer
,
job
));
_check
();
return
completer
.
future
;
}
void
cancelAllJobs
()
{
_queue
.
clear
();
}
void
_check
()
async
{
if
(!
_active
&&
_queue
.
isNotEmpty
)
{
_active
=
true
;
...
...
@@ -36,13 +47,6 @@ class GetQueue {
_check
();
}
}
Future
<
T
>
add
<
T
>(
Function
job
)
{
var
completer
=
Completer
<
T
>();
_queue
.
add
(
_Item
(
completer
,
job
));
_check
();
return
completer
.
future
;
}
}
class
_Item
{
...
...
Please
register
or
login
to post a comment