Skip to content

Commit

Permalink
Merge pull request #57 from leoafarias/fix/handle-global-not-set
Browse files Browse the repository at this point in the history
UI to display global not set
  • Loading branch information
leoafarias authored Apr 28, 2021
2 parents 6b99ebc + ef4fb98 commit 4bf4045
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 59 deletions.
7 changes: 6 additions & 1 deletion lib/providers/flutter_releases.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class AppReleasesState {
List<ChannelDto> channels;
List<VersionDto> versions;
Map<String, ReleaseDto> allMap;
bool hasGlobal;
AppReleasesState({
this.channels,
this.versions,
this.master,
this.allMap,
this.hasGlobal = false,
}) {
channels = <ChannelDto>[];
versions = <VersionDto>[];
Expand All @@ -27,6 +29,7 @@ class AppReleasesState {
List<ReleaseDto> get all {
final releases = [...channels, ...versions];
if (master != null) {
// Master goes first
releases.insert(0, master);
}

Expand Down Expand Up @@ -54,7 +57,6 @@ final releasesStateProvider = Provider<AppReleasesState>((ref) {
FlutterReleases payload;
ref.watch(_fetchFlutterReleases).whenData((value) => payload = value);
final installedVersions = ref.watch(fvmCacheProvider.notifier);
final globalVersion = FVMClient.getGlobalVersionSync();

// Watch this state change for refresh
ref.watch(fvmCacheProvider);
Expand All @@ -73,6 +75,9 @@ final releasesStateProvider = Provider<AppReleasesState>((ref) {
return releasesState;
}

final globalVersion = FVMClient.getGlobalVersionSync();
releasesState.hasGlobal = globalVersion != null;

// MASTER: Set Master separetely because workflow is very different
final masterCache = installedVersions.getChannel(kMasterChannel);
String masterVersion;
Expand Down
1 change: 0 additions & 1 deletion lib/providers/fvm_cache.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class FvmCacheProvider extends StateNotifier<List<CacheVersion>> {
ProviderReference ref;
List<CacheVersion> channels;
List<CacheVersion> versions;
CacheVersion global;
List<CacheVersion> all;

StreamSubscription<WatchEvent> directoryWatcher;
Expand Down
153 changes: 99 additions & 54 deletions lib/screens/settings_scenes/settings_section_flutter.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:sidekick/components/atoms/typography.dart';
import 'package:sidekick/providers/flutter_releases.provider.dart';
import 'package:sidekick/providers/settings.provider.dart';

class SettingsSectionFlutter extends StatelessWidget {
class SettingsSectionFlutter extends HookWidget {
final Settings settings;
final Function() onSave;

Expand All @@ -14,62 +18,103 @@ class SettingsSectionFlutter extends StatelessWidget {

@override
Widget build(BuildContext context) {
final releases = useProvider(releasesStateProvider);

final deactivate = !releases.hasGlobal;

return Container(
padding: const EdgeInsets.only(top: 20),
child: ListView(
children: [
Text('Flutter', style: Theme.of(context).textTheme.headline6),
const SizedBox(height: 20),
SwitchListTile(
title: const Text('Analytics & Crash Reporting'),
subtitle: const Text("When a flutter command crashes it attempts"
child: CupertinoScrollbar(
child: ListView(
children: [
Text('Flutter', style: Theme.of(context).textTheme.headline6),
const SizedBox(height: 20),
releases.hasGlobal
? Container()
: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// TODO: Move this into a separate component
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.deepOrange.withOpacity(0.1),
border: Border.all(
color: Colors.deepOrange,
width: 0.5,
),
),
child: const Text(
'A Flutter sdk version neeeds to be set as global '
'in order to access Flutter settings',
),
),
const SizedBox(height: 20)
],
),
SwitchListTile(
title: const Text('Analytics & Crash Reporting'),
subtitle: const Text(
"When a flutter command crashes it attempts"
" to send a crash report to Google in order to help"
" Google contribute improvements to Flutter over time"),
value: !settings.flutter.analytics,
onChanged: (value) {
settings.flutter.analytics = !value;
onSave();
},
),
const SizedBox(height: 20),
const Subheading('Platforms'),
const SizedBox(height: 20),
SwitchListTile(
title: const Text('Web'),
value: settings.flutter.web,
onChanged: (value) {
settings.flutter.web = value;
onSave();
},
),
const Divider(),
SwitchListTile(
title: const Text('MacOS'),
value: settings.flutter.macos,
onChanged: (value) {
settings.flutter.macos = value;
onSave();
},
),
const Divider(),
SwitchListTile(
title: const Text('Windows'),
value: settings.flutter.windows,
onChanged: (value) {
settings.flutter.windows = value;
onSave();
},
),
const Divider(),
SwitchListTile(
title: const Text('Linux'),
value: settings.flutter.linux,
onChanged: (value) {
settings.flutter.linux = value;
onSave();
},
),
],
" Google contribute improvements to Flutter over time",
),
value: !settings.flutter.analytics,
onChanged: deactivate
? null
: (value) {
settings.flutter.analytics = !value;
onSave();
},
),
const SizedBox(height: 20),
const Subheading('Platforms'),
const SizedBox(height: 20),
SwitchListTile(
title: const Text('Web'),
value: settings.flutter.web,
onChanged: deactivate
? null
: (value) {
settings.flutter.web = value;
onSave();
},
),
const Divider(),
SwitchListTile(
title: const Text('MacOS'),
value: settings.flutter.macos,
onChanged: deactivate
? null
: (value) {
settings.flutter.macos = value;
onSave();
},
),
const Divider(),
SwitchListTile(
title: const Text('Windows'),
value: settings.flutter.windows,
onChanged: deactivate
? null
: (value) {
settings.flutter.windows = value;
onSave();
},
),
const Divider(),
SwitchListTile(
title: const Text('Linux'),
value: settings.flutter.linux,
onChanged: deactivate
? null
: (value) {
settings.flutter.linux = value;
onSave();
},
),
],
),
),
);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/services/flutter_config_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class FlutterConfigService {
final globalVersion = await FVMClient.getGlobal();

if (globalVersion == null) {
throw Exception(
'Can only check flutter settings with a global version configured',
);
// TODO: Need to change this
// Can only run with a global version configured
// Will cause settings to be all off
return '';
}

final result = await Process.run(globalVersion.flutterExec, args);
Expand Down

0 comments on commit 4bf4045

Please sign in to comment.