Files
tuiche/lib/pages/mh_page/homepage/component/citypicker.dart
2025-06-21 08:55:52 +08:00

105 lines
3.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_city_picker/listener/picker_listener.dart';
import 'package:flutter_city_picker/model/address.dart';
import 'package:flutter_city_picker/view/city_picker.dart';
class CityPicker {
/// 展示
static void show({
required BuildContext context,
AnimationController? animController,
double opacity = 0.5,
bool dismissible = true,
double height = 500.0,
double titleHeight = 50.0,
double corner = 20.0,
Color? backgroundColor,
double paddingLeft = 15.0,
Widget? titleWidget,
String? selectText,
Widget? closeWidget,
double tabHeight = 40.0,
bool showTabIndicator = true,
double tabPadding = 10.0,
Color? tabIndicatorColor,
double tabIndicatorHeight = 3.0,
double labelTextSize = 15.0,
Color? selectedLabelColor,
Color? unselectedLabelColor,
double itemHeadHeight = 30.0,
Color? itemHeadBackgroundColor,
Color? itemHeadLineColor,
double itemHeadLineHeight = 0.1,
TextStyle? itemHeadTextStyle,
double itemHeight = 40.0,
double indexBarWidth = 28,
double indexBarItemHeight = 20,
Color indexBarBackgroundColor = Colors.black12,
TextStyle? indexBarTextStyle,
Widget? itemSelectedIconWidget,
TextStyle? itemSelectedTextStyle,
TextStyle? itemUnSelectedTextStyle,
List<AddressNode>? initialAddress,
required CityPickerListener cityPickerListener,
}) {
showGeneralDialog(
context: context,
barrierColor: Colors.black.withOpacity(opacity),
barrierDismissible: dismissible,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 300),
pageBuilder: (context, animation, secondaryAnimation) {
return Align(
alignment: Alignment.bottomCenter,
child: Material(
color: Colors.transparent,
child: Container(
width: MediaQuery.of(context).size.width,
height: height,
decoration: BoxDecoration(
color: backgroundColor ?? Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(corner),
topRight: Radius.circular(corner),
),
),
child: CityPickerWidget(
height: height,
titleHeight: titleHeight,
corner: corner,
backgroundColor: backgroundColor,
paddingLeft: paddingLeft,
titleWidget: titleWidget,
selectText: selectText,
closeWidget: closeWidget,
tabHeight: tabHeight,
showTabIndicator: showTabIndicator,
tabPadding: tabPadding,
tabIndicatorColor: tabIndicatorColor,
tabIndicatorHeight: tabIndicatorHeight,
labelTextSize: labelTextSize,
selectedLabelColor: selectedLabelColor,
unselectedLabelColor: unselectedLabelColor,
itemHeadHeight: itemHeadHeight,
itemHeadBackgroundColor: itemHeadBackgroundColor,
itemHeadLineColor: itemHeadLineColor,
itemHeadLineHeight: itemHeadLineHeight,
itemHeadTextStyle: itemHeadTextStyle,
itemHeight: itemHeight,
indexBarWidth: indexBarWidth,
indexBarItemHeight: indexBarItemHeight,
indexBarBackgroundColor: indexBarBackgroundColor,
indexBarTextStyle: indexBarTextStyle,
itemSelectedIconWidget: itemSelectedIconWidget,
itemSelectedTextStyle: itemSelectedTextStyle,
itemUnSelectedTextStyle: itemUnSelectedTextStyle,
initialAddress: initialAddress,
cityPickerListener: cityPickerListener,
),
),
),
);
},
);
}
}