I am reciving an error with my flutter app.
Here is the error
Error: No named parameter with the name 'child' in Flutter
The error is on line 51 and 62
Im trying to build an app in flutter. Im reciving an error when using child. Im trying to make an elevated button and some text but for both im reciving this error
Here is my code:
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Time Attack',
theme: ThemeData(
primarySwatch: Colors.red,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.red,
title: const Text('Time Attack'),
centerTitle: true,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
final player = AudioCache();
//player.play('musicForapp.mp3');
},
backgroundColor: Colors.red,
child: const Icon(Icons.punch_clock),
),
body: Column(
child: Container(
color: Colors.red,
child: const Text(
"Click the Icon in the bottem left to simulate an alarm",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
),
),
),
),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const TasksPage(),
),
);
}, //on pressed
child: const Text("Navigate"),
),
),
);
} //widget build
} //_MyHomePageState
class TasksPage extends StatefulWidget {
const TasksPage({super.key});
@override
State<TasksPage> createState() => _TasksPageState();
}
class _TasksPageState extends State<TasksPage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.red,
title: const Text('Tasks'),
centerTitle: true,
),
body: const Center(
child: Text(
"What is 2 x 2?",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
),
),
),
),
);
} //widget build
} //_TasksPageState
Why am I reciving this error?
CodePudding user response:
that is because Column
should have a children
, not a child. try this
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.red,
title: const Text('Time Attack'),
centerTitle: true,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
final player = AudioCache();
//player.play('musicForapp.mp3');
},
backgroundColor: Colors.red,
child: const Icon(Icons.punch_clock),
),
body: Column(
children: [
Container(
color: Colors.red,
child: const Text(
"Click the Icon in the bottem left to simulate an alarm",
style: TextStyle(
color: Colors.white,
fontSize: 30.0,
),
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const TasksPage(),
),
);
}, //on pressed
child: const Text("Navigate"),
)
],
),
),
);
} //widget build
} /