Skip to content

Commit

Permalink
comments (0)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkhan.nausharipov committed Nov 19, 2022
1 parent b78bbd3 commit 70c0d61
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'builders/sdks.dart';

class SdkDropdown extends StatelessWidget {
final String sdkId;
final void Function(String? sdkId) onChanged;
final ValueChanged<String?> onChanged;
const SdkDropdown({
required this.sdkId,
required this.onChanged,
Expand Down
6 changes: 3 additions & 3 deletions learning/tour-of-beam/frontend/lib/pages/tour/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {
playgroundController = _createPlaygroundController(initialSdkId) {
contentTreeController.addListener(_onChanged);
_unitContentCache.addListener(_onChanged);
_appNotifier.addListener(_setSdk);
_appNotifier.addListener(_onAppNotifierChanged);
_onChanged();
}

Expand All @@ -56,7 +56,7 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {
treeIds: contentTreeController.treeIds,
);

void _setSdk() {
void _onAppNotifierChanged() {
final sdkId = _appNotifier.sdkId;
if (sdkId != null) {
playgroundController.setSdk(Sdk.parseOrCreate(sdkId));
Expand Down Expand Up @@ -163,7 +163,7 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {
void dispose() {
_unitContentCache.removeListener(_onChanged);
contentTreeController.removeListener(_onChanged);
_appNotifier.removeListener(_setSdk);
_appNotifier.removeListener(_onAppNotifierChanged);
super.dispose();
}
}
4 changes: 2 additions & 2 deletions learning/tour-of-beam/frontend/lib/pages/welcome/screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class _SdkSelection extends StatelessWidget {
sdkId: appNotifier.sdkId,
setSdkId: (v) => appNotifier.sdkId = v,
onStartPressed: () {
startTour(appNotifier.sdkId);
_startTour(appNotifier.sdkId);
},
),
);
Expand All @@ -151,7 +151,7 @@ class _SdkSelection extends StatelessWidget {
);
}

void startTour(String? sdkId) {
void _startTour(String? sdkId) {
if (sdkId == null) {
return;
}
Expand Down
20 changes: 11 additions & 9 deletions learning/tour-of-beam/frontend/lib/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'constants/storage_keys.dart';

class AppNotifier extends ChangeNotifier {
static const _storage = FlutterSecureStorage();
String? _sdkId;

AppNotifier() {
Expand All @@ -35,19 +34,22 @@ class AppNotifier extends ChangeNotifier {

set sdkId(String? newValue) {
_sdkId = newValue;
unawaited(_writeSdkId());
unawaited(_writeSdkId(newValue));
notifyListeners();
}

Future<void> _writeSdkId() async {
await _storage.write(
key: StorageKeys.sdkId,
value: _sdkId,
);
Future<void> _writeSdkId(String? value) async {
final preferences = await SharedPreferences.getInstance();
if (value != null) {
await preferences.setString(StorageKeys.sdkId, value);
} else {
await preferences.remove(StorageKeys.sdkId);
}
}

Future<void> _readSdkId() async {
_sdkId = await _storage.read(key: StorageKeys.sdkId);
final preferences = await SharedPreferences.getInstance();
_sdkId = preferences.getString(StorageKeys.sdkId);
notifyListeners();
}
}
42 changes: 0 additions & 42 deletions learning/tour-of-beam/frontend/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -324,48 +324,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.12"
flutter_secure_storage:
dependency: "direct main"
description:
name: flutter_secure_storage
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.0"
flutter_secure_storage_linux:
dependency: transitive
description:
name: flutter_secure_storage_linux
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
flutter_secure_storage_macos:
dependency: transitive
description:
name: flutter_secure_storage_macos
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
flutter_secure_storage_platform_interface:
dependency: transitive
description:
name: flutter_secure_storage_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter_secure_storage_web:
dependency: transitive
description:
name: flutter_secure_storage_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
flutter_secure_storage_windows:
dependency: transitive
description:
name: flutter_secure_storage_windows
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
flutter_svg:
dependency: "direct main"
description:
Expand Down
1 change: 0 additions & 1 deletion learning/tour-of-beam/frontend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dependencies:
easy_localization_loader: ^1.0.0
flutter: { sdk: flutter }
flutter_markdown: ^0.6.12
flutter_secure_storage: ^6.0.0
flutter_svg: ^1.0.3
get_it: ^7.2.0
google_fonts: ^3.0.1
Expand Down

0 comments on commit 70c0d61

Please sign in to comment.