Hello i started to learn Flutter with AndroidStudio IDE. While i following a video to learn i change my code like in video. But there is diffrences and this diffrences getting me errors.
import 'package:flutterogrencitakip/models/student.dart';
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: HomeScreen());
}
}
class HomeScreen extends StatelessWidget {
List<Student> students = [
Student.withId(1, "Yusuf", "Erarslan", 95),
Student.withId(2, "Yusufff", "Erarslassn", 35),
Student.withId(3, "YusufffAAA", "ErAAAarslassn", 15)
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Öğrenci Takip Sistemi"),
),
body: buildBody());
}
Widget buildBody() {
return Column(
children:<Widget>[
Expanded(
child: ListView.builder(
itemCount: students.length,
itemBuilder: (BuildContext context, int index){
return Text(students[index].firstName);
}),
)
],
);
}
}
This code getting me error even i have student.dart in models folder. This is output.
lib/main.dart:40:42: Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
return Text(students[index].firstName);
is this because of im using return instead of throw or my void main class and class myApp classes are has wrong definition ? Because it was like that.
void main(){
const MyApp bla bla bla i can't remember exactly
}
Screenshots
My Project Folders:
My Problems:
Changed area by me:
My Student Class:
class Student{
int? id;
String? firstName;
String? lastName;
int? grade;
String? status;
(String firstName, String lastName, int grade){
this.firstName= firstName;
this.lastName= lastName;
this.grade = grade;
}
//named constructor
Student.withId(int id,String firstName, String lastName, int grade){
this.id=id;
this.firstName= firstName;
this.lastName= lastName;
this.grade = grade;
}
}