confirmButton method
It'll pop with AssetPickerProvider.selectedAssets when there are any assets were chosen. Then, the assets picker will pop too. 当有资源已选时,点击按钮将把已选资源通过路由返回。 资源选择器将识别并一同返回。
Implementation
@override
Widget confirmButton(BuildContext context) {
return ChangeNotifierProvider<
AssetPickerViewerProvider<AssetEntity>?>.value(
value: provider,
child: Consumer<AssetPickerViewerProvider<AssetEntity>?>(
builder: (_, AssetPickerViewerProvider<AssetEntity>? provider, __) {
assert(
isWeChatMoment || provider != null,
'Viewer provider must not be null'
'when the special type is not WeChat moment.',
);
return MaterialButton(
minWidth: () {
if (isWeChatMoment && hasVideo) {
return 48.0;
}
return provider!.isSelectedNotEmpty ? 48.0 : 20.0;
}(),
height: 32.0,
padding: const EdgeInsets.symmetric(horizontal: 12.0),
color: themeData.colorScheme.secondary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3.0),
),
child: Text(
() {
if (isWeChatMoment && hasVideo) {
return Constants.textDelegate.confirm;
}
if (provider!.isSelectedNotEmpty) {
return '${Constants.textDelegate.confirm}'
' (${provider.currentlySelectedAssets.length}'
'/'
'${selectorProvider!.maxAssets})';
}
return Constants.textDelegate.confirm;
}(),
style: TextStyle(
color: themeData.textTheme.bodyText1?.color,
fontSize: 17.0,
fontWeight: FontWeight.normal,
),
),
onPressed: () {
if (isWeChatMoment && hasVideo) {
Navigator.of(context).pop(<AssetEntity>[currentAsset]);
return;
}
if (provider!.isSelectedNotEmpty) {
Navigator.of(context).pop(provider.currentlySelectedAssets);
return;
}
selectAsset(currentAsset);
Navigator.of(context).pop(
selectedAssets ?? <AssetEntity>[currentAsset],
);
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
},
),
);
}