'Flutter Error: No named parameter with the name 'child'
I need help, when I run the code below in the android studio I get the following error: Error: No named parameter with the name 'child'
I have also posted below the error message generated by android studio.
I ran flutter upgrade, and now I am getting an error that says- [dart] The named parameter 'child' isn't defined. The project is newly created and the default code is untouched, but it still has the same Error:
import 'package:app_markeeting_and_promotion/models/home_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:device_apps/device_apps.dart';
import 'package:firebase_admob/firebase_admob.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class DownlaodsApp extends StatefulWidget {
@override
_DownlaodsAppState createState() => _DownlaodsAppState();
}
class _DownlaodsAppState extends State<DownlaodsApp> {
var stream = FirebaseFirestore.instance;
static const MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(keywords: ["Promotion","Kids","coins"]);
RewardedVideoAd rewardedVideoAd = RewardedVideoAd.instance;
int coins;
String appName;
@override
void initState() {
super.initState();
//"ca-app-pub-xxxxxxxxxxxx/5xxxxxxx75"
rewardedVideoAd.load(adUnitId: "ca-app-pub-xxxxxxxxxxxx/5xxxxxx5");
}
@override
Widget build(BuildContext context) {
final pro = Provider.of<HomeModel>(context);
return Scaffold(
appBar: AppBar(
title: Text("Download Apps"),
),
body: FutureBuilder(
future: stream.collection('apps').get(),
builder: (context,snapshot){
if(snapshot.hasData){
return ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (ctx,i){
final List<DocumentSnapshot> documents = snapshot.data.docs;
if(documents[i]['coins'] > 2){
return ListTile(
// subtitle: Text(documents[i]['userId']),
// ignore: deprecated_member_use
trailing: FlatButton(
color: Colors.green,
onPressed: ()async{
setState(() {
appName = documents[i]['link'];
});
await pro.downloadApp(documents[i]['link']);
showDialog(
context: context,
child: AlertDialog(
title: Text("Claim Your Coin"),
content: Text("its verify That you installed the app"),
actions: [
// ignore: deprecated_member_use
FlatButton(onPressed: ()async{
print(appName);
Navigator.pop(context);
bool installed = await DeviceApps.isAppInstalled(appName);
if(installed == true){
print("installed=====================================");
print(documents[i].id);
await rewardedVideoAd.show();
RewardedVideoAd.instance.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.rewarded) {
setState(() {
coins = rewardAmount;
});
}
};
print(coins);
final pro = Provider.of<HomeModel>(context,listen: false);
await pro.addDownload(documents[i].id, coins);
print("app called");
}else{
print(documents[i].id);
await rewardedVideoAd.show();
RewardedVideoAd.instance.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.rewarded) {
setState(() {
coins = rewardAmount;
});
}
};
print("Not Installed");
showDialog(
context: context,
child: AlertDialog(
content: Text("You Must installed the app to claim your coins",style: TextStyle(color: Colors.red,),),
title: Text("App Not Installed"),
actions: [
// ignore: deprecated_member_use
FlatButton(onPressed: (){Navigator.pop(context);}, child: Text("Okay"))
],
)
);
}
}, child: Text("Claim"))
],
)
);
},
child: Text("Download"),),
title: Text("https://play.google.com/store/apps/details?id=${documents[i]['link']}"),
);
}else{
return Container();
}
},
);
}else{
return Center(child: CircularProgressIndicator(),);
}
},
),
);
}
}
Below is the error code:
Launching lib\main.dart on sdk gphone x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
lib/views/downloads_apps.dart:92:36: Error: No named parameter with the name 'child'.
child: AlertDialog(
^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/dialog.dart:1035:12: Context: Found this candidate, but the arguments don't match.
Future<T?> showDialog<T>({
^^^^^^^^^^
lib/views/downloads_apps.dart:53:27: Error: No named parameter with the name 'child'.
child: AlertDialog(
^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/dialog.dart:1035:12: Context: Found this candidate, but the arguments don't match.
Future<T?> showDialog<T>({
^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 18s
Exception: Gradle task assembleDebug failed with exit code 1
Solution 1:[1]
Look's like you have mentioned "child" attribute in Alert/ShowDailog, Make sure your Alert And ShowDailog matches below code,
return showDialog(
context: context, // this context should be passed to Future Function as parameter
builder: (BuildContext cx) {
return AlertDialog(
content: Text("Alert"),
actions: [
FlatButton(
child: Text("Ok"),
onPressed: () {
Navigator.pop(cx);
}),
],
);
},
);
please provide your code sample to understand what your trying.
Solution 2:[2]
showDialog widget takes context and a builder. In builder, we provide the AlertDialog widget with title, content(Description of a title), and actions (Yes or no buttons)
In your code you have used child instead of builder that's why this error is arise, to fix it use a builder inside your showDialog
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text("Claim Your Coin"),
content: Text("its verify That you installed the app"),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(ctx).pop();
},
child: Text("Okay"),
),
],
),
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mrudul Addipalli |
| Solution 2 | Paresh Mangukiya |
