Flutter Tutorial for Beginners #18 - Custom Classes

preview_player
Показать описание
----------------------------------------

🐱‍💻 🐱‍💻 Course Links:

🐱‍💻 🐱‍💻 Other Related Courses:

Рекомендации по теме
Комментарии
Автор

if u have Non-nullable instance field error
just add "?" like this.

String? text;
String? author;

ahjed
Автор

I found I had to add 'required' to the parameters in the quote.dart file:
Quote({ required this.text, required this.author });
Otherwise I was getting an error : "can't have a value of 'null' because of its type."

IRDazza
Автор

If you are having a problem with creating the String fields, you have two choices:
1. Instead of "String quote" use "late String quote" or
2. Instead of "String quote" use "String? quote"

yahyafati
Автор

"This is the qite text" - Oscar Wilde

Samir-jyxp
Автор

Quote(author: 'Oscar Wilde', text: 'Be yourself; everyone else is already taken'),
Quote(author: 'Oscar Wilde', text: 'I have nothing to declare except my genius'),
Quote(author: 'Oscar Wilde', text: 'The truth is rarely pure and never simple')

techchak
Автор

solution for new flutter version:


quote.dart

class Quote {

String? text;
String? author;

// normal constructor, as we've already seen

// Quote(String author, String text){
// this.text = text;
// this.author = author;
// }

// constructor with named parameters

// Quote({ String author, String text }){
// this.text = text;
// this.author = author;
// }

// constructor with named parameters
// & automatically assigns named arguments to class properties

Quote({ required this.text, required this.author });

}


main.dart

import
import 'quote.dart';

void main() {
runApp(MaterialApp(
home: QuoteList(),
));
}

class QuoteList extends StatefulWidget {
const QuoteList({Key? key}) : super(key: key);

@override
_QuoteListState createState() => _QuoteListState();
}

class _QuoteListState extends State<QuoteList> {
List<Quote> quotes = [
Quote(author: 'Oscar Wilde', text: 'Be yourself; everyone else is already taken'),
Quote(author: 'Oscar Wilde', text: 'I have nothing to declare except my genius'),
Quote(author: 'Oscar Wilde', text: 'The truth is rarely pure and never simple')
];

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
appBar: AppBar(
title: Text('Shani Quote App'),
centerTitle: true,
backgroundColor: Colors.redAccent,
),
body: Column(
children: quotes.map((quote) => Text('${quote.text} - ${quote.author}')).toList(),
),
);
}
}

jashwanthgowda
Автор

You are awesome! This series is simply incredible. Easy to follow and good depth of content. Keep up the awesome work!

TheLyricalBrother
Автор

The way that you simplification these complex concepts is just awesome 🥰

mohamedsatti
Автор

What a great series! I am caught up and appreciate the breather, though I'm excited for more. :)

MojaveHigh
Автор

A nice feature of Dart is the sugar for the construter, you can do it like this:


class Quote {
String text;
String author;


Quote(this.text, this.author);
}

MrRoxx
Автор

Superb tutorial, Net Ninja! The best I found among the several I know! Many thanks!! Flutter rocks! 👍🏻😃

Magnetron
Автор

Gonna state the obvious here. You're an amazing teacher/content creator. Thank you for the quality content

lenzpaul
Автор

quote.dart needs required with the latest flutter/dart like so: Quote({required this.text, required this.author}) and an extra {} before the last }. I don't know why but it gave errors and this needed to be added. Have fun!

sphereintelligence
Автор

5:40 i stopped the video to comment and tell you man you are a live saver i never understood those named parameters just now thank you Sir

algeriennesaffaires
Автор

Man i really can't believe how simple you make everything look

abdullahmoiz
Автор

Thanks for this amazing series! Even I'm not an expert at coding, I'm now starting to really understand Flutter.

gabrieluca
Автор

Watching every video in this series! Great work, keep it up :)

ahmimo
Автор

Awesome job, thank you for your excellent teaching.

kosovarepublik
Автор

I was wondering is there anything i can use equal like in C# List<T> and this is nice to have, custom class and lists.

amnesia
Автор

Very very clear desciption; thanks very much for tutorials they're very cool

andreabollato