ad project
This commit is contained in:
+283
@@ -0,0 +1,283 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class Depense {
|
||||
final String nom;
|
||||
final double montant;
|
||||
|
||||
Depense({required this.nom, required this.montant});
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
bool _darkMode = false;
|
||||
String _currency = '€';
|
||||
|
||||
void _changeCurrency(String value) {
|
||||
setState(() {
|
||||
_currency = value;
|
||||
});
|
||||
}
|
||||
|
||||
void _toggleTheme(bool value) {
|
||||
setState(() {
|
||||
_darkMode = value;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'Gestion Finance',
|
||||
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.deepPurple,
|
||||
brightness: Brightness.light,
|
||||
),
|
||||
),
|
||||
|
||||
darkTheme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.deepPurple,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
),
|
||||
|
||||
themeMode: _darkMode ? ThemeMode.dark : ThemeMode.light,
|
||||
|
||||
home: MyHomePage(
|
||||
onThemeChanged: _toggleTheme,
|
||||
darkMode: _darkMode,
|
||||
currency: _currency,
|
||||
onCurrencyChanged: _changeCurrency,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
final Function(bool) onThemeChanged;
|
||||
final bool darkMode;
|
||||
final String currency;
|
||||
final Function(String) onCurrencyChanged;
|
||||
|
||||
const MyHomePage({
|
||||
super.key,
|
||||
required this.onThemeChanged,
|
||||
required this.darkMode,
|
||||
required this.currency,
|
||||
required this.onCurrencyChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final List<Depense> _depenses = [];
|
||||
|
||||
final TextEditingController _nomController = TextEditingController();
|
||||
final TextEditingController _montantController = TextEditingController();
|
||||
|
||||
void _ajouterDepense() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Nouvelle dépense'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _nomController,
|
||||
decoration: const InputDecoration(labelText: 'Nom'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _montantController,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(labelText: 'Montant'),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Annuler'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_depenses.add(
|
||||
Depense(
|
||||
nom: _nomController.text,
|
||||
montant: double.tryParse(_montantController.text) ?? 0,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
_nomController.clear();
|
||||
_montantController.clear();
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Ajouter'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
double get _total {
|
||||
return _depenses.fold(0, (sum, item) => sum + item.montant);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Gestion des dépenses'),
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.settings),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SettingsPage(
|
||||
darkMode: widget.darkMode,
|
||||
onThemeChanged: widget.onThemeChanged,
|
||||
currency: widget.currency,
|
||||
onCurrencyChanged: widget.onCurrencyChanged,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
color: Colors.deepPurple.shade100,
|
||||
child: Text(
|
||||
'Total : ${_total.toStringAsFixed(2)} ${widget.currency}',
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: _depenses.isEmpty
|
||||
? const Center(child: Text('Aucune dépense'))
|
||||
: ListView.builder(
|
||||
itemCount: _depenses.length,
|
||||
itemBuilder: (context, index) {
|
||||
final depense = _depenses[index];
|
||||
|
||||
return Dismissible(
|
||||
key: Key(depense.nom + index.toString()),
|
||||
|
||||
direction: DismissDirection.startToEnd,
|
||||
|
||||
onDismissed: (direction) {
|
||||
setState(() {
|
||||
_depenses.removeAt(index);
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('${depense.nom} supprimé')),
|
||||
);
|
||||
},
|
||||
|
||||
background: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
color: Colors.red,
|
||||
child: const Icon(Icons.delete, color: Colors.white),
|
||||
),
|
||||
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.money_off),
|
||||
title: Text(depense.nom),
|
||||
trailing: Text(
|
||||
'${depense.montant.toStringAsFixed(2)} ${widget.currency}',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _ajouterDepense,
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
final bool darkMode;
|
||||
final Function(bool) onThemeChanged;
|
||||
final String currency;
|
||||
final Function(String) onCurrencyChanged;
|
||||
|
||||
const SettingsPage({
|
||||
super.key,
|
||||
required this.darkMode,
|
||||
required this.onThemeChanged,
|
||||
required this.currency,
|
||||
required this.onCurrencyChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Paramètres')),
|
||||
body: ListView(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
title: const Text('Mode sombre'),
|
||||
value: darkMode,
|
||||
onChanged: onThemeChanged,
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Devise'),
|
||||
trailing: DropdownButton<String>(
|
||||
value: currency,
|
||||
items: const [
|
||||
DropdownMenuItem(value: '€', child: Text('Euro (€)')),
|
||||
DropdownMenuItem(value: '\$', child: Text('Dollar (\$)')),
|
||||
DropdownMenuItem(value: '£', child: Text('Livre (£)')),
|
||||
DropdownMenuItem(value: '¥', child: Text('Yen (¥)')),
|
||||
],
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
onCurrencyChanged(value);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user