Skip to content

Commit

Permalink
Added showMoyenne to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCoduriV committed Sep 22, 2021
1 parent b2afb5b commit 502b550
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 40 deletions.
19 changes: 19 additions & 0 deletions lib/controllers/settings_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';

class SettingsProvider extends ChangeNotifier {
late bool _showMoyenne;
final box = Hive.box('heig-settings');

SettingsProvider() {
_showMoyenne = box.get('showMoyenne', defaultValue: true);
}

bool get showMoyenne => _showMoyenne;

set showMoyenne(bool showMoyenne) {
_showMoyenne = showMoyenne;
box.put('showMoyenne', showMoyenne);
notifyListeners();
}
}
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart' as foundation;
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:get_it/get_it.dart';
import 'package:heig_front/controllers/settings_provider.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -39,6 +40,7 @@ Future<void> setup() async {
Hive.registerAdapter(TodoAdapter());
Hive.registerAdapter(UserAdapter());
await Hive.openBox('heig');
await Hive.openBox('heig-settings');

GetIt.I.registerSingleton<BulletinProvider>(BulletinProvider());
GetIt.I.registerSingleton<ApiController>(ApiController());
Expand All @@ -48,6 +50,7 @@ Future<void> setup() async {
GetIt.I.registerSingleton<UserProvider>(UserProvider());
GetIt.I.registerSingleton<HorairesProvider>(HorairesProvider());
GetIt.I.registerSingleton<NotificationsManager>(NotificationsManager());
GetIt.I.registerSingleton<SettingsProvider>(SettingsProvider());
GetIt.I.registerSingleton<theme.ThemeProvider>(theme.ThemeProvider());
GetIt.I.registerSingleton<GlobalKey<RefreshIndicatorState>>(
GlobalKey<RefreshIndicatorState>());
Expand Down
23 changes: 13 additions & 10 deletions lib/widgets/chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import 'package:flutter/material.dart';
class Chart extends StatelessWidget {
final List<double> notes;
final List<double> moyennes;
const Chart(this.notes, this.moyennes, {Key? key}) : super(key: key);
final bool showMoyenne;
const Chart(this.notes, this.moyennes, {Key? key, this.showMoyenne = true})
: super(key: key);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -69,16 +71,17 @@ class Chart extends StatelessWidget {
.toList(),
),
),
LineChartBarData(
spots: spots2,
isCurved: true,
colors: gradientColors2,
barWidth: 3,
isStrokeCapRound: true,
dotData: FlDotData(
show: false,
if (showMoyenne)
LineChartBarData(
spots: spots2,
isCurved: true,
colors: gradientColors2,
barWidth: 3,
isStrokeCapRound: true,
dotData: FlDotData(
show: false,
),
),
),
],
), // Optional
);
Expand Down
21 changes: 13 additions & 8 deletions lib/widgets/screens/bulletin_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:heig_front/controllers/settings_provider.dart';
import 'package:provider/provider.dart';

import '../../controllers/bulletin_provider.dart';
Expand All @@ -16,8 +17,11 @@ class BulletinScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(
value: GetIt.I<BulletinProvider>(),
return MultiProvider(
providers: [
ChangeNotifierProvider.value(value: GetIt.I<BulletinProvider>()),
ChangeNotifierProvider.value(value: GetIt.I<SettingsProvider>())
],
builder: (context, _) {
final Bulletin bulletin = context.watch<BulletinProvider>().bulletin;
final bool loading = context.watch<BulletinProvider>().loading;
Expand All @@ -34,8 +38,8 @@ class BulletinScreen extends StatelessWidget {
TextStyle(fontWeight: FontWeight.w500, fontSize: 17)),
const SizedBox(width: 10),
DropdownButton<int>(
style: const TextStyle(
backgroundColor: Colors.white, color: Colors.black),
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1!.color),
value: Provider.of<BulletinProvider>(context).year,
icon: const Icon(Icons.arrow_downward),
onChanged: (int? newValue) {
Expand Down Expand Up @@ -68,7 +72,7 @@ class BulletinScreen extends StatelessWidget {
),
Expanded(
child: LayoutBuilder(
builder: (context, constraints) => RefreshIndicator(
builder: (_context, constraints) => RefreshIndicator(
color: Colors.red,
key: GetIt.I<GlobalKey<RefreshIndicatorState>>(),
onRefresh: () =>
Expand All @@ -87,15 +91,16 @@ class BulletinScreen extends StatelessWidget {
);
}

Widget buildButtons(context, Bulletin bulletin, BoxConstraints constraints) {
Widget buildButtons(
BuildContext context, Bulletin bulletin, BoxConstraints constraints) {
if (bulletin.branches.isEmpty) {
return SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight, minWidth: constraints.maxWidth),
child: const Center(
child: Text('Veuillez tirer vers le bas pour rafraichir.'),
child: Text('tirez vers le bas pour rafraichir.'),
),
),
);
Expand All @@ -105,7 +110,7 @@ class BulletinScreen extends StatelessWidget {
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.fromLTRB(5, 10, 5, 0),
itemCount: bulletin.branches.length,
itemBuilder: (context, index) {
itemBuilder: (_context, index) {
final List<Branche> branches = bulletin.branches;

return BrancheButton(
Expand Down
41 changes: 26 additions & 15 deletions lib/widgets/screens/notes_details.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:heig_front/controllers/settings_provider.dart';
import 'package:provider/provider.dart';
import 'package:vrouter/vrouter.dart';

import '../../controllers/bulletin_provider.dart';
Expand All @@ -19,19 +21,22 @@ class NotesDetails extends StatelessWidget {
final List<Note> notesCours = bulletin.branches[id].cours;
final List<Note> notesLabo = bulletin.branches[id].laboratoire;

return Column(
children: [
Expanded(
child: Container(
color: Theme.of(context).primaryColor,
padding: const EdgeInsets.all(20),
child: ListView(
physics: const BouncingScrollPhysics(),
children: getChildren(context, notesCours, notesLabo),
return ChangeNotifierProvider.value(
value: GetIt.I.get<SettingsProvider>(),
builder: (context, _) => Column(
children: [
Expanded(
child: Container(
color: Theme.of(context).primaryColor,
padding: const EdgeInsets.all(20),
child: ListView(
physics: const BouncingScrollPhysics(),
children: getChildren(context, notesCours, notesLabo),
),
),
),
),
],
],
),
);
}

Expand All @@ -49,8 +54,11 @@ class NotesDetails extends StatelessWidget {
padding: const EdgeInsets.only(right: 20),
height: 200,
width: double.infinity,
child: Chart(notesCours.map((e) => e.note).toList(),
notesCours.map((e) => e.moyenneClasse).toList()),
child: Chart(
notesCours.map((e) => e.note).toList(),
notesCours.map((e) => e.moyenneClasse).toList(),
showMoyenne: Provider.of<SettingsProvider>(context).showMoyenne,
),
),
if (notesCours.isNotEmpty)
DataTable(
Expand All @@ -70,8 +78,11 @@ class NotesDetails extends StatelessWidget {
padding: const EdgeInsets.only(right: 20),
height: 200,
width: double.infinity,
child: Chart(notesLabo.map((e) => e.note).toList(),
notesLabo.map((e) => e.moyenneClasse).toList()),
child: Chart(
notesLabo.map((e) => e.note).toList(),
notesLabo.map((e) => e.moyenneClasse).toList(),
showMoyenne: Provider.of<SettingsProvider>(context).showMoyenne,
),
),
if (notesLabo.isNotEmpty)
DataTable(
Expand Down
32 changes: 25 additions & 7 deletions lib/widgets/screens/settings_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:heig_front/controllers/settings_provider.dart';
import 'package:provider/provider.dart';
import '../../controllers/theme_data.dart' as theme;

class SettingsScreen extends StatefulWidget {
Expand All @@ -12,11 +14,13 @@ class SettingsScreen extends StatefulWidget {
class _SettingsScreenState extends State<SettingsScreen> {
@override
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).primaryColor,
child: ListView(
children: [
SwitchListTile(
return ChangeNotifierProvider.value(
value: GetIt.I.get<SettingsProvider>(),
builder: (context, _) => Container(
color: Theme.of(context).primaryColor,
child: ListView(
children: [
SwitchListTile(
title: Text(
'Dark mode',
style: TextStyle(
Expand All @@ -29,8 +33,22 @@ class _SettingsScreenState extends State<SettingsScreen> {
} else {
GetIt.I.get<theme.ThemeProvider>().mode = ThemeMode.dark;
}
})
],
},
),
SwitchListTile(
title: Text(
'Afficher la moyenne',
style: TextStyle(
color: Theme.of(context).textTheme.bodyText1!.color),
),
value: Provider.of<SettingsProvider>(context).showMoyenne,
onChanged: (value) {
GetIt.I.get<SettingsProvider>().showMoyenne =
!GetIt.I.get<SettingsProvider>().showMoyenne;
},
)
],
),
),
);
}
Expand Down

0 comments on commit 502b550

Please sign in to comment.