Flutter Coding Assessment 1
Flutter Coding Assessment 1
Candidate Name *
Avinash gupta
Coding section
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 1/11
4/22/25, 11:34 AM Flutter Coding Assessment
Question:
The following code throws an error at runtime. Identify and fix the error.
<Code>
class MyWidget extends StatelessWidget {
final title;
MyWidget(this.title);
@override
Widget build(BuildContext context) {
return Text(title);
}
}
</Code>
MyWidget({this.title});
@override
Widget build(BuildContext context) {
return Text(title ?? ""); //made changes
}
}
Since the title is not required means title can be null so fixed in above code
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 2/11
4/22/25, 11:34 AM Flutter Coding Assessment
Question:
The developer is trying to increment a counter when the button is clicked, but the UI is not
updating. What’s wrong?
<Code>
class CounterPage extends StatefulWidget {
@override
_CounterPageState createState() => _CounterPageState();
}
void incrementCounter() {
count++;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Text('Count: $count')),
floatingActionButton: FloatingActionButton(
onPressed: incrementCounter,
child: Icon(Icons.add),
),
);
}
}
</Code>
void incrementCounter() {
setState(){
count++;
}
}
Now it fix the error , sestate rebuild the widget and update the state see above code
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 3/11
4/22/25, 11:34 AM Flutter Coding Assessment
Question:
Create a Flutter screen that takes a list of strings and displays only the strings that start with a
specific letter, say 'A'. The filtered list should be shown in a ListView.
MyWidget(this.title);
filterList=filterList.nameOfMethod(name=>name).contains(searchQuery).tolist();
@override
Widget build(BuildContext context) {
return Sacffold(
body:
Flexible(
childer:[
FormTextField(
title:"Search here:",
onChange: (searchQuery){
Filter(searchQuery);
}
),
ListViewBuilder(){
itemcount:filterList.legth(),
(contenxt,index){
return Listtile(title:list[index]);
}
}
)
)
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 4/11
4/22/25, 11:34 AM Flutter Coding Assessment
}
}
</Code>
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 5/11
4/22/25, 11:34 AM Flutter Coding Assessment
Question:
Build a simple Flutter form with the following fields:
➡️Name (required)
➡️Email (must be a valid email)
➡️Age (must be numeric)
Add validation and show a success snackbar on form submission.
void FormValidation(){
if(formKey.currentstate.validate){
snackbar(titele:"form is not valid");
}else{
snackbar(titele:"Form submit successfully");
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Form(
key: formKey,
Column(
childeren[
TextFormField(
validator:
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 6/11
4/22/25, 11:34 AM Flutter Coding Assessment
onchange:(value){
if(value.isEmpty ){
return "$value can not be empty";
}
return;
),
TextFormField(
validator:
onchange:(value){
if(value.isEmpty ){
return "$value can not be empty";
}
return;
),
TextFormField(
validator:
onchange:(value){
if(value.isEmpty ){
return "$value can not be empty";
}
return;
),
floatingActionButton: FloatingActionButton(
onPressed: FormValidation,
child: Icon(Icons.add),
),
);
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 7/11
4/22/25, 11:34 AM Flutter Coding Assessment
}
}
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 8/11
4/22/25, 11:34 AM Flutter Coding Assessment
Question:
Create a screen that fetches a list of users from a public API (e.g.,
https://jsonplaceholder.typicode.com/users) and displays their names in a list. Show a loading
indicator while data is being fetched and handle API failure gracefully.
try{
if(response ==200){
return jsonDecode(response.body);
}else{
throw("Something went wrong $response.statuscode")
}
}
}catch(e){
throw(e)
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child:
FutureBuilder(
future: fetch(),
(context,snapshot){
if(snapshot.waiting){
return CircularIndicator()
}else{
final data = snapshot.data;
return ListviewBuilder(
itemcount:data .legth()
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pKw… 9/11
4/22/25, 11:34 AM Flutter Coding Assessment
context,index){
return Listtile(
title: data[index]['name']
)
}
}
)
),
);
}
}
Question:
What is the difference between Navigator.push and Navigator.pushReplacement? When would
you use each?
Navigator.push is used to push the user to screen on the top of the current screen while
Navigator.pushReplacement also push the screen but it replace the current screen with new screen
when we no need of the current screen use Navigator.pushReplacement and when we need the screen
like we need come back just after that use Navigator.push
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pK… 10/11
4/22/25, 11:34 AM Flutter Coding Assessment
Question:
The below animation doesn’t work as expected. Fix the issue and describe what was wrong.
<Code>
class FadeInWidget extends StatefulWidget {
@override
_FadeInWidgetState createState() => _FadeInWidgetState();
}
@override
void initState() {
super.initState();
_controller = AnimationController(vsync: this, duration: Duration(seconds: 2));
_animation = Tween(begin: 0.0, end: 1.0).animate(_controller);
}
@override
Widget build(BuildContext context) {
return FadeTransition(
opacity: _animation,
child: Text('Hello!'),
);
}
}
</Code>
Forms
https://docs.google.com/forms/d/1W6MqY3-48hjifAOg5JaPNekiGH59f7f97nz4AGlIFu0/edit#response=ACYDBNgahtmAB7UHG_Hz-D_y071pK… 11/11