I did created a brand-new project just now and I encountered this problem.
I Can't Use Buttons because I can't Assign a function to them!
Here is my code:
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:url_launcher/url_launcher.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: const Align(
alignment: Alignment.center,
child: TextButton(onPressed: () {}, child: Text('LAUNCH'))), //PROBLEM IS HERE
);
}
Future<void> _launchUrl(String urlString) async {
if (await canLaunch(urlString)) {
await launch(
urlString,
forceWebView: true,
);
} else {
Fluttertoast.showToast(
msg: "Try Again",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}
}
}
As you can see I can't give () {}
to the onPressed
method of TextButton
. This is the root of my problem.
The Error that Flutter shows for this is:
Invalid constant value.
Also the packages I use:
dependencies:
fluttertoast: ^8.0.8
url_launcher: ^6.0.17
animated_splash_screen: ^1.1.0