mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-25 20:16:05 +00:00
baabc0a915
* refactor(Theme): migrate accentColor - based on the specs at https://docs.flutter.dev/release/breaking-changes/theme-data-accent-properties#migration-guide. * refactor(Theme): all deprecated TextTheme styles * refactor(Theme): deprecated backgroundColor for colorScheme.background * refactor(Theme): deprecated buttonColor to use TextTheme backgroundColor instead * refactor(Theme): deprecated isAlwaysShown to use thumbVisibility instead
174 lines
5 KiB
Dart
174 lines
5 KiB
Dart
import 'package:cake_wallet/palette.dart';
|
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:cake_wallet/src/widgets/picker_wrapper_widget.dart';
|
|
|
|
class CheckBoxPicker extends StatefulWidget {
|
|
CheckBoxPicker({
|
|
required this.items,
|
|
required this.onChanged,
|
|
required this.title,
|
|
this.displayItem,
|
|
this.isSeparated = true,
|
|
});
|
|
|
|
final List<CheckBoxItem> items;
|
|
final String title;
|
|
final Widget Function(CheckBoxItem)? displayItem;
|
|
final bool isSeparated;
|
|
final Function(int, bool) onChanged;
|
|
|
|
@override
|
|
CheckBoxPickerState createState() => CheckBoxPickerState(items);
|
|
}
|
|
|
|
class CheckBoxPickerState extends State<CheckBoxPicker> {
|
|
CheckBoxPickerState(this.items);
|
|
|
|
final List<CheckBoxItem> items;
|
|
|
|
ScrollController controller = ScrollController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return PickerWrapperWidget(
|
|
children: [
|
|
if (widget.title.isNotEmpty)
|
|
Container(
|
|
padding: EdgeInsets.symmetric(horizontal: 24),
|
|
child: Text(
|
|
widget.title,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontFamily: 'Lato',
|
|
fontWeight: FontWeight.bold,
|
|
decoration: TextDecoration.none,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 24, right: 24, top: 24),
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.all(Radius.circular(30)),
|
|
child: Container(
|
|
color: Theme.of(context)
|
|
.accentTextTheme!
|
|
.titleLarge!
|
|
.color!,
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
maxHeight: MediaQuery.of(context).size.height * 0.65,
|
|
maxWidth: ResponsiveLayoutUtil.kPopupWidth,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Flexible(
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: <Widget>[
|
|
items.length > 3
|
|
? Scrollbar(
|
|
controller: controller,
|
|
child: itemsList(),
|
|
)
|
|
: itemsList(),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget itemsList() {
|
|
return Container(
|
|
color: Theme.of(context)
|
|
.accentTextTheme!
|
|
.titleLarge!
|
|
.backgroundColor!,
|
|
child: ListView.separated(
|
|
padding: EdgeInsets.zero,
|
|
controller: controller,
|
|
shrinkWrap: true,
|
|
separatorBuilder: (context, index) => widget.isSeparated
|
|
? Divider(
|
|
color: Theme.of(context)
|
|
.accentTextTheme!
|
|
.titleLarge!
|
|
.backgroundColor!,
|
|
height: 1,
|
|
)
|
|
: const SizedBox(),
|
|
itemCount: items == null || items.isEmpty ? 0 : items.length,
|
|
itemBuilder: (context, index) => buildItem(index),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildItem(int index) {
|
|
final item = items[index];
|
|
|
|
return GestureDetector(
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Container(
|
|
height: 55,
|
|
color: Theme.of(context)
|
|
.accentTextTheme!
|
|
.titleLarge!
|
|
.color!,
|
|
padding: EdgeInsets.only(left: 24, right: 24),
|
|
child: CheckboxListTile(
|
|
value: item.value,
|
|
activeColor: item.value
|
|
? Palette.blueCraiola
|
|
: Theme.of(context)
|
|
.accentTextTheme!
|
|
.titleMedium!
|
|
.decorationColor!,
|
|
checkColor: Colors.white,
|
|
title: widget.displayItem?.call(item) ??
|
|
Text(
|
|
item.title,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontFamily: 'Lato',
|
|
fontWeight: FontWeight.w600,
|
|
color: item.isDisabled
|
|
? Colors.grey.withOpacity(0.5)
|
|
: Theme.of(context).primaryTextTheme!.titleLarge!.color!,
|
|
decoration: TextDecoration.none,
|
|
),
|
|
),
|
|
onChanged: (bool? value) {
|
|
if (value == null) {
|
|
return;
|
|
}
|
|
|
|
item.value = value;
|
|
widget.onChanged(index, value);
|
|
setState(() {});
|
|
},
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CheckBoxItem {
|
|
CheckBoxItem(this.title, this.value, {this.isDisabled = false});
|
|
|
|
final String title;
|
|
final bool isDisabled;
|
|
bool value;
|
|
}
|