Reputation: 13
Trying to learn Flutter and Dart for an upcoming project.. I have experience with Java and PHP but this is very new for me.. Help me out pls..
Getting error at line 53 and 56 in the code attached below where I have included stream.streamURL and stream.streamName .
main.dart
import 'package:flutter/material.dart';
import 'streamData.dart';
void main() => runApp(MaterialApp(
home: firstCard(),
));
class firstCard extends StatefulWidget {
@override
State<firstCard> createState() => _firstCardState();
}
class _firstCardState extends State<firstCard> {
List<Streams> streamData = [
Streams(streamName: "vishwesh", streamURL: "vishwesh.io"),
Streams(streamName: "vxshwxsh", streamURL: "vxshwxsh.io")
];
Widget streamTemplate(stream) {
return StreamCard(stream: stream);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[900],
appBar: AppBar(
title: Text('First Card'),
centerTitle: true,
backgroundColor: Colors.blueGrey[900],
elevation: 0.0,
),
body: Column(
children: streamData.map((result) => streamTemplate(result)).toList(),
));
}
}
class StreamCard extends StatelessWidget {
final Stream? stream;
StreamCard({this.stream});
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 16.0),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(stream?.streamURL,
style: TextStyle(fontSize: 20.0, color: Colors.grey[600])),
SizedBox(height: 6.0),
Text(stream.streamName,
style: TextStyle(fontSize: 14.0, color: Colors.grey[800]))
],
),
));
}
}
streamData.dart
class Streams {
String? streamName;
String? streamURL;
Streams({required this.streamName, required this.streamURL});
}
Upvotes: 1
Views: 2413
Reputation: 18
Change the final Stream? stream;
to final Streams? stream;
. You were not using the class that you created on a different file, instead you used an abstract class from Dart itself.
Upvotes: 0
Reputation: 812
Looking at your code, I think the error is due to a typo in your code:
class StreamCard extends StatelessWidget {
final Stream? stream;
You declared a variable of type Stream in StreamCard class, rename it to Streams instead.The final code would be:
class StreamCard extends StatelessWidget {
final Streams? stream;
Upvotes: 1