2020-01-04 19:31:52 +00:00
|
|
|
import 'dart:ui';
|
2020-08-25 18:12:14 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-08-25 18:12:14 +00:00
|
|
|
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';
|
2020-05-21 18:01:12 +00:00
|
|
|
import 'package:cake_wallet/palette.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-08-25 18:12:14 +00:00
|
|
|
class Picker<Item extends Object> extends StatefulWidget {
|
2020-05-21 18:01:12 +00:00
|
|
|
Picker({
|
|
|
|
@required this.selectedAtIndex,
|
|
|
|
@required this.items,
|
|
|
|
this.images,
|
|
|
|
@required this.title,
|
|
|
|
@required this.onItemSelected,
|
2020-08-25 18:12:14 +00:00
|
|
|
this.mainAxisAlignment = MainAxisAlignment.start,
|
|
|
|
this.isAlwaysShowScrollThumb = false
|
2020-05-21 18:01:12 +00:00
|
|
|
});
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
final int selectedAtIndex;
|
|
|
|
final List<Item> items;
|
2020-05-21 18:01:12 +00:00
|
|
|
final List<Image> images;
|
2020-01-08 12:26:34 +00:00
|
|
|
final String title;
|
|
|
|
final Function(Item) onItemSelected;
|
2020-05-21 18:01:12 +00:00
|
|
|
final MainAxisAlignment mainAxisAlignment;
|
2020-08-25 18:12:14 +00:00
|
|
|
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;
|
2020-01-08 12:26:34 +00:00
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-08-25 18:12:14 +00:00
|
|
|
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
|
2020-05-21 18:01:12 +00:00
|
|
|
),
|
2020-08-25 18:12:14 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
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,
|
2020-05-21 18:01:12 +00:00
|
|
|
separatorBuilder: (context, index) => Divider(
|
2020-08-25 18:12:14 +00:00
|
|
|
color: Theme.of(context).accentTextTheme.title.backgroundColor,
|
2020-05-21 18:01:12 +00:00
|
|
|
height: 1,
|
2020-01-04 19:31:52 +00:00
|
|
|
),
|
2020-05-21 18:01:12 +00:00
|
|
|
itemCount: items == null ? 0 : items.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final item = items[index];
|
|
|
|
final image = images != null? images[index] : null;
|
2020-08-25 18:12:14 +00:00
|
|
|
final isItemSelected = index == widget.selectedAtIndex;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-05-21 18:01:12 +00:00
|
|
|
final color = isItemSelected
|
2020-08-25 18:12:14 +00:00
|
|
|
? Theme.of(context).textTheme.body2.color
|
|
|
|
: Theme.of(context).accentTextTheme.title.color;
|
2020-05-21 18:01:12 +00:00
|
|
|
final textColor = isItemSelected
|
2020-08-25 18:12:14 +00:00
|
|
|
? Palette.blueCraiola
|
2020-05-29 15:10:11 +00:00
|
|
|
: Theme.of(context).primaryTextTheme.title.color;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-05-21 18:01:12 +00:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
if (onItemSelected == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
onItemSelected(item);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
height: 77,
|
|
|
|
padding: EdgeInsets.only(left: 24, right: 24),
|
|
|
|
color: color,
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
2020-08-25 18:12:14 +00:00
|
|
|
mainAxisAlignment: widget.mainAxisAlignment,
|
2020-05-21 18:01:12 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
image != null
|
2020-08-25 18:12:14 +00:00
|
|
|
? image
|
|
|
|
: Offstage(),
|
2020-05-21 18:01:12 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(
|
2020-08-25 18:12:14 +00:00
|
|
|
left: image != null ? 12 : 0
|
2020-05-21 18:01:12 +00:00
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
item.toString(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18,
|
2020-08-25 18:12:14 +00:00
|
|
|
fontFamily: 'Poppins',
|
|
|
|
fontWeight: FontWeight.w600,
|
2020-05-21 18:01:12 +00:00
|
|
|
color: textColor,
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2020-08-25 18:12:14 +00:00
|
|
|
),
|
|
|
|
widget.isAlwaysShowScrollThumb
|
|
|
|
? CakeScrollbar(
|
|
|
|
backgroundHeight: backgroundHeight,
|
|
|
|
thumbHeight: thumbHeight,
|
|
|
|
fromTop: fromTop
|
2020-05-21 18:01:12 +00:00
|
|
|
)
|
2020-08-25 18:12:14 +00:00
|
|
|
: Offstage(),
|
|
|
|
],
|
|
|
|
)
|
2020-05-21 18:01:12 +00:00
|
|
|
),
|
2020-08-25 18:12:14 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
AlertCloseButton(image: closeButton)
|
|
|
|
],
|
|
|
|
)
|
2020-01-04 19:31:52 +00:00
|
|
|
);
|
|
|
|
}
|
2020-08-25 18:12:14 +00:00
|
|
|
}
|