import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:sharesdk_plugin/sharesdk_plugin.dart'; import 'package:zhiying_base_widget/widgets/share/models/share_data_model.dart'; import 'package:zhiying_base_widget/widgets/share/models/share_plateform.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; class ShareAlert extends StatelessWidget { final Widget child; final ShareDataModel model; const ShareAlert(this.model, {Key key, this.child}) : super(key: key); // 中间视图 @override Widget build(BuildContext context) { return GestureDetector( child: Scaffold( backgroundColor: Colors.transparent, body: BackdropFilter( filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5), //背景 child: Container( child: Column( children: [ Expanded( child: Center(child: child ?? Container()), ), _ShareAlertContent(this.model), ], ), ), // 模糊化 ), ), onTap: () { Navigator.of(context).pop(); }, ); } } class _ShareAlertContent extends StatelessWidget { final ShareDataModel model; const _ShareAlertContent(this.model, {Key key}) : super(key: key); @override Widget build(BuildContext context) { return GestureDetector( onTap: () {}, child: Container( width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(12), topRight: Radius.circular(12), ), ), child: SafeArea( top: false, child: Column( children: [ Container( margin: EdgeInsets.only(top: 8, bottom: 8), width: 62, height: 4, decoration: BoxDecoration( color: Color(0xffd8d8d8), borderRadius: BorderRadius.circular(2)), ), Text( '分享至', style: TextStyle( fontSize: 15, color: Color(0xff333333), fontWeight: FontWeight.bold), ), Container( margin: EdgeInsets.only(left: 12, right: 12, top: 10, bottom: 10), child: _createIcons(), ), GestureDetector( child: Container( margin: EdgeInsets.only(left: 12, right: 12, bottom: 10), padding: EdgeInsets.all(12), decoration: BoxDecoration( color: Color(0xfff3f3f3), borderRadius: BorderRadius.circular(8)), child: Center( child: Text( '取消', style: TextStyle( fontSize: 12, fontWeight: FontWeight.bold, color: Color(0xff999999)), ), ), ), onTap: () { Navigator.of(context).pop(); }, ) ], ), ), ), ); } Widget _createIcons() { return Wrap( spacing: 10, runSpacing: 10, children: List.generate(6, (index) { return _createIcon(); }), ); } Widget _createIcon() { return GestureDetector( child: Container( width: 60, child: Column( children: [ Container( width: 40, height: 40, decoration: BoxDecoration( borderRadius: BorderRadius.circular(20), color: Colors.redAccent), ), Padding( padding: const EdgeInsets.only(top: 2, bottom: 2), child: Text( '分享平台', style: TextStyle( fontSize: 12, color: Color(0xff333333), fontWeight: FontWeight.bold), ), ), ], ), ), onTap: () { _shareByMob(SharePlateform.qq); }, ); } void _shareByMob(SharePlateform plateform) { //单独公共分享 SSDKMap params = SSDKMap() ..setGeneral( model.title, model.content, model.image, null, null, model.url, null, null, null, null, SSDKContentTypes.audio, ); ShareSDKPlatform p = ShareSDKPlatforms.wechatSession; switch (plateform) { case SharePlateform.wechatSession: p = ShareSDKPlatforms.wechatSession; break; case SharePlateform.wechatTimeline: p = ShareSDKPlatforms.wechatTimeline; break; case SharePlateform.qq: p = ShareSDKPlatforms.qq; break; case SharePlateform.qqZone: p = ShareSDKPlatforms.qZone; break; case SharePlateform.sina: p = ShareSDKPlatforms.sina; break; } SharesdkPlugin.share(p, params, (SSDKResponseState state, Map userdata, Map contentEntity, SSDKError error) { Logger.debug('${state}, ${error.rawData}'); }); } }