You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PatientApp-KKUMC/lib/uitl/cupertino_picker.dart

88 lines
3.0 KiB
Dart

import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CupertinoPickerUtils{
int cupertinoPickerIndex = 0;
/// show Cupertino Picker for any list [context] the page BuildContext
/// [items] the list of items we need to show
/// [onSelectFun] the call function on select event
///The [isDismissible] parameter specifies whether the bottom sheet will be
/// dismissed when user taps on the scrim.
showCupertinoPicker(
{context, items, decKey, onSelectFun, bool isDismissible = false}) {
showModalBottomSheet(
isDismissible: isDismissible,
context: context,
builder: (BuildContext builder) {
return Container(
height: SizeConfig.realScreenHeight * 0.4,
color: Color(0xfff7f7f7),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
color: Color(0xfff7f7f7),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
CupertinoButton(
child: Text(TranslationBase.of(context).cancel,
style:
TextStyle(color: Theme.of(context).primaryColor)),
onPressed: () {
Navigator.pop(context);
},
),
CupertinoButton(
child: Text(
TranslationBase.of(context).done,
style: TextStyle(color: Theme.of(context).primaryColor),
),
onPressed: () {
Navigator.pop(context);
onSelectFun(cupertinoPickerIndex);
},
),
],
),
),
Container(
height: SizeConfig.realScreenHeight * 0.3,
color: Color(0xfff7f7f7),
child: buildPickerItems(context, items, decKey, onSelectFun))
],
),
);
},
);
}
/// build Cupertino Picker for any list
/// [context] the page BuildContext
/// [items] the list of items we need to show
/// [onSelectFun] the call function on select event
/// [decKey] the key we show for user
buildPickerItems(context, List items, decKey, onSelectFun) {
return CupertinoPicker(
magnification: 1.5,
scrollController:
FixedExtentScrollController(initialItem: cupertinoPickerIndex),
children: items.map((item) {
return Text(
'${item["$decKey"]}',
style: TextStyle(fontSize: SizeConfig.textMultiplier * 2),
);
}).toList(),
itemExtent: 25,
looping: true,
onSelectedItemChanged: (int index) {
cupertinoPickerIndex = index;
},
);
}
}