Flutter Viva QnA
Flutter Viva QnA
1
Future<String> fetchData() async {
return await Future.delayed(
Duration(seconds: 2),
() => "Data loaded"
);
}
11. What are keys in Flutter, and why are they important?
Ans) Keys help Flutter identify and preserve widget states when widgets
move or change order. They’re crucial for correctly handling lists, forms,
and animations.
12. Create a simple Flutter app that displays “Hello, World!” on
the screen.
Ans)
import ’package:flutter/material.dart’;
Column(
2
children: [
Text(’First’),
Text(’Second’),
Text(’Third’),
],
)
@override
Widget build(BuildContext context) {
return Column(
children: [
TextField(
onChanged: (value) {
setState(() {
textValue = value;
});
},
),
Text(textValue),
],
);
}
}
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey,
3
blurRadius: 5,
offset: Offset(2, 2)
),
],
gradient: LinearGradient(
colors: [Colors.blue, Colors.purple],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
width: 200,
height: 100,
)