Skip to content

Commit

Permalink
chore: support more number format
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed May 1, 2022
1 parent 5c4a681 commit cf05d7d
Show file tree
Hide file tree
Showing 8 changed files with 483 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flowy_sdk/log.dart';
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show Field;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -29,11 +30,12 @@ class FieldEditor extends FlowyOverlayDelegate {
BuildContext context, {
AnchorDirection anchorDirection = AnchorDirection.bottomWithLeftAligned,
}) {
Log.trace("Show $identifier()");
FlowyOverlay.of(context).remove(identifier());
FlowyOverlay.of(context).insertWithAnchor(
widget: OverlayContainer(
child: _FieldEditorWidget(_fieldEditorBloc, fieldContextLoader),
constraints: BoxConstraints.loose(const Size(220, 400)),
constraints: BoxConstraints.loose(const Size(280, 400)),
),
identifier: identifier(),
anchorContext: context,
Expand Down Expand Up @@ -68,7 +70,7 @@ class _FieldEditorWidget extends StatelessWidget {
child: BlocBuilder<FieldEditorBloc, FieldEditorState>(
builder: (context, state) {
return state.field.fold(
() => const SizedBox(width: 200),
() => const SizedBox(),
(field) => ListView(
shrinkWrap: true,
children: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class _FieldSwitcherState extends State<FieldSwitcher> {
FlowyOverlay.of(context).insertWithAnchor(
widget: OverlayContainer(
child: child,
constraints: BoxConstraints.loose(const Size(340, 400)),
constraints: BoxConstraints.loose(const Size(460, 440)),
),
identifier: identifier,
anchorContext: context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,23 @@ class NumberTypeOptionWidget extends TypeOptionWidget {
listener: (context, state) => dataDelegate.didUpdateTypeOptionData(state.typeOption.writeToBuffer()),
builder: (context, state) {
return FlowyButton(
text: FlowyText.medium(LocaleKeys.grid_field_numberFormat.tr(), fontSize: 12),
text: Row(
children: [
FlowyText.medium(LocaleKeys.grid_field_numberFormat.tr(), fontSize: 12),
// const HSpace(6),
const Spacer(),
FlowyText.regular(state.typeOption.format.title(), fontSize: 12),
],
),
padding: GridSize.typeOptionContentInsets,
hoverColor: theme.hover,
onTap: () {
final list = NumberFormatList(onSelected: (format) {
context.read<NumberTypeOptionBloc>().add(NumberTypeOptionEvent.didSelectFormat(format));
});
final list = NumberFormatList(
onSelected: (format) {
context.read<NumberTypeOptionBloc>().add(NumberTypeOptionEvent.didSelectFormat(format));
},
selectedFormat: state.typeOption.format,
);
overlayDelegate.showOverlay(context, list);
},
rightIcon: svgWidget("grid/more", color: theme.iconColor),
Expand All @@ -72,12 +82,14 @@ typedef _SelectNumberFormatCallback = Function(NumberFormat format);

class NumberFormatList extends StatelessWidget {
final _SelectNumberFormatCallback onSelected;
const NumberFormatList({required this.onSelected, Key? key}) : super(key: key);
final NumberFormat selectedFormat;
const NumberFormatList({required this.selectedFormat, required this.onSelected, Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final cells = NumberFormat.values.map((format) {
return NumberFormatCell(
isSelected: format == selectedFormat,
format: format,
onSelected: (format) {
onSelected(format);
Expand All @@ -86,7 +98,7 @@ class NumberFormatList extends StatelessWidget {
}).toList();

return SizedBox(
width: 120,
width: 180,
child: ListView.separated(
shrinkWrap: true,
controller: ScrollController(),
Expand All @@ -108,19 +120,30 @@ class NumberFormatList extends StatelessWidget {

class NumberFormatCell extends StatelessWidget {
final NumberFormat format;
final bool isSelected;
final Function(NumberFormat format) onSelected;
const NumberFormatCell({required this.format, required this.onSelected, Key? key}) : super(key: key);
const NumberFormatCell({
required this.isSelected,
required this.format,
required this.onSelected,
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = context.watch<AppTheme>();
Widget? checkmark;
if (isSelected) {
checkmark = svgWidget("grid/checkmark");
}

return SizedBox(
height: GridSize.typeOptionItemHeight,
child: FlowyButton(
text: FlowyText.medium(format.title(), fontSize: 12),
hoverColor: theme.hover,
onTap: () => onSelected(format),
leftIcon: svgWidget(format.iconName(), color: theme.iconColor),
rightIcon: checkmark,
),
);
}
Expand All @@ -129,31 +152,95 @@ class NumberFormatCell extends StatelessWidget {
extension NumberFormatExtension on NumberFormat {
String title() {
switch (this) {
case NumberFormat.CNY:
return "Yen";
case NumberFormat.ArgentinePeso:
return "Argentine peso";
case NumberFormat.Baht:
return "Baht";
case NumberFormat.CanadianDollar:
return "Canadian dollar";
case NumberFormat.ChileanPeso:
return "Chilean peso";
case NumberFormat.ColombianPeso:
return "Colombian peso";
case NumberFormat.DanishKrone:
return "Danish krone";
case NumberFormat.Dirham:
return "Dirham";
case NumberFormat.EUR:
return "Euro";
case NumberFormat.Forint:
return "Forint";
case NumberFormat.Franc:
return "Franc";
case NumberFormat.HongKongDollar:
return "Hone Kong dollar";
case NumberFormat.Koruna:
return "Koruna";
case NumberFormat.Krona:
return "Krona";
case NumberFormat.Leu:
return "Leu";
case NumberFormat.Lira:
return "Lira";
case NumberFormat.MexicanPeso:
return "Mexican Peso";
case NumberFormat.NewTaiwanDollar:
return "New Taiwan dollar";
case NumberFormat.NewZealandDollar:
return "New Zealand dollar";
case NumberFormat.NorwegianKrone:
return "Norwegian krone";
case NumberFormat.Number:
return "Numbers";
return "Number";
case NumberFormat.Percent:
return "Percent";
case NumberFormat.PhilippinePeso:
return "Percent";
case NumberFormat.Pound:
return "Pound";
case NumberFormat.Rand:
return "Rand";
case NumberFormat.Real:
return "Real";
case NumberFormat.Ringgit:
return "Ringgit";
case NumberFormat.Riyal:
return "Riyal";
case NumberFormat.Ruble:
return "Ruble";
case NumberFormat.Rupee:
return "Rupee";
case NumberFormat.Rupiah:
return "Rupiah";
case NumberFormat.Shekel:
return "Skekel";
case NumberFormat.USD:
return "US Dollar";
case NumberFormat.UruguayanPeso:
return "Uruguayan peso";
case NumberFormat.Won:
return "Uruguayan peso";
case NumberFormat.Yen:
return "Yen";
case NumberFormat.Yuan:
return "Yuan";
default:
throw UnimplementedError;
}
}

String iconName() {
switch (this) {
case NumberFormat.CNY:
return "grid/field/yen";
case NumberFormat.EUR:
return "grid/field/euro";
case NumberFormat.Number:
return "grid/field/numbers";
case NumberFormat.USD:
return "grid/field/us_dollar";
default:
throw UnimplementedError;
}
}
// String iconName() {
// switch (this) {
// case NumberFormat.CNY:
// return "grid/field/yen";
// case NumberFormat.EUR:
// return "grid/field/euro";
// case NumberFormat.Number:
// return "grid/field/numbers";
// case NumberFormat.USD:
// return "grid/field/us_dollar";
// default:
// throw UnimplementedError;
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,78 @@ import 'package:protobuf/protobuf.dart' as $pb;
class NumberFormat extends $pb.ProtobufEnum {
static const NumberFormat Number = NumberFormat._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Number');
static const NumberFormat USD = NumberFormat._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'USD');
static const NumberFormat CNY = NumberFormat._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CNY');
static const NumberFormat EUR = NumberFormat._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EUR');
static const NumberFormat CanadianDollar = NumberFormat._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CanadianDollar');
static const NumberFormat EUR = NumberFormat._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EUR');
static const NumberFormat Pound = NumberFormat._(5, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Pound');
static const NumberFormat Yen = NumberFormat._(6, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Yen');
static const NumberFormat Ruble = NumberFormat._(7, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Ruble');
static const NumberFormat Rupee = NumberFormat._(8, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Rupee');
static const NumberFormat Won = NumberFormat._(9, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Won');
static const NumberFormat Yuan = NumberFormat._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Yuan');
static const NumberFormat Real = NumberFormat._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Real');
static const NumberFormat Lira = NumberFormat._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Lira');
static const NumberFormat Rupiah = NumberFormat._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Rupiah');
static const NumberFormat Franc = NumberFormat._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Franc');
static const NumberFormat HongKongDollar = NumberFormat._(15, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'HongKongDollar');
static const NumberFormat NewZealandDollar = NumberFormat._(16, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NewZealandDollar');
static const NumberFormat Krona = NumberFormat._(17, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Krona');
static const NumberFormat NorwegianKrone = NumberFormat._(18, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NorwegianKrone');
static const NumberFormat MexicanPeso = NumberFormat._(19, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'MexicanPeso');
static const NumberFormat Rand = NumberFormat._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Rand');
static const NumberFormat NewTaiwanDollar = NumberFormat._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'NewTaiwanDollar');
static const NumberFormat DanishKrone = NumberFormat._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DanishKrone');
static const NumberFormat Baht = NumberFormat._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Baht');
static const NumberFormat Forint = NumberFormat._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Forint');
static const NumberFormat Koruna = NumberFormat._(25, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Koruna');
static const NumberFormat Shekel = NumberFormat._(26, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Shekel');
static const NumberFormat ChileanPeso = NumberFormat._(27, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ChileanPeso');
static const NumberFormat PhilippinePeso = NumberFormat._(28, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PhilippinePeso');
static const NumberFormat Dirham = NumberFormat._(29, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Dirham');
static const NumberFormat ColombianPeso = NumberFormat._(30, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ColombianPeso');
static const NumberFormat Riyal = NumberFormat._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Riyal');
static const NumberFormat Ringgit = NumberFormat._(32, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Ringgit');
static const NumberFormat Leu = NumberFormat._(33, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Leu');
static const NumberFormat ArgentinePeso = NumberFormat._(34, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ArgentinePeso');
static const NumberFormat UruguayanPeso = NumberFormat._(35, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UruguayanPeso');
static const NumberFormat Percent = NumberFormat._(36, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Percent');

static const $core.List<NumberFormat> values = <NumberFormat> [
Number,
USD,
CNY,
CanadianDollar,
EUR,
Pound,
Yen,
Ruble,
Rupee,
Won,
Yuan,
Real,
Lira,
Rupiah,
Franc,
HongKongDollar,
NewZealandDollar,
Krona,
NorwegianKrone,
MexicanPeso,
Rand,
NewTaiwanDollar,
DanishKrone,
Baht,
Forint,
Koruna,
Shekel,
ChileanPeso,
PhilippinePeso,
Dirham,
ColombianPeso,
Riyal,
Ringgit,
Leu,
ArgentinePeso,
UruguayanPeso,
Percent,
];

static final $core.Map<$core.int, NumberFormat> _byValue = $pb.ProtobufEnum.initByValue(values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,45 @@ const NumberFormat$json = const {
'2': const [
const {'1': 'Number', '2': 0},
const {'1': 'USD', '2': 1},
const {'1': 'CNY', '2': 2},
const {'1': 'EUR', '2': 3},
const {'1': 'CanadianDollar', '2': 2},
const {'1': 'EUR', '2': 4},
const {'1': 'Pound', '2': 5},
const {'1': 'Yen', '2': 6},
const {'1': 'Ruble', '2': 7},
const {'1': 'Rupee', '2': 8},
const {'1': 'Won', '2': 9},
const {'1': 'Yuan', '2': 10},
const {'1': 'Real', '2': 11},
const {'1': 'Lira', '2': 12},
const {'1': 'Rupiah', '2': 13},
const {'1': 'Franc', '2': 14},
const {'1': 'HongKongDollar', '2': 15},
const {'1': 'NewZealandDollar', '2': 16},
const {'1': 'Krona', '2': 17},
const {'1': 'NorwegianKrone', '2': 18},
const {'1': 'MexicanPeso', '2': 19},
const {'1': 'Rand', '2': 20},
const {'1': 'NewTaiwanDollar', '2': 21},
const {'1': 'DanishKrone', '2': 22},
const {'1': 'Baht', '2': 23},
const {'1': 'Forint', '2': 24},
const {'1': 'Koruna', '2': 25},
const {'1': 'Shekel', '2': 26},
const {'1': 'ChileanPeso', '2': 27},
const {'1': 'PhilippinePeso', '2': 28},
const {'1': 'Dirham', '2': 29},
const {'1': 'ColombianPeso', '2': 30},
const {'1': 'Riyal', '2': 31},
const {'1': 'Ringgit', '2': 32},
const {'1': 'Leu', '2': 33},
const {'1': 'ArgentinePeso', '2': 34},
const {'1': 'UruguayanPeso', '2': 35},
const {'1': 'Percent', '2': 36},
],
};

/// Descriptor for `NumberFormat`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List numberFormatDescriptor = $convert.base64Decode('CgxOdW1iZXJGb3JtYXQSCgoGTnVtYmVyEAASBwoDVVNEEAESBwoDQ05ZEAISBwoDRVVSEAM=');
final $typed_data.Uint8List numberFormatDescriptor = $convert.base64Decode('CgxOdW1iZXJGb3JtYXQSCgoGTnVtYmVyEAASBwoDVVNEEAESEgoOQ2FuYWRpYW5Eb2xsYXIQAhIHCgNFVVIQBBIJCgVQb3VuZBAFEgcKA1llbhAGEgkKBVJ1YmxlEAcSCQoFUnVwZWUQCBIHCgNXb24QCRIICgRZdWFuEAoSCAoEUmVhbBALEggKBExpcmEQDBIKCgZSdXBpYWgQDRIJCgVGcmFuYxAOEhIKDkhvbmdLb25nRG9sbGFyEA8SFAoQTmV3WmVhbGFuZERvbGxhchAQEgkKBUtyb25hEBESEgoOTm9yd2VnaWFuS3JvbmUQEhIPCgtNZXhpY2FuUGVzbxATEggKBFJhbmQQFBITCg9OZXdUYWl3YW5Eb2xsYXIQFRIPCgtEYW5pc2hLcm9uZRAWEggKBEJhaHQQFxIKCgZGb3JpbnQQGBIKCgZLb3J1bmEQGRIKCgZTaGVrZWwQGhIPCgtDaGlsZWFuUGVzbxAbEhIKDlBoaWxpcHBpbmVQZXNvEBwSCgoGRGlyaGFtEB0SEQoNQ29sb21iaWFuUGVzbxAeEgkKBVJpeWFsEB8SCwoHUmluZ2dpdBAgEgcKA0xldRAhEhEKDUFyZ2VudGluZVBlc28QIhIRCg1VcnVndWF5YW5QZXNvECMSCwoHUGVyY2VudBAk');
@$core.Deprecated('Use numberTypeOptionDescriptor instead')
const NumberTypeOption$json = const {
'1': 'NumberTypeOption',
Expand Down
Loading

0 comments on commit cf05d7d

Please sign in to comment.