Files
hackathon-innovaflow5.0-cdf…/recolecta_app/lib/main.dart
shinra32 f12e119d6f Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com>
Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com>

modificacion de configuraciones para flutter,
2026-05-22 15:27:24 -06:00

88 lines
2.5 KiB
Dart

// ============================================================
// main.dart — App Recolecta (corregido)
// Cambios aplicados:
// 1. Agregados imports faltantes (material, riverpod)
// 2. Corregido ColorScheme.fromSeed (faltaba el tipo)
// 3. Corregido MainAxisAlignment.center (faltaba el tipo)
// 4. Agregado WidgetsFlutterBinding.ensureInitialized() antes de dotenv
// ============================================================
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
Future<void> main() async {
// NECESARIO antes de cualquier async en main (inicializa el motor de Flutter)
WidgetsFlutterBinding.ensureInitialized();
// Carga el .env desde assets/
await dotenv.load(fileName: "assets/.env");
runApp(const ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Recolecta',
theme: ThemeData(
// ❌ ANTES: colorScheme: .fromSeed(seedColor: Colors.deepPurple),
// ✅ AHORA: faltaba el tipo ColorScheme antes del .fromSeed
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Recolecta - Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
// ❌ ANTES: mainAxisAlignment: .center,
// ✅ AHORA: faltaba el tipo MainAxisAlignment antes del .center
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}