import 'package:flutter/material.dart';
// TODO: Create GreetingService class
// TODO: Create ServiceLocator class with register and get methods
void main() {
// TODO: Register GreetingService instance
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: ServiceLocatorDemo(),
);
}
}
class ServiceLocatorDemo extends StatefulWidget {
const ServiceLocatorDemo({super.key});
@override
State<ServiceLocatorDemo> createState() => _ServiceLocatorDemoState();
}
class _ServiceLocatorDemoState extends State<ServiceLocatorDemo> {
String greeting = '';
void _showGreeting() {
// TODO: Use service locator to get GreetingService and update greeting
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Service Locator Demo')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Greeting:'),
const SizedBox(height: 8),
Text(greeting, style: const TextStyle(fontSize: 18)),
const SizedBox(height: 24),
ElevatedButton(
onPressed: _showGreeting,
child: const Text('Show Greeting'),
),
],
),
),
);
}
}