Flutter Hoow add通过电话应用共享此应用吗?

问题描述

嗨,我如何在我的应用程序中建立链接,如果用户单击它,则使用电子邮件whatsapp等打开此菜单,并且用户可以与我的Play商店链接共享给朋友?

解决方法

您可以使用share软件包。这是完整的代码:


import 'package:flutter/material.dart';
import 'package:share/share.dart';


void main() {
  runApp(DemoApp());
}

class DemoApp extends StatefulWidget {
  @override
  DemoAppState createState() => DemoAppState();
}

class DemoAppState extends State<DemoApp> {

  // Your own PlayStore or AppStore Link
  String appStoreLink = '<link of app store>';
  String subject = '<subject>';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Share Plugin Demo',home: Scaffold(
          appBar: AppBar(
            title: const Text('Share Plugin Demo'),),body: SingleChildScrollView(
            child: Padding(
              padding: const EdgeInsets.all(24.0),child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
               
                  const Padding(padding: EdgeInsets.only(top: 12.0)),Builder(
                    builder: (BuildContext context) {
                      return RaisedButton(
                        child: const Text('Share'),onPressed: () => _onShare(context),);
                    },],)),);
  }

  
  _onShare(BuildContext context) async {
  
    final RenderBox box = context.findRenderObject();
  
      await Share.share(appStoreLink,subject: subject,sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
    }
  
}