ive created a custom button that I use in multiple places in my flutter app. and I've also used the toast package to copy and show text anytime the button is clicked. the problem is i have to manually write out what text the button will copy every single time the button is clicked, this is my code.
code for button, the toast and also how i call the button.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:deciphernigeria/widgets/toastmessage.dart';
class InformationCard extends StatelessWidget {
final String toptitle;
final String bottomtext;
final String copiedtext;
const InformationCard({
Key key,
this.toptitle,
this.bottomtext,
this.copiedtext,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return InkWell(
onTap:
() {
showtoast();
Clipboard.setData(ClipboardData(text: copiedtext));
},
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
offset: Offset(0.0, 10.0),
blurRadius: 2.0,
spreadRadius: 0.0,
color: Color.fromRGBO(51, 51, 51, 0.16),
),
],
),
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(10, 15, 0, 15),
child: SvgPicture.asset(
'assets/icons/information.svg',
height: 30,
),
),
SizedBox(width: 20),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(0,10,30,0),
child: Text(
toptitle,
style: Theme.of(context).textTheme.subtitle2,
),
),
SizedBox(
height: 5,
),
Padding(
padding: const EdgeInsets.fromLTRB(0,0,30,10),
child: Text(bottomtext),
)
],
),
),
],
),
),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
void showtoast() => Fluttertoast.showToast(
msg: 'copied text to clipboard',
fontSize: 15,
backgroundColor: Colors.lightGreen,
);
InformationCard(
toptitle: 'the boy',
bottomtext: 'handsome',
copiedtext: 'handsome',
),
you can see when i call the button, i have to manually input the word handsome in the copied text so that handsome is copied when they click the button. i have to also manually write handsome in the bottom text so they know what they are clicking and copying. Please how can i do it that i don't need to manually rewrite the copied text before it is copied and also add some extra text to the copied word. for example since the top text is the boy and the bottom text is handsome, how do i code the button so that it will automatically copy the boy is tall and handsome when clicked without writing the bottom text? so i can use the button multiple times without rewriting. Thanks