import 'package:flutter/material.dart';
class VariableDemoScreen extends StatelessWidget {
const VariableDemoScreen({super.key});
@override
Widget build(BuildContext context) {
int explicitNumber = 42;
var inferredString = 'Hello';
return Scaffold(
appBar: AppBar(
title: const Text('Variable Demo Screen'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Explicit type: $explicitNumber'),
Text('Inferred type: $inferredString'),
],
),
),
);
}
}
We declared explicitNumber with the type int explicitly. This means we tell Flutter this variable will hold an integer.
We declared inferredString with var, so Flutter figures out the type automatically from the assigned value, which is a string.
Both variables are then shown in two Text widgets inside a centered Column. This helps beginners see how type declaration and inference work in Flutter.