Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings panel #73

Merged
merged 38 commits into from
Nov 22, 2020
Merged

Settings panel #73

merged 38 commits into from
Nov 22, 2020

Conversation

mateobelanger
Copy link
Contributor

@mateobelanger mateobelanger commented Nov 10, 2020

  • Added settings tab to navdrawer
  • Persistent settings with streamed_shared_preferences package (previously added by Mourad)
  • Cute UI blocks with settings_ui package
  • Added Age, Sex and AcquisitionBoard settings
  • 'Not Set' values when app is initially launched
  • Settings widget can be added to Record 'Sleep sequence' when a value has not been setted.

Misc

  • Changed sliverbar backgound, I think it's nice
  • Changed the app logo to new dodo

rsz_1124755560_838718470216463_4549644917938712101_n
rsz_124919687_426030165220498_1733611947004864712_n
rsz_124829334_2786706181587668_7741060750976301390_n_1

Copy link
Contributor

@MouradLachhab MouradLachhab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice. The only other thing is that when I started checking how to dynamically change between Bluetooth and USB repository, I looked into streaming_shared_preferences that extends shared_preferences. So unless we go for the solution where we automatically connect to the device instead of selecting it, we might have to swap for that to do dynamic changes. It allows you to subscribe to preferences and be notified of changes. They are very similar and changes should be minimal.

mobile/lib/src/application/settings/settings_cubit.dart Outdated Show resolved Hide resolved
mobile/lib/src/application/settings/settings_cubit.dart Outdated Show resolved Hide resolved
mobile/lib/src/application/settings/settings_cubit.dart Outdated Show resolved Hide resolved
mobile/lib/src/application/settings/settings_cubit.dart Outdated Show resolved Hide resolved
@WilliamHarvey97
Copy link
Contributor

such wow! good job!

@mateobelanger
Copy link
Contributor Author

Je n'aime pas du tout le widget pour la sélection du board d'acquisition? Qu'est-ce que vous diriez d'utiliser des radio buttons dans un modal? J'ai déjà fait un widget pour ça:

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class RadioButtonItem {
  final Widget title;
  final dynamic value;

  RadioButtonItem({@required this.title, @required this.value});
}

class RadioButtonsDialog<T> extends HookWidget {
  final Widget title;
  final List<RadioButtonItem> radioButtonItems;
  final T initialValue;
  final String cancelLabel;
  final String confirmLabel;
  final void Function(T) onConfirm;

  RadioButtonsDialog({
    Key key,
    this.title,
    @required this.radioButtonItems,
    @required this.initialValue,
    @required this.cancelLabel,
    @required this.confirmLabel,
    @required this.onConfirm,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final selection = useState(initialValue);
    return AlertDialog(
      title: title,
      contentPadding: EdgeInsets.symmetric(vertical: 8),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          ...radioButtonItems.map(
            (e) => RadioListTile(
              title: e.title,
              value: e.value,
              groupValue: selection.value,
              onChanged: (value) => selection.value = value,
            ),
          )
        ],
      ),
      actions: <Widget>[
        FlatButton(
          child: Text(cancelLabel.toUpperCase()),
          onPressed: () {
            Navigator.of(context).pop(false);
          },
        ),
        FlatButton(
          child: Text(
            confirmLabel.toUpperCase(),
            style: TextStyle(
              color: Theme.of(context).accentColor,
            ),
          ),
          onPressed: () {
            onConfirm(selection.value);
            Navigator.of(context).pop(true);
          },
        ),
      ],
    );
  }
}

(Ici je juge que c'est une bonne chose d'avoir un state local au widget, car c'est uniquement un state de présentation et non pas un state d'application. Par contre, il faudra sauvegarder la carte sélectionnné dans un bloc)

j'ai enlevé l'option du board d'acquisition parce que c'était plus nécessaire

@WilliamHarvey97
Copy link
Contributor

WilliamHarvey97 commented Nov 13, 2020

j'ai enlevé l'option du board d'acquisition parce que c'était plus nécessaire

Pour le sexe alors? Aussi, si c'est le genre de widget que tu aimes j'aurais aussi un NumberInputDialog

@mateobelanger
Copy link
Contributor Author

Je n'aime pas du tout le widget pour la sélection du board d'acquisition? Qu'est-ce que vous diriez d'utiliser des radio buttons dans un modal? J'ai déjà fait un widget pour ça:

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class RadioButtonItem {
  final Widget title;
  final dynamic value;

  RadioButtonItem({@required this.title, @required this.value});
}

class RadioButtonsDialog<T> extends HookWidget {
  final Widget title;
  final List<RadioButtonItem> radioButtonItems;
  final T initialValue;
  final String cancelLabel;
  final String confirmLabel;
  final void Function(T) onConfirm;

  RadioButtonsDialog({
    Key key,
    this.title,
    @required this.radioButtonItems,
    @required this.initialValue,
    @required this.cancelLabel,
    @required this.confirmLabel,
    @required this.onConfirm,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final selection = useState(initialValue);
    return AlertDialog(
      title: title,
      contentPadding: EdgeInsets.symmetric(vertical: 8),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          ...radioButtonItems.map(
            (e) => RadioListTile(
              title: e.title,
              value: e.value,
              groupValue: selection.value,
              onChanged: (value) => selection.value = value,
            ),
          )
        ],
      ),
      actions: <Widget>[
        FlatButton(
          child: Text(cancelLabel.toUpperCase()),
          onPressed: () {
            Navigator.of(context).pop(false);
          },
        ),
        FlatButton(
          child: Text(
            confirmLabel.toUpperCase(),
            style: TextStyle(
              color: Theme.of(context).accentColor,
            ),
          ),
          onPressed: () {
            onConfirm(selection.value);
            Navigator.of(context).pop(true);
          },
        ),
      ],
    );
  }
}

(Ici je juge que c'est une bonne chose d'avoir un state local au widget, car c'est uniquement un state de présentation et non pas un state d'application. Par contre, il faudra sauvegarder la carte sélectionnné dans un bloc)

j'ai enlevé l'option du board d'acquisition parce que c'était plus nécessaire

j'ai enlevé l'option du board d'acquisition parce que c'était plus nécessaire
pour le widget de sélection dropdown. J'me suis inspiré des settings de Spotify. C'est purement une préférence subjective d'ergonomie. J'trouve ça moins intrusif.


Settings(
{this.age = 30, this.serverAddress = '0.0.0.0', this.sex = Sex.NotSet})
: assert(age != null || (age == null && age > 12 && age < 125)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use contants like MAX_AGE, MIN_AGE.

Maybe use a factory constructor so you can throw custom exceptions that you could handle in the future, in place of assert statements.

@mateobelanger mateobelanger merged commit 8b0036b into master Nov 22, 2020
@mateobelanger mateobelanger deleted the mobile/app-user-settings branch November 22, 2020 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants