@ -1,15 +1,20 @@
import ' dart:ui ' ;
import ' package:flutter/cupertino.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:cake_wallet/src/widgets/alert_background.dart ' ;
import ' package:cake_wallet/src/widgets/cake_scrollbar.dart ' ;
import ' package:cake_wallet/src/widgets/alert_close_button.dart ' ;
import ' package:cake_wallet/palette.dart ' ;
class Picker < Item extends Object > extends StatelessWidget {
class Picker < Item extends Object > extends State fu lWidget {
Picker ( {
@ required this . selectedAtIndex ,
@ required this . items ,
this . images ,
@ required this . title ,
@ required this . onItemSelected ,
this . mainAxisAlignment = MainAxisAlignment . start
this . mainAxisAlignment = MainAxisAlignment . start ,
this . isAlwaysShowScrollThumb = false
} ) ;
final int selectedAtIndex ;
@ -18,59 +23,87 @@ class Picker<Item extends Object> extends StatelessWidget {
final String title ;
final Function ( Item ) onItemSelected ;
final MainAxisAlignment mainAxisAlignment ;
final bool isAlwaysShowScrollThumb ;
@ override
PickerState createState ( ) = > PickerState < Item > ( items , images , onItemSelected ) ;
}
class PickerState < Item > extends State < Picker > {
PickerState ( this . items , this . images , this . onItemSelected ) ;
final Function ( Item ) onItemSelected ;
final List < Item > items ;
final List < Image > images ;
final closeButton = Image . asset ( ' assets/images/close.png ' ,
color: Palette . darkBlueCraiola ,
) ;
ScrollController controller = ScrollController ( ) ;
final double backgroundHeight = 193 ;
final double thumbHeight = 72 ;
double fromTop = 0 ;
@ override
Widget build ( BuildContext context ) {
return GestureDetector (
onTap: ( ) = > Navigator . of ( context ) . pop ( ) ,
child: Container (
color: Colors . transparent ,
child: BackdropFilter (
filter: ImageFilter . blur ( sigmaX: 3.0 , sigmaY: 3.0 ) ,
child: Container (
decoration: BoxDecoration ( color: PaletteDark . darkNightBlue . withOpacity ( 0.75 ) ) ,
child: Center (
child: Column (
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
Container (
padding: EdgeInsets . only ( left: 24 , right: 24 ) ,
child: Text (
title ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 18 ,
fontWeight: FontWeight . bold ,
decoration: TextDecoration . none ,
color: Colors . white
) ,
) ,
controller . addListener ( ( ) {
fromTop = controller . hasClients
? ( controller . offset / controller . position . maxScrollExtent * ( backgroundHeight - thumbHeight ) )
: 0 ;
setState ( ( ) { } ) ;
} ) ;
return AlertBackground (
child: Stack (
alignment: Alignment . center ,
children: < Widget > [
Column (
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
Container (
padding: EdgeInsets . only ( left: 24 , right: 24 ) ,
child: Text (
widget . title ,
textAlign: TextAlign . center ,
style: TextStyle (
fontSize: 18 ,
fontFamily: ' Poppins ' ,
fontWeight: FontWeight . bold ,
decoration: TextDecoration . none ,
color: Colors . white
) ,
Padding (
padding: EdgeInsets . only ( left: 24 , right: 24 , top: 24 ) ,
child: GestureDetector (
onTap: ( ) = > null ,
child: ClipRRect (
borderRadius: BorderRadius . all ( Radius . circular ( 14 ) ) ,
child: Container (
height: 233 ,
color: Theme . of ( context ) . accentTextTheme . title . backgroundColor ,
child: ListView . separated (
) ,
) ,
Padding (
padding: EdgeInsets . only ( left: 24 , right: 24 , top: 24 ) ,
child: GestureDetector (
onTap: ( ) = > null ,
child: ClipRRect (
borderRadius: BorderRadius . all ( Radius . circular ( 14 ) ) ,
child: Container (
height: 233 ,
color: Theme . of ( context ) . accentTextTheme . title . color ,
child: Stack (
alignment: Alignment . center ,
children: < Widget > [
ListView . separated (
controller: controller ,
separatorBuilder: ( context , index ) = > Divider (
color: Theme . of ( context ) . dividerColor ,
color: Theme . of ( context ) . accentTextTheme. title . background Color,
height: 1 ,
) ,
itemCount: items = = null ? 0 : items . length ,
itemBuilder: ( context , index ) {
final item = items [ index ] ;
final image = images ! = null ? images [ index ] : null ;
final isItemSelected = index = = selectedAtIndex;
final isItemSelected = index = = widget. selectedAtIndex;
final color = isItemSelected
? Theme . of ( context ) . accentTextTheme. subtitle . decorationC olor
: Colors. transparent ;
? Theme . of ( context ) . textTheme. body2 . c olor
: Theme. of ( context ) . accentTextTheme . title . color ;
final textColor = isItemSelected
? Colors. blue
? Palette. blueCraiola
: Theme . of ( context ) . primaryTextTheme . title . color ;
return GestureDetector (
@ -87,21 +120,22 @@ class Picker<Item extends Object> extends StatelessWidget {
color: color ,
child: Row (
mainAxisSize: MainAxisSize . max ,
mainAxisAlignment: mainAxisAlignment,
mainAxisAlignment: widget. mainAxisAlignment,
crossAxisAlignment: CrossAxisAlignment . center ,
children: < Widget > [
image ! = null
? image
: Offstage ( ) ,
? image
: Offstage ( ) ,
Padding (
padding: EdgeInsets . only (
left: image ! = null ? 12 : 0
left: image ! = null ? 12 : 0
) ,
child: Text (
item . toString ( ) ,
style: TextStyle (
fontSize: 18 ,
fontWeight: FontWeight . bold ,
fontFamily: ' Poppins ' ,
fontWeight: FontWeight . w600 ,
color: textColor ,
decoration: TextDecoration . none ,
) ,
@ -112,17 +146,25 @@ class Picker<Item extends Object> extends StatelessWidget {
) ,
) ;
} ,
) ,
widget . isAlwaysShowScrollThumb
? CakeScrollbar (
backgroundHeight: backgroundHeight ,
thumbHeight: thumbHeight ,
fromTop: fromTop
)
) ,
) ,
: Offstage ( ) ,
] ,
)
) ,
)
] ,
) ,
)
) ,
) ,
) ,
) ,
) ,
)
] ,
) ,
AlertCloseButton ( image: closeButton )
] ,
)
) ;
}
}
}