Skip to content

Commit

Permalink
Add button to copy code link to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Wei committed Jul 7, 2019
1 parent 7bbc34a commit aa576c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/my_code_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:animated_floatactionbuttons/animated_floatactionbuttons.dart';
import 'package:clipboard_manager/clipboard_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart' as url_launcher;
Expand All @@ -12,6 +13,8 @@ class MyCodeView extends StatefulWidget {

MyCodeView({@required this.filePath});

String get githubPath => '$GITHUB_URL/blob/master/${this.filePath}';

@override
MyCodeViewState createState() {
return MyCodeViewState();
Expand Down Expand Up @@ -50,11 +53,20 @@ class MyCodeViewState extends State<MyCodeView> {

List<Widget> _buildFloatingButtons() {
return <Widget>[
FloatingActionButton(
child: Icon(Icons.content_copy),
tooltip: 'Copy code link to clipboard',
onPressed: () {
ClipboardManager.copyToClipBoard(this.widget.githubPath);
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Code link copied to Clipboard!'),
));
},
),
FloatingActionButton(
child: Icon(Icons.open_in_new),
tooltip: 'View the code on github',
onPressed: () => url_launcher
.launch('$GITHUB_URL/blob/master/${this.widget.filePath}'),
tooltip: 'View code on github',
onPressed: () => url_launcher.launch(this.widget.githubPath),
),
FloatingActionButton(
child: Icon(Icons.zoom_out),
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
flutter:
sdk: flutter
animated_floatactionbuttons: '0.1.0'
clipboard_manager: '0.0.4'
cloud_firestore: '0.12.6'
english_words: '3.1.5'
firebase_analytics: '3.0.3'
Expand Down

0 comments on commit aa576c0

Please sign in to comment.