diff --git a/lib/providers/flutter_releases.provider.dart b/lib/providers/flutter_releases.provider.dart index 51703df5..854e1ede 100644 --- a/lib/providers/flutter_releases.provider.dart +++ b/lib/providers/flutter_releases.provider.dart @@ -12,11 +12,13 @@ class AppReleasesState { List channels; List versions; Map allMap; + bool hasGlobal; AppReleasesState({ this.channels, this.versions, this.master, this.allMap, + this.hasGlobal = false, }) { channels = []; versions = []; @@ -27,6 +29,7 @@ class AppReleasesState { List get all { final releases = [...channels, ...versions]; if (master != null) { + // Master goes first releases.insert(0, master); } @@ -54,7 +57,6 @@ final releasesStateProvider = Provider((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); @@ -73,6 +75,9 @@ final releasesStateProvider = Provider((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; diff --git a/lib/providers/fvm_cache.provider.dart b/lib/providers/fvm_cache.provider.dart index 7c6679c4..487bfedc 100644 --- a/lib/providers/fvm_cache.provider.dart +++ b/lib/providers/fvm_cache.provider.dart @@ -62,7 +62,6 @@ class FvmCacheProvider extends StateNotifier> { ProviderReference ref; List channels; List versions; - CacheVersion global; List all; StreamSubscription directoryWatcher; diff --git a/lib/screens/settings_scenes/settings_section_flutter.dart b/lib/screens/settings_scenes/settings_section_flutter.dart index 680c95ae..fce86d42 100644 --- a/lib/screens/settings_scenes/settings_section_flutter.dart +++ b/lib/screens/settings_scenes/settings_section_flutter.dart @@ -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; @@ -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(); + }, + ), + ], + ), ), ); } diff --git a/lib/services/flutter_config_service.dart b/lib/services/flutter_config_service.dart index d33b72b3..bc110afe 100644 --- a/lib/services/flutter_config_service.dart +++ b/lib/services/flutter_config_service.dart @@ -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);