I am trying to turn the URL into a function but there's an error. (ignore the formatting, I have extracted it out from my long writing code)
--My CustomElevatedButton function--
class CustomElevatedButton extends StatelessWidget {
final Color colors;
final String name;
final String education;
final String eventName;
final String clickEvent;
final String imageURl;
final String errorMessage;
final String information1;
final String information2;
final String information3;
**final Uri mylink;**
const CustomElevatedButton(
{Key? key,
required this.colors,
required this.name,
required this.education,
required this.eventName,
required this.clickEvent,
required this.imageURl,
required this.errorMessage,
required this.information1,
required this.information2,
required this.information3,
**required this.mylink**})
: super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
style: TextButton.styleFrom(backgroundColor: colors,),
child: Align(
alignment: Alignment.centerLeft,
child: RichText(
textAlign: TextAlign.justify,
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: education,
style: const TextStyle(color: Colors.black),
),
TextSpan(
text: name,
style:
const TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
),
],
),
),
),
onPressed: () {
sendAnalyticsEvent(
eventName: eventName,
clickevent: clickEvent
);
showModalBottomSheet(
isScrollControlled: true,
context: context,
shape: const RoundedRectangleBorder(
borderRadius: const BorderRadius.vertical(
top: Radius.circular(20),
)),
builder: (context) => Container(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.network(
imageURl,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return const CircularProgressIndicator();
},
errorBuilder: (context, error, stackTrace) =>
Text(errorMessage),
),
ListTile(
title: Text(
information1,
textAlign: TextAlign.justify,
),
),
ListTile(
title: Text(
information2,
textAlign: TextAlign.justify,
),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
width: double.infinity,
child: CupertinoButton.filled(
child: Text(information3),
**onPressed: () => openBrowserTab()**,
),
),
),
],
),
),
);
},
);
}
}
--My openBrowserTab--
openBrowserTab() async {
await FlutterWebBrowser.openWebPage(
url:
"https://stackoverflow.com",
customTabsOptions: CustomTabsOptions(
toolbarColor: Colors.lightBlueAccent,
));
}
--How I call CustomElevatedButton and display it as widget--
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.lightBlue,
title: Text("Diploma Programmes"),
),
body: new SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomElevatedButton(
clickEvent: 'User clicked dia',
colors: Colors.grey.shade200,
education: 'Diploma in Accounting | ',
errorMessage: 'Some errors occurred!',
eventName: 'DIA_taylors',
imageURl: 'https://i.imgur.com/uaHTJgF.png',
information1: '\nTaylor\u0027s Diploma in Accounting is the diploma of choice if you wish o pursue a career in accounting and obtain a globally recognised professional qualification. The Diploma in Accounting will give you a strong foundation in various accounting and related subjects. \n\nThe Diploma in Accounting aimes to produce entrepreneurs as well as para-accountants with the technical skills and the fundamental knowledge required in the current er, for an accounting career in the industry and commerce, both in the public and private sectors.\n',
information2: '• April and August Intake \n• Scholarships available',
information3: 'Interested? Get more info!',
name: 'Taylor\u0027s',
**mylink: 'https://stackoverflow,com',**
),
Can someone guide me on which part of my code is wrong? Is it supposed to be final string not final URI or final URI?
BOLD are the ones relevant to the function.