I’m new to flutter.
When I trying to build an app, an error showing as
[{
"resource": "/d:/Learn Fluter
Self/Flutter_Projects/Demo_App/flutter_application_1/lib/home.dart",
"owner": "_generated_diagnostic_collection_name_#1",
"code": {
"value": "extra_positional_arguments_could_be_named",
"target": {
"$mid": 1,
"path": "/diagnostics/extra_positional_arguments_could_be_named",
"scheme": "https",
"authority": "dart.dev"
}
},
"severity": 8,
"message": **"Too many positional arguments: 0 expected, but 1 found.nTry removing the extra positional arguments, or specifying the name for named arguments."**,
"source": "dart",
"startLineNumber": 25,
"startColumn": 7,
"endLineNumber": 38,
"endColumn": 8
}]
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar(),
body:
// Column(
// children: [
Center(
child: Padding(
padding: EdgeInsets.only(top: 10),
child: Text(
'CarVariants',
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold),
)),
),
GridView.count(
// Create a grid with 2 columns. If you change the scrollDirection to
// horizontal, this produces 2 rows.
crossAxisCount: 2,
// Generate 100 widgets that display their index in the List.
children: List.generate(100, (index) {
return Center(
child: Text(
'Item $index',
style: Theme.of(context).textTheme.headlineSmall,
),
);
}),
),
// Container(
// child: Image.asset('assets/images/sedan.png'),
// ),
// Container(
// child: Image.asset('assets/images/suv.png'),
// ),
// ],
// ),
);
}
AppBar appBar() {
return AppBar(
title: Text(
'CarBay',
style: TextStyle(
color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold),
),
backgroundColor: Color.fromARGB(255, 79, 218, 125),
elevation: 0.0,
centerTitle: true,
leading: Container(
margin: EdgeInsets.all(10),
alignment: Alignment.center,
child: SvgPicture.asset(
'assets/icons/backButton.svg',
height: 200,
width: 200,
),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(10)),
),
);
}
}
2
Answers
The problem is with your Scaffold and body. The body parameter only takes one child, and your body has a Center and a GridView widget. I see you have commented out your Column, but in your setup you will need the Column since it can take multiple children. That way the body will have one child, the Column. Try this:
why are you commenting body:Column and its Children[]??
also make sure to wrap GridView.count with a SizedBox and give sizedBox a height