Skip to content

Commit

Permalink
chore: fix and format
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesvedder committed Jun 28, 2024
1 parent c44ddc9 commit 191a21f
Show file tree
Hide file tree
Showing 32 changed files with 514 additions and 416 deletions.
131 changes: 75 additions & 56 deletions app/lib/screens/study/onboarding/study_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,66 +134,77 @@ class _StudySelectionScreenState extends State<StudySelectionScreen> {
],
),
),
_hiddenStudies && template == null
? Column(
children: [
MaterialBanner(
padding: const EdgeInsets.all(8),
leading: Icon(
MdiIcons.exclamationThick,
color: Colors.orange,
size: 32,
),
content: Text(
AppLocalizations.of(context)!
.study_selection_hidden_studies,
style: Theme.of(context).textTheme.titleSmall,
),
actions: const [SizedBox.shrink()],
backgroundColor: Colors.yellow[100],
),
const SizedBox(height: 16),
],
)
: const SizedBox.shrink(),
template != null
? Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: theme.colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
if (_hiddenStudies && template == null)
Column(
children: [
MaterialBanner(
padding: const EdgeInsets.all(8),
leading: Icon(
MdiIcons.exclamationThick,
color: Colors.orange,
size: 32,
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(loc.selected_template_trial,
style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
Text.rich(TextSpan(children: [
content: Text(
AppLocalizations.of(context)!
.study_selection_hidden_studies,
style: Theme.of(context).textTheme.titleSmall,
),
actions: const [SizedBox.shrink()],
backgroundColor: Colors.yellow[100],
),
const SizedBox(height: 16),
],
)
else
const SizedBox.shrink(),
if (template != null)
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: theme.colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
loc.selected_template_trial,
style: theme.textTheme.titleMedium,
),
const SizedBox(height: 8),
Text.rich(
TextSpan(
children: [
TextSpan(
text: "${loc.title}: ",
style: theme.textTheme.titleSmall,
),
TextSpan(
text: template.title,
),
])),
const SizedBox(height: 2),
Text.rich(TextSpan(children: [
],
),
),
const SizedBox(height: 2),
Text.rich(
TextSpan(
children: [
TextSpan(
text: "${loc.description}: ",
style: theme.textTheme.titleSmall,
),
TextSpan(
text: template.description,
),
])),
],
],
),
),
)
: const SizedBox.shrink(),
],
),
)
else
const SizedBox.shrink(),
Expanded(
child: RetryFutureBuilder<ExtractionResult<Study>>(
tryFunction: () async => subStudies.isEmpty
Expand All @@ -218,11 +229,14 @@ class _StudySelectionScreenState extends State<StudySelectionScreen> {
// Filter out sub-studies and templates without sub studies
final filteredStudies = subStudies.isEmpty
? studies
.where((study) =>
!study.isSubStudy &&
(!study.isTemplate ||
studies.any(
(s) => s.parentTemplateId == study.id)))
.where(
(study) =>
!study.isSubStudy &&
(!study.isTemplate ||
studies.any(
(s) => s.parentTemplateId == study.id,
)),
)
.toList()
: studies;
return ListView.builder(
Expand All @@ -240,16 +254,21 @@ class _StudySelectionScreenState extends State<StudySelectionScreen> {
numSubtrials: numSubtrials,
onTap: () => study is Template
? Navigator.pushNamed(
context, Routes.studySelection,
context,
Routes.studySelection,
arguments: StudySelectionScreenArgs(
template: study,
subStudies: studies
.where((s) =>
template: study,
subStudies: studies
.where(
(s) =>
s is TemplateSubStudy &&
s.parentTemplateId ==
study.id)
.map((s) => s as TemplateSubStudy)
.toList()))
study.id,
)
.map((s) => s as TemplateSubStudy)
.toList(),
),
)
: navigateToStudyOverview(context, study),
),
),
Expand Down
113 changes: 60 additions & 53 deletions designer_v2/lib/common_views/form_table_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,33 +186,36 @@ class FormSectionHeader extends StatelessWidget {
Row(
children: [
Expanded(
child: FormTableLayout(
rows: [
FormTableRow(
label: title,
labelHelpText: helpText,
labelStyle: titleStyle.merge(titleTextStyle),
input: const SizedBox.shrink(),
),
],
columnWidths: const {
0: IntrinsicColumnWidth(),
},
)),
(right != null)
? Row(
children: [
right!,
const SizedBox(width: 12.0),
],
)
: const SizedBox.shrink(),
showLock
? ReactiveFormLock(
formControl: lockControl,
helpText: lockHelpText,
)
: const SizedBox.shrink(),
child: FormTableLayout(
rows: [
FormTableRow(
label: title,
labelHelpText: helpText,
labelStyle: titleStyle.merge(titleTextStyle),
input: const SizedBox.shrink(),
),
],
columnWidths: const {
0: IntrinsicColumnWidth(),
},
),
),
if (right != null)
Row(
children: [
right!,
const SizedBox(width: 12.0),
],
)
else
const SizedBox.shrink(),
if (showLock)
ReactiveFormLock(
formControl: lockControl,
helpText: lockHelpText,
)
else
const SizedBox.shrink(),
],
),
if (divider) const Divider() else const SizedBox.shrink(),
Expand Down Expand Up @@ -267,12 +270,13 @@ class FormLabel extends StatelessWidget {
}

class FormLock extends StatefulWidget {
const FormLock(
{super.key,
required this.locked,
this.onLockChanged,
this.readOnly = false,
this.helpText});
const FormLock({
super.key,
required this.locked,
this.onLockChanged,
this.readOnly = false,
this.helpText,
});

final bool locked;
final bool readOnly;
Expand Down Expand Up @@ -306,18 +310,19 @@ class _FormLockState extends State<FormLock> {
});
},
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: Padding(
padding: const EdgeInsets.all(8),
child:
Icon(_locked ? MdiIcons.lock : MdiIcons.lockOpen, size: 24.0),
)),
duration: const Duration(milliseconds: 250),
child: Padding(
padding: const EdgeInsets.all(8),
child:
Icon(_locked ? MdiIcons.lock : MdiIcons.lockOpen, size: 24.0),
),
),
),
);

if (widget.helpText != null) {
return Tooltip(
message: widget.helpText!,
message: widget.helpText,
child: lockView,
);
}
Expand All @@ -333,17 +338,19 @@ class ReactiveFormLock<T> extends ReactiveFormField<bool, bool> {
super.formControl,
ReactiveFormFieldCallback<bool>? onChanged,
String? helpText,
}) : super(builder: (field) {
return FormLock(
locked: field.value ?? false,
readOnly: field.control.disabled,
helpText: helpText,
onLockChanged: field.control.enabled
? (value) {
field.didChange(value);
onChanged?.call(field.control);
}
: null,
);
});
}) : super(
builder: (field) {
return FormLock(
locked: field.value ?? false,
readOnly: field.control.disabled,
helpText: helpText,
onLockChanged: field.control.enabled
? (value) {
field.didChange(value);
onChanged?.call(field.control);
}
: null,
);
},
);
}
4 changes: 3 additions & 1 deletion designer_v2/lib/domain/study.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ class StudyTemplates {
}

static TemplateSubStudy emptySubStudyDraft(
String userId, Template parentTemplate) {
String userId,
Template parentTemplate,
) {
final newDraft = TemplateSubStudy.create(userId, parentTemplate);
newDraft.title = StudyTemplates.kUnnamedSubStudyTitle;
newDraft.iconName = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class StudyAnalyzeControllerState extends StudyControllerBaseState {
study.value?.exportDisabledReason(currentUser!) ?? '';

@override
StudyAnalyzeControllerState copyWith(
{WrappedModel<Study>? studyWithMetadata}) {
StudyAnalyzeControllerState copyWith({
WrappedModel<Study>? studyWithMetadata,
}) {
return StudyAnalyzeControllerState(
studyWithMetadata: studyWithMetadata ?? super.studyWithMetadata,
currentUser: currentUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DashboardController extends StateNotifier<DashboardState>
router.dispatch(RoutingIntents.studyNew(isTemplate));
}

onExpandStudy(Study study) {
void onExpandStudy(Study study) {
final expandedStudies = state.expandedStudies.contains(study.id)
? state.expandedStudies.difference({study.id})
: state.expandedStudies.union({study.id});
Expand Down
Loading

0 comments on commit 191a21f

Please sign in to comment.