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
2020-07-01 03:08:26 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2020-07-01 03:08:26 -0300
Commit
1710394887cee8370b39ddceed8fe178b030e7fc
17103948
1 parent
d866dd01
Add files via upload
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
255 additions
and
163 deletions
CHANGELOG.md
lib/src/root/parse_route.dart
lib/src/root/root_widget.dart
lib/src/routes/custom_transition.dart
lib/src/routes/default_route.dart
lib/src/routes/default_transitions.dart
lib/src/routes/get_route.dart
lib/src/routes/transitions_component.dart
lib/src/routes/transitions_filter.dart
lib/src/routes/transitions_type.dart
lib/src/snackbar/snack.dart
lib/src/snackbar/snack_route.dart
pubspec.yaml
test/get_main_test.dart
test/routes_test.dart
CHANGELOG.md
View file @
1710394
## [3.1.3]
-
Activate unknownRoute on version 3
-
Go back transitions.size and transitions.cupertino
## [3.1.2]
-
Expose GetInstance
...
...
lib/src/root/parse_route.dart
View file @
1710394
import
'dart:collection'
;
import
'package:flutter/widgets.dart'
;
import
'package:get/src/routes/get_route.dart'
;
...
...
@@ -20,7 +22,7 @@ class ParseRouteTree {
// throw ("Default route was already defined");
// }
var
node
=
ParseRouteTreeNode
(
path
,
ParseRouteTreeNodeType
.
component
);
node
.
routes
=
[
route
]
;
node
.
routes
=
HashSet
<
GetPage
>()..
add
(
route
)
;
_nodes
.
add
(
node
);
// _hasDefaultRoute = true;
return
;
...
...
@@ -45,7 +47,7 @@ class ParseRouteTree {
}
if
(
i
==
pathComponents
.
length
-
1
)
{
if
(
node
.
routes
==
null
)
{
node
.
routes
=
[
route
]
;
node
.
routes
=
HashSet
<
GetPage
>()..
add
(
route
)
;
}
else
{
node
.
routes
.
add
(
route
);
}
...
...
@@ -131,8 +133,8 @@ class ParseRouteTree {
if
(
nodeToUse
!=
null
&&
nodeToUse
.
routes
!=
null
&&
nodeToUse
.
routes
.
length
>
0
)
{
List
<
GetPage
>
routes
=
nodeToUse
.
routes
;
GetPageMatch
routeMatch
=
GetPageMatch
(
routes
[
0
]);
HashSet
<
GetPage
>
routes
=
nodeToUse
.
routes
;
GetPageMatch
routeMatch
=
GetPageMatch
(
routes
.
first
);
routeMatch
.
parameters
=
match
.
parameters
;
...
...
@@ -201,7 +203,7 @@ class ParseRouteTreeNode {
String
part
;
ParseRouteTreeNodeType
type
;
List
<
GetPage
>
routes
=
<
GetPage
>[]
;
HashSet
<
GetPage
>
routes
=
HashSet
<
GetPage
>()
;
List
<
ParseRouteTreeNode
>
nodes
=
<
ParseRouteTreeNode
>[];
ParseRouteTreeNode
parent
;
...
...
lib/src/root/root_widget.dart
View file @
1710394
...
...
@@ -43,6 +43,7 @@ class GetMaterialApp extends StatelessWidget {
this
.
shortcuts
,
this
.
smartManagement
=
SmartManagement
.
full
,
this
.
initialBinding
,
this
.
unknownRoute
,
this
.
routingCallback
,
this
.
defaultTransition
,
// this.actions,
...
...
@@ -106,11 +107,30 @@ class GetMaterialApp extends StatelessWidget {
final
Duration
transitionDuration
;
final
bool
defaultGlobalState
;
final
List
<
GetPage
>
getPages
;
final
GetPage
unknownRoute
;
Route
<
dynamic
>
generator
(
RouteSettings
settings
)
{
final
match
=
Get
.
routeTree
.
matchRoute
(
settings
.
name
);
Get
.
parameters
=
match
?.
parameters
;
if
(
match
?.
route
==
null
)
{
return
GetPageRoute
(
page:
unknownRoute
.
page
,
parameter:
unknownRoute
.
parameter
,
settings:
RouteSettings
(
name:
settings
.
name
,
arguments:
settings
.
arguments
),
curve:
unknownRoute
.
curve
,
opaque:
unknownRoute
.
opaque
,
customTransition:
match
.
route
.
customTransition
,
binding:
unknownRoute
.
binding
,
bindings:
unknownRoute
.
bindings
,
duration:
(
transitionDuration
??
unknownRoute
.
transitionDuration
),
transition:
unknownRoute
.
transition
,
popGesture:
unknownRoute
.
popGesture
,
fullscreenDialog:
unknownRoute
.
fullscreenDialog
,
);
}
return
GetPageRoute
(
page:
match
.
route
.
page
,
parameter:
match
.
route
.
parameter
,
...
...
@@ -118,6 +138,7 @@ class GetMaterialApp extends StatelessWidget {
RouteSettings
(
name:
settings
.
name
,
arguments:
settings
.
arguments
),
curve:
match
.
route
.
curve
,
opaque:
match
.
route
.
opaque
,
customTransition:
match
.
route
.
customTransition
,
binding:
match
.
route
.
binding
,
bindings:
match
.
route
.
bindings
,
duration:
(
transitionDuration
??
match
.
route
.
transitionDuration
),
...
...
lib/src/routes/custom_transition.dart
View file @
1710394
...
...
@@ -3,6 +3,8 @@ import 'package:flutter/widgets.dart';
abstract
class
CustomTransition
{
Widget
buildTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
,
...
...
lib/src/routes/default_route.dart
View file @
1710394
...
...
@@ -16,6 +16,7 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
final
bool
popGesture
;
final
Transition
transition
;
final
Curve
curve
;
final
Alignment
alignment
;
final
GetPageBuilder
page
;
final
CustomTransition
customTransition
;
final
Bindings
binding
;
...
...
@@ -32,8 +33,9 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
this
.
bindings
,
this
.
opaque
=
true
,
this
.
parameter
,
this
.
alignment
,
this
.
fullscreenDialog
=
false
,
this
.
curve
,
this
.
curve
=
Curves
.
linear
,
this
.
popGesture
,
this
.
customTransition
,
})
:
super
(
...
...
@@ -64,6 +66,8 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
if
(
this
.
customTransition
!=
null
)
{
return
this
.
customTransition
.
buildTransition
(
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
popGesture
??
Get
.
defaultPopGesture
...
...
@@ -82,6 +86,8 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
if
(
Get
.
customTransition
!=
null
)
{
return
Get
.
customTransition
.
buildTransition
(
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
popGesture
??
Get
.
defaultPopGesture
...
...
@@ -96,6 +102,8 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
return
TransitionFilter
.
newTransitionComponent
(
Get
.
defaultTransition
)
.
buildChildWithTransition
(
context
,
curve
,
alignment
,
curvedAnimation
,
secondaryAnimation
,
popGesture
??
Get
.
defaultPopGesture
...
...
@@ -122,6 +130,8 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
return
TransitionFilter
.
newTransitionComponent
(
transition
)
.
buildChildWithTransition
(
context
,
curve
,
alignment
,
curvedAnimation
,
secondaryAnimation
,
popGesture
??
Get
.
defaultPopGesture
...
...
@@ -134,7 +144,7 @@ class GetPageRoute<T> extends PageRouteBuilder<T> {
@override
Duration
get
transitionDuration
=>
this
.
duration
??
Duration
(
milliseconds:
3
00
);
this
.
duration
??
Duration
(
milliseconds:
4
00
);
static
bool
_isPopGestureEnabled
<
T
>(
PageRoute
<
T
>
route
)
{
if
(
route
.
isFirst
)
return
false
;
...
...
lib/src/routes/default_transitions.dart
View file @
1710394
...
...
@@ -10,6 +10,8 @@ class LeftToRightFadeTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
...
...
@@ -39,6 +41,8 @@ class RightToLeftFadeTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
...
...
@@ -68,11 +72,13 @@ class NoTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
return
transitionComponent
.
buildChildWithTransition
(
context
,
animation
,
secondaryAnimation
,
child
);
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
child
);
}
}
...
...
@@ -84,13 +90,15 @@ class FadeInTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
return
FadeTransition
(
opacity:
animation
,
child:
transitionComponent
.
buildChildWithTransition
(
context
,
animation
,
secondaryAnimation
,
child
),
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
child
),
);
}
}
...
...
@@ -103,6 +111,8 @@ class SlideDownTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
...
...
@@ -112,7 +122,7 @@ class SlideDownTransition extends TransitionInterface {
end:
Offset
.
zero
,
).
animate
(
animation
),
child:
transitionComponent
.
buildChildWithTransition
(
context
,
animation
,
secondaryAnimation
,
child
),
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
child
),
);
}
}
...
...
@@ -125,6 +135,8 @@ class SlideLeftTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
...
...
@@ -134,7 +146,7 @@ class SlideLeftTransition extends TransitionInterface {
end:
Offset
.
zero
,
).
animate
(
animation
),
child:
transitionComponent
.
buildChildWithTransition
(
context
,
animation
,
secondaryAnimation
,
child
),
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
child
),
);
}
}
...
...
@@ -147,6 +159,8 @@ class SlideRightTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
...
...
@@ -156,7 +170,7 @@ class SlideRightTransition extends TransitionInterface {
end:
Offset
.
zero
,
).
animate
(
animation
),
child:
transitionComponent
.
buildChildWithTransition
(
context
,
animation
,
secondaryAnimation
,
child
),
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
child
),
);
}
}
...
...
@@ -169,6 +183,8 @@ class SlideTopTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
...
...
@@ -178,7 +194,7 @@ class SlideTopTransition extends TransitionInterface {
end:
Offset
.
zero
,
).
animate
(
animation
),
child:
transitionComponent
.
buildChildWithTransition
(
context
,
animation
,
secondaryAnimation
,
child
),
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
child
),
);
}
}
...
...
@@ -191,13 +207,63 @@ class ZoomInTransition extends TransitionInterface {
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
return
ScaleTransition
(
scale:
animation
,
child:
transitionComponent
.
buildChildWithTransition
(
context
,
animation
,
secondaryAnimation
,
child
),
context
,
curve
,
alignment
,
animation
,
secondaryAnimation
,
child
),
);
}
}
class
SizeTransitions
extends
TransitionInterface
{
SizeTransitions
({
TransitionComponent
transitionComponent
,
})
:
super
(
transitionComponent:
transitionComponent
);
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
return
Align
(
alignment:
Alignment
.
center
,
child:
SizeTransition
(
sizeFactor:
CurvedAnimation
(
parent:
animation
,
curve:
curve
,
),
child:
child
,
),
);
}
}
class
CupertinoTransitions
extends
TransitionInterface
{
CupertinoTransitions
({
TransitionComponent
transitionComponent
,
})
:
super
(
transitionComponent:
transitionComponent
);
@override
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
return
CupertinoPageTransition
(
primaryRouteAnimation:
animation
,
secondaryRouteAnimation:
secondaryAnimation
,
linearTransition:
true
,
child:
child
,
);
}
}
...
...
lib/src/routes/get_route.dart
View file @
1710394
import
'package:flutter/widgets.dart'
;
import
'package:get/src/routes/bindings_interface.dart'
;
import
'custom_transition.dart'
;
import
'transitions_type.dart'
;
class
GetPage
{
...
...
@@ -15,7 +16,7 @@ class GetPage {
final
bool
opaque
;
final
Bindings
binding
;
final
List
<
Bindings
>
bindings
;
final
Widget
customTransition
;
final
CustomTransition
customTransition
;
final
Duration
transitionDuration
;
final
bool
fullscreenDialog
;
final
RouteSettings
settings
;
...
...
lib/src/routes/transitions_component.dart
View file @
1710394
...
...
@@ -3,6 +3,8 @@ import 'package:flutter/widgets.dart';
class
TransitionComponent
{
Widget
buildChildWithTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
...
...
lib/src/routes/transitions_filter.dart
View file @
1710394
...
...
@@ -33,6 +33,13 @@ class TransitionFilter {
case
Transition
.
leftToRightWithFade
:
return
LeftToRightFadeTransition
(
transitionComponent:
transitionComponent
);
case
Transition
.
cupertino
:
return
CupertinoTransitions
(
transitionComponent:
transitionComponent
);
case
Transition
.
size
:
return
SizeTransitions
(
transitionComponent:
transitionComponent
);
default
:
return
FadeInTransition
(
transitionComponent:
transitionComponent
);
}
...
...
lib/src/routes/transitions_type.dart
View file @
1710394
...
...
@@ -11,6 +11,8 @@ enum Transition {
leftToRightWithFade
,
zoom
,
noTransition
,
cupertino
,
size
,
native
}
...
...
lib/src/snackbar/snack.dart
View file @
1710394
...
...
@@ -3,7 +3,7 @@ import 'dart:ui';
import
'package:flutter/material.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:get/get.dart'
;
import
'snack_route.dart'
as
route
;
import
'snack_route.dart'
as
snack
route
;
typedef
void
SnackStatusCallback
(
SnackStatus
status
);
typedef
void
OnTap
(
GetBar
snack
);
...
...
@@ -209,11 +209,11 @@ class GetBar<T extends Object> extends StatefulWidget {
/// A [TextFormField] in case you want a simple user input. Every other widget is ignored if this is not null.
final
Form
userInputForm
;
route
.
SnackRoute
<
T
>
_snackRoute
;
snack
route
.
SnackRoute
<
T
>
_snackRoute
;
/// Show the snack. Kicks in [SnackStatus.IS_APPEARING] state followed by [SnackStatus.SHOWING]
Future
<
T
>
show
()
async
{
_snackRoute
=
route
.
showSnack
<
T
>(
_snackRoute
=
snack
route
.
showSnack
<
T
>(
snack:
this
,
)
as
SnackRoute
<
T
>;
return
await
Get
.
key
.
currentState
.
push
(
_snackRoute
);
...
...
lib/src/snackbar/snack_route.dart
View file @
1710394
import
'dart:async'
;
import
'dart:ui'
;
import
'snack.dart'
;
import
'package:flutter/material.dart'
;
import
'package:
flutter/scheduler
.dart'
;
import
'package:
get/src/snackbar/snack
.dart'
;
class
SnackRoute
<
T
>
extends
OverlayRoute
<
T
>
{
Animation
<
double
>
_filterBlurAnimation
;
Animation
<
Color
>
_filterColorAnimation
;
final
GetBar
snack
;
final
Builder
_builder
;
final
Completer
<
T
>
_transitionCompleter
=
Completer
<
T
>();
final
SnackStatusCallback
_onStatusChanged
;
Alignment
_initialAlignment
;
Alignment
_endAlignment
;
bool
_wasDismissedBySwipe
=
false
;
Timer
_timer
;
T
_result
;
SnackStatus
currentStatus
;
SnackRoute
({
@required
this
.
snack
,
RouteSettings
settings
,
})
:
super
(
settings:
settings
)
{
this
.
_builder
=
Builder
(
builder:
(
BuildContext
innerContext
)
{
return
GestureDetector
(
child:
snack
,
onTap:
snack
.
onTap
!=
null
?
()
{
snack
.
onTap
(
snack
);
}
:
null
,
);
});
})
:
_builder
=
Builder
(
builder:
(
BuildContext
innerContext
)
{
return
GestureDetector
(
child:
snack
,
onTap:
snack
.
onTap
!=
null
?
()
=>
snack
.
onTap
(
snack
)
:
null
,
);
}),
_onStatusChanged
=
snack
.
onStatusChanged
,
super
(
settings:
settings
)
{
_configureAlignment
(
this
.
snack
.
snackPosition
);
_onStatusChanged
=
snack
.
onStatusChanged
;
}
_configureAlignment
(
SnackPosition
snackPosition
)
{
void
_configureAlignment
(
SnackPosition
snackPosition
)
{
switch
(
snack
.
snackPosition
)
{
case
SnackPosition
.
TOP
:
{
...
...
@@ -44,51 +46,12 @@ class SnackRoute<T> extends OverlayRoute<T> {
}
}
GetBar
snack
;
Builder
_builder
;
Future
<
T
>
get
completed
=>
_transitionCompleter
.
future
;
final
Completer
<
T
>
_transitionCompleter
=
Completer
<
T
>();
SnackStatusCallback
_onStatusChanged
;
Alignment
_initialAlignment
;
Alignment
_endAlignment
;
bool
_wasDismissedBySwipe
=
false
;
Timer
_timer
;
bool
get
opaque
=>
false
;
@override
Iterable
<
OverlayEntry
>
createOverlayEntries
()
{
List
<
OverlayEntry
>
overlays
=
[];
if
(
snack
.
overlayBlur
>
0.0
)
{
overlays
.
add
(
OverlayEntry
(
builder:
(
BuildContext
context
)
{
return
GestureDetector
(
onTap:
snack
.
isDismissible
?
()
=>
snack
.
dismiss
()
:
null
,
child:
AnimatedBuilder
(
animation:
_filterBlurAnimation
,
builder:
(
context
,
child
)
{
return
BackdropFilter
(
filter:
ImageFilter
.
blur
(
sigmaX:
_filterBlurAnimation
.
value
,
sigmaY:
_filterBlurAnimation
.
value
),
child:
Container
(
constraints:
BoxConstraints
.
expand
(),
color:
_filterColorAnimation
.
value
,
),
);
},
),
);
},
maintainState:
false
,
opaque:
opaque
),
);
}
final
List
<
OverlayEntry
>
overlays
=
[];
overlays
.
add
(
OverlayEntry
(
...
...
@@ -96,9 +59,7 @@ class SnackRoute<T> extends OverlayRoute<T> {
final
Widget
annotatedChild
=
Semantics
(
child:
AlignTransition
(
alignment:
_animation
,
child:
snack
.
isDismissible
?
_getDismissibleSnack
(
_builder
)
:
_getSnack
(),
child:
_getSnack
(),
),
focused:
false
,
container:
true
,
...
...
@@ -116,33 +77,6 @@ class SnackRoute<T> extends OverlayRoute<T> {
/// This string is a workaround until Dismissible supports a returning item
String
dismissibleKeyGen
=
""
;
Widget
_getDismissibleSnack
(
Widget
child
)
{
return
Dismissible
(
direction:
_getDismissDirection
(),
resizeDuration:
null
,
confirmDismiss:
(
_
)
{
if
(
currentStatus
==
SnackStatus
.
IS_APPEARING
||
currentStatus
==
SnackStatus
.
IS_HIDING
)
{
return
Future
.
value
(
false
);
}
return
Future
.
value
(
true
);
},
key:
Key
(
dismissibleKeyGen
),
onDismissed:
(
_
)
{
dismissibleKeyGen
+=
"1"
;
_cancelTimer
();
_wasDismissedBySwipe
=
true
;
if
(
isCurrent
)
{
navigator
.
pop
();
}
else
{
navigator
.
removeRoute
(
this
);
}
},
child:
_getSnack
(),
);
}
Widget
_getSnack
()
{
return
Container
(
margin:
snack
.
margin
,
...
...
@@ -150,18 +84,6 @@ class SnackRoute<T> extends OverlayRoute<T> {
);
}
DismissDirection
_getDismissDirection
()
{
if
(
snack
.
dismissDirection
==
SnackDismissDirection
.
HORIZONTAL
)
{
return
DismissDirection
.
horizontal
;
}
else
{
if
(
snack
.
snackPosition
==
SnackPosition
.
TOP
)
{
return
DismissDirection
.
up
;
}
else
{
return
DismissDirection
.
down
;
}
}
}
@override
bool
get
finishedWhenPopped
=>
_controller
.
status
==
AnimationStatus
.
dismissed
;
...
...
@@ -210,6 +132,8 @@ class SnackRoute<T> extends OverlayRoute<T> {
}
Animation
<
double
>
createBlurFilterAnimation
()
{
if
(
snack
.
overlayBlur
==
null
)
return
null
;
return
Tween
(
begin:
0.0
,
end:
snack
.
overlayBlur
).
animate
(
CurvedAnimation
(
parent:
_controller
,
...
...
@@ -223,6 +147,8 @@ class SnackRoute<T> extends OverlayRoute<T> {
}
Animation
<
Color
>
createColorFilterAnimation
()
{
if
(
snack
.
overlayColor
==
null
)
return
null
;
return
ColorTween
(
begin:
Colors
.
transparent
,
end:
snack
.
overlayColor
)
.
animate
(
CurvedAnimation
(
...
...
@@ -236,9 +162,6 @@ class SnackRoute<T> extends OverlayRoute<T> {
);
}
T
_result
;
SnackStatus
currentStatus
;
//copy of `routes.dart`
void
_handleStatusChanged
(
AnimationStatus
status
)
{
switch
(
status
)
{
...
...
@@ -282,8 +205,6 @@ class SnackRoute<T> extends OverlayRoute<T> {
_controller
=
createAnimationController
();
assert
(
_controller
!=
null
,
'
$runtimeType
.createAnimationController() returned null.'
);
_filterBlurAnimation
=
createBlurFilterAnimation
();
_filterColorAnimation
=
createColorFilterAnimation
();
_animation
=
createAnimation
();
assert
(
_animation
!=
null
,
'
$runtimeType
.createAnimation() returned null.'
);
super
.
install
();
...
...
@@ -291,28 +212,17 @@ class SnackRoute<T> extends OverlayRoute<T> {
@override
TickerFuture
didPush
()
{
super
.
didPush
();
assert
(
_controller
!=
null
,
'
$runtimeType
.didPush called before calling install() or after calling dispose().'
);
assert
(!
_transitionCompleter
.
isCompleted
,
'Cannot reuse a
$runtimeType
after disposing it.'
);
_animation
.
addStatusListener
(
_handleStatusChanged
);
_configureTimer
();
super
.
didPush
();
return
_controller
.
forward
();
}
@override
void
didReplace
(
Route
<
dynamic
>
oldRoute
)
{
assert
(
_controller
!=
null
,
'
$runtimeType
.didReplace called before calling install() or after calling dispose().'
);
assert
(!
_transitionCompleter
.
isCompleted
,
'Cannot reuse a
$runtimeType
after disposing it.'
);
if
(
oldRoute
is
SnackRoute
)
_controller
.
value
=
oldRoute
.
_controller
.
value
;
_animation
.
addStatusListener
(
_handleStatusChanged
);
super
.
didReplace
(
oldRoute
);
}
@override
bool
didPop
(
T
result
)
{
assert
(
_controller
!=
null
,
'
$runtimeType
.didPop called before calling install() or after calling dispose().'
);
...
...
@@ -360,17 +270,6 @@ class SnackRoute<T> extends OverlayRoute<T> {
}
}
/// Whether this route can perform a transition to the given route.
/// Subclasses can override this method to restrict the set of routes they
/// need to coordinate transitions with.
bool
canTransitionTo
(
SnackRoute
<
dynamic
>
nextRoute
)
=>
true
;
/// Whether this route can perform a transition from the given route.
///
/// Subclasses can override this method to restrict the set of routes they
/// need to coordinate transitions with.
bool
canTransitionFrom
(
SnackRoute
<
dynamic
>
previousRoute
)
=>
true
;
@override
void
dispose
()
{
assert
(!
_transitionCompleter
.
isCompleted
,
...
...
@@ -388,10 +287,8 @@ class SnackRoute<T> extends OverlayRoute<T> {
}
SnackRoute
showSnack
<
T
>({
@required
GetBar
snack
})
{
assert
(
snack
!=
null
);
return
SnackRoute
<
T
>(
snack:
snack
,
settings:
RouteSettings
(
name:
"snackbar"
),
settings:
RouteSettings
(
name:
'snackbar'
),
);
}
...
...
pubspec.yaml
View file @
1710394
name
:
get
description
:
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
version
:
3.1.
2
version
:
3.1.
3
homepage
:
https://github.com/jonataslaw/get
environment
:
...
...
test/get_main_test.dart
View file @
1710394
...
...
@@ -4,6 +4,28 @@ import 'package:get/get.dart';
import
'util/wrapper.dart'
;
class
SizeTransitions
extends
CustomTransition
{
@override
Widget
buildTransition
(
BuildContext
context
,
Curve
curve
,
Alignment
alignment
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
Widget
child
)
{
return
Align
(
alignment:
Alignment
.
center
,
child:
SizeTransition
(
sizeFactor:
CurvedAnimation
(
parent:
animation
,
curve:
curve
,
),
child:
child
,
),
);
}
}
void
main
(
)
{
testWidgets
(
"Get.to smoke test"
,
(
tester
)
async
{
await
tester
.
pumpWidget
(
...
...
@@ -21,7 +43,10 @@ void main() {
GetMaterialApp
(
initialRoute:
'/'
,
getPages:
[
GetPage
(
page:
()
=>
FirstScreen
(),
name:
'/'
),
GetPage
(
page:
()
=>
FirstScreen
(),
name:
'/'
,
customTransition:
SizeTransitions
()),
GetPage
(
page:
()
=>
SecondScreen
(),
name:
'/second'
),
GetPage
(
page:
()
=>
ThirdScreen
(),
name:
'/third'
),
],
...
...
@@ -188,9 +213,17 @@ void main() {
WrapperNamed
(
initialRoute:
'/'
,
namedRoutes:
[
GetPage
(
page:
()
=>
Container
(),
name:
'/'
),
GetPage
(
page:
()
=>
FirstScreen
(),
name:
'/first'
),
GetPage
(
page:
()
=>
SecondScreen
(),
name:
'/second'
),
GetPage
(
page:
()
=>
Container
(),
name:
'/'
,
popGesture:
true
,
transition:
Transition
.
cupertino
),
GetPage
(
page:
()
=>
FirstScreen
(),
name:
'/first'
,
transition:
Transition
.
size
),
GetPage
(
page:
()
=>
SecondScreen
(),
name:
'/second'
,
transition:
null
),
GetPage
(
page:
()
=>
ThirdScreen
(),
name:
'/third'
),
],
),
...
...
@@ -324,16 +357,42 @@ void main() {
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
FirstScreen
),
findsOneWidget
);
await
tester
.
pumpWidget
(
Wrapper
(
child:
Container
(),
defaultTransition:
Transition
.
cupertino
,
),
);
Get
.
to
(
FirstScreen
());
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
FirstScreen
),
findsOneWidget
);
await
tester
.
pumpWidget
(
Wrapper
(
child:
Container
(),
defaultTransition:
Transition
.
size
,
),
);
Get
.
to
(
FirstScreen
());
await
tester
.
pumpAndSettle
();
expect
(
find
.
byType
(
FirstScreen
),
findsOneWidget
);
});
testWidgets
(
"Get.snackbar test"
,
(
tester
)
async
{
await
tester
.
pumpWidget
(
Wrapper
(
child:
RaisedButton
(
GetMaterialApp
(
popGesture:
true
,
home:
RaisedButton
(
child:
Text
(
'Open Snackbar'
),
onPressed:
()
{
Get
.
snackbar
(
'title'
,
"message"
,
duration:
Duration
(
seconds:
1
),
instantInit:
true
);
Get
.
snackbar
(
'title'
,
"message"
,
duration:
Duration
(
seconds:
1
));
},
),
),
...
...
@@ -353,10 +412,20 @@ void main() {
child:
Text
(
'Open Snackbar'
),
onPressed:
()
{
Get
.
rawSnackbar
(
title:
'title'
,
message:
"message"
,
duration:
Duration
(
seconds:
1
),
instantInit:
true
);
title:
'title'
,
message:
"message"
,
onTap:
(
_
)
{
print
(
'snackbar tapped'
);
},
duration:
Duration
(
seconds:
1
),
shouldIconPulse:
true
,
icon:
Icon
(
Icons
.
alarm
),
showProgressIndicator:
true
,
barBlur:
null
,
isDismissible:
true
,
leftBarIndicatorColor:
Colors
.
amber
,
overlayBlur:
1.0
,
);
},
),
),
...
...
test/routes_test.dart
View file @
1710394
...
...
@@ -14,6 +14,15 @@ void main() {
"GetRoute maintainState null"
,
(
WidgetTester
testr
)
async
{
expect
(
()
=>
GetPage
(
page:
()
=>
Scaffold
(),
maintainState:
null
,
name:
'/'
),
throwsAssertionError
);
},
);
testWidgets
(
"GetRoute name null"
,
(
WidgetTester
testr
)
async
{
expect
(
()
=>
GetPage
(
page:
()
=>
Scaffold
(),
maintainState:
null
,
name:
null
),
throwsAssertionError
);
...
...
@@ -25,7 +34,7 @@ void main() {
(
WidgetTester
testr
)
async
{
expect
(
()
=>
GetPage
(
page:
()
=>
Scaffold
(),
fullscreenDialog:
null
,
name:
null
),
page:
()
=>
Scaffold
(),
fullscreenDialog:
null
,
name:
'/'
),
throwsAssertionError
);
},
);
...
...
Please
register
or
login
to post a comment