raman raman
raman raman

Reputation: 1811

how can I add share feature to below dart code


import 'package:flutter/material.dart';

import 'package:share/share.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Stop addiction',
      theme: ThemeData(
        primarySwatch: Colors.teal,
      ),
      home: Scaffold(
        appBar: AppBar(backgroundColor:Colors.black,
          title: Text('stop addiction',style:TextStyle(color:Colors.red),),centerTitle: true,actions: <Widget>[
            IconButton(icon: Icon(Icons.share,color:Colors.white70,), onPressed:Share.share('check out my website https://example.com');)
          ],
        ),
        body: _blank()
      ),
    );
  }
}

Questions:

  1. How can I add share feature to above code
  2. When user will click on the icon share options should appear on the screen.

Upvotes: 0

Views: 43

Answers (1)

Doc
Doc

Reputation: 11651

The code should be

    IconButton(icon: Icon(Icons.share,color:Colors.white70,), onPressed:() => Share.share('check out my website https://example.com')/*semicolon removed here*/)

And, remove the semicolon

Upvotes: 1

Related Questions