Skip to content

Commit

Permalink
fix: Adjust to breaking dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nstrelow committed May 1, 2022
1 parent 721cec2 commit 2f4e14b
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/lib/screens/app_onboarding/terms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _TermsScreenState extends State<TermsScreen> {
const SizedBox(height: 30),
OutlinedButton.icon(
icon: const Icon(MdiIcons.scaleBalance),
onPressed: () => launch(appConfig.imprint[appLocale.toString()]),
onPressed: () => launchUrl(Uri.parse(appConfig.imprint[appLocale.toString()])),
label: Text(AppLocalizations.of(context).imprint_read),
),
],
Expand Down Expand Up @@ -119,7 +119,7 @@ class LegalSection extends StatelessWidget {
const SizedBox(height: 20),
OutlinedButton.icon(
icon: icon,
onPressed: () => launch(pdfUrl),
onPressed: () => launchUrl(Uri.parse(pdfUrl)),
label: Text(pdfUrlLabel),
),
CheckboxListTile(title: Text(acknowledgment), value: isChecked, onChanged: onChange),
Expand Down
10 changes: 5 additions & 5 deletions app/lib/screens/study/dashboard/contact_tab/contact_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ class ContactItem extends StatelessWidget {
switch (type) {
case ContactItemType.website:
if (!itemValue.startsWith('http://') && !itemValue.startsWith('https://')) {
launch('http://$itemValue');
launchUrl(Uri.parse('http://$itemValue'));
} else {
launch(itemValue);
launchUrl(Uri.parse(itemValue));
}
break;
case ContactItemType.email:
launch('mailto:$itemValue');
launchUrl(Uri.parse('mailto:$itemValue'));
break;
case ContactItemType.phone:
launch('tel:$itemValue');
launchUrl(Uri.parse('tel:$itemValue'));
break;
}
launch(itemValue);
launchUrl(Uri.parse(itemValue));
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/lib/screens/study/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
text: 'www.flaticon.com',
recognizer: TapGestureRecognizer()
..onTap = () {
launch('https://www.flaticon.com/');
launchUrl(Uri.parse('https://www.flaticon.com/'));
},
),
const TextSpan(text: ' made by'),
Expand All @@ -119,8 +119,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
.map(
(author) => InkWell(
onTap: () {
launch(
'https://www.flaticon.com/authors/${author.replaceAll(RegExp(r'\s|_'), '-')}',
launchUrl(
Uri.parse('https://www.flaticon.com/authors/${author.replaceAll(RegExp(r'\s|_'), '-')}'),
);
},
child: Text(
Expand Down
13 changes: 5 additions & 8 deletions core/lib/src/env/env.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import 'package:supabase/supabase.dart';

final dotEnv = <String, String>{};

late SupabaseClient client;
late String supabaseUrl;
late String supabaseAnonKey;
late String? appUrl;
late String? projectGeneratorUrl;

void loadEnv(Map<String, String> env, {SupabaseClient? supabaseClient}) {
dotEnv.addAll(env);
projectGeneratorUrl = dotEnv['STUDYU_PROJECT_GENERATOR_URL'];
appUrl = dotEnv['STUDYU_APP_URL'];
supabaseUrl = dotEnv['STUDYU_SUPABASE_URL']!;
supabaseAnonKey = dotEnv['STUDYU_SUPABASE_PUBLIC_ANON_KEY']!;
void setEnv(String envSupabaseUrl, String envSupabaseAnonKey, {String? envAppUrl, String? envProjectGeneratorUrl, SupabaseClient? supabaseClient}) {
supabaseUrl = envSupabaseUrl;
supabaseAnonKey = envSupabaseAnonKey;
projectGeneratorUrl = envProjectGeneratorUrl;
appUrl = envAppUrl;
client = supabaseClient ?? SupabaseClient(supabaseUrl, supabaseAnonKey);
}
4 changes: 2 additions & 2 deletions designer/lib/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class _DashboardState extends State<Dashboard> {
const SizedBox(height: 20),
OutlinedButton.icon(
icon: const Icon(MdiIcons.fileDocumentEdit),
onPressed: () => launch(appConfig.designerTerms[appLocale.toString()]),
onPressed: () => launchUrl(Uri.parse(appConfig.designerTerms[appLocale.toString()])),
label: Text(AppLocalizations.of(context).terms_read),
),
OutlinedButton.icon(
icon: const Icon(MdiIcons.shieldLock),
onPressed: () => launch(appConfig.designerPrivacy[appLocale.toString()]),
onPressed: () => launchUrl(Uri.parse(appConfig.designerPrivacy[appLocale.toString()])),
label: Text(AppLocalizations.of(context).privacy_read),
),
],
Expand Down
4 changes: 2 additions & 2 deletions designer/lib/designer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class _DesignerState extends State<Designer> {
icon: const Icon(MdiIcons.testTube),
label: const Text('Try draft study'),
style: TextButton.styleFrom(primary: Colors.white),
onPressed: () => launch(
'${env.appUrl}${Uri.encodeComponent(Supabase.instance.client.auth.session().persistSessionString)}',
onPressed: () => launchUrl(
Uri.parse('${env.appUrl}${Uri.encodeComponent(Supabase.instance.client.auth.session().persistSessionString)}'),
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions designer/lib/designer/about_designer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ class _AboutDesignerState extends State<AboutDesigner> {
FormBuilderTextField(
onChanged: _saveFormChanges,
name: 'website',
validator: FormBuilderValidators.url(context),
validator: FormBuilderValidators.url(),
decoration: InputDecoration(labelText: AppLocalizations.of(context).website),
initialValue: _draftStudy.contact.website,
),
FormBuilderTextField(
onChanged: _saveFormChanges,
name: 'email',
validator: FormBuilderValidators.email(context),
validator: FormBuilderValidators.email(),
decoration: InputDecoration(labelText: AppLocalizations.of(context).email),
initialValue: _draftStudy.contact.email,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class _LinearRegressionSectionEditorSectionState extends State<LinearRegressionS
name: AppLocalizations.of(context).alpha,
decoration: InputDecoration(labelText: AppLocalizations.of(context).alpha_confidence),
initialValue: widget.section.alpha.toString(),
validator: FormBuilderValidators.numeric(context),
validator: FormBuilderValidators.numeric(),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions designer/lib/widgets/study_detail/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _HeaderState extends State<Header> {
List<Widget> gitPublicActions() {
return [
TextButton.icon(
onPressed: () => launch(widget.study.repo.webUrl),
onPressed: () => launchUrl(Uri.parse(widget.study.repo.webUrl)),
icon: const Icon(MdiIcons.gitlab, color: gitlabColor),
label: const Text('Open Gitlab project', style: TextStyle(color: gitlabColor)),
),
Expand All @@ -86,7 +86,7 @@ class _HeaderState extends State<Header> {
final res = await http.get(Uri.parse('https://gitlab.com/api/v4/projects/${widget.study.repo.projectId}'));
final encodedRepoUrl =
Uri.encodeComponent((jsonDecode(res.body) as Map<String, dynamic>)['http_url_to_repo'] as String);
await launch('https://mybinder.org/v2/git/$encodedRepoUrl/HEAD?urlpath=lab');
await launchUrl(Uri.parse('https://mybinder.org/v2/git/$encodedRepoUrl/HEAD?urlpath=lab'));
},
icon: Image.asset('assets/images/binder.png', height: 24, width: 24),
label: const Text('Launch on Binder'),
Expand Down
8 changes: 7 additions & 1 deletion flutter_common/lib/src/utils/env_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ Future<void> loadEnv() async {
authCallbackUrlHostname: kIsWeb ? null : 'designer.studyu.health', // optional
debug: true, // optional
);
env.loadEnv(dotenv.env, supabaseClient: Supabase.instance.client);
env.setEnv(
dotenv.env['STUDYU_SUPABASE_URL']!,
dotenv.env['STUDYU_SUPABASE_PUBLIC_ANON_KEY']!,
envAppUrl: dotenv.env['STUDYU_APP_URL'],
envProjectGeneratorUrl: dotenv.env['STUDYU_PROJECT_GENERATOR_URL'],
supabaseClient: Supabase.instance.client,
);
}
7 changes: 6 additions & 1 deletion notebook_uploader/bin/notebook_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ const studyId = 'study-id';
late final ArgResults argResults;

void loadEnv() {
env.loadEnv(Platform.environment);
env.setEnv(
Platform.environment['STUDYU_SUPABASE_URL']!,
Platform.environment['STUDYU_SUPABASE_PUBLIC_ANON_KEY']!,
envAppUrl: Platform.environment['STUDYU_APP_URL'],
envProjectGeneratorUrl: Platform.environment['STUDYU_PROJECT_GENERATOR_URL'],
);
}

Future<void> main(List<String> arguments) async {
Expand Down
11 changes: 8 additions & 3 deletions repo_generator/bin/repo_generator.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import 'package:dotenv/dotenv.dart' as dot_env show load, env;
import 'package:dotenv/dotenv.dart';
import 'package:studyu_core/env.dart' as env;
import 'package:studyu_repo_generator/server.dart';

void loadEnv() {
dot_env.load();
env.loadEnv(dot_env.env);
final dotEnv = DotEnv()..load();
env.setEnv(
dotEnv['STUDYU_SUPABASE_URL']!,
dotEnv['STUDYU_SUPABASE_PUBLIC_ANON_KEY']!,
envAppUrl: dotEnv['STUDYU_APP_URL'],
envProjectGeneratorUrl: dotEnv['STUDYU_PROJECT_GENERATOR_URL'],
);
}

Future<void> main(List<String> args) async {
Expand Down
5 changes: 3 additions & 2 deletions repo_generator/lib/utils/generator.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:io';

import 'package:dotenv/dotenv.dart' as dot_env show env;
import 'package:dotenv/dotenv.dart';
import 'package:path/path.dart' as p;
import 'package:pretty_json/pretty_json.dart';
import 'package:studyu_core/core.dart';
Expand All @@ -13,7 +13,8 @@ import 'gitlab.dart';

Future<void> generateRepo(GitlabClient gl, String studyId) async {
print('Generating repo...');
final generatedProjectPath = dot_env.env['STUDYU_PROJECT_PATH'] ?? 'generated';
final dotEnv = DotEnv()..load();
final generatedProjectPath = dotEnv['STUDYU_PROJECT_PATH'] ?? 'generated';

// Fetch study schema and subjects data
print('Fetching study data...');
Expand Down
12 changes: 9 additions & 3 deletions repo_generator/main_dev.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import 'package:dotenv/dotenv.dart' as dot_env show load, env;
import 'package:dotenv/dotenv.dart';
import 'package:shelf_hotreload/shelf_hotreload.dart';
import 'package:studyu_core/env.dart' as env;
import 'package:studyu_repo_generator/server.dart';

void loadEnv() {
dot_env.load();
env.loadEnv(dot_env.env);
final dotEnv = DotEnv()
..load();
env.setEnv(
dotEnv['STUDYU_SUPABASE_URL']!,
dotEnv['STUDYU_SUPABASE_PUBLIC_ANON_KEY']!,
envAppUrl: dotEnv['STUDYU_APP_URL'],
envProjectGeneratorUrl: dotEnv['STUDYU_PROJECT_GENERATOR_URL'],
);
}

Future<void> main(List<String> args) async {
Expand Down

0 comments on commit 2f4e14b

Please sign in to comment.