Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/flutter/samples into Upda…
Browse files Browse the repository at this point in the history
…te-platform_channels
  • Loading branch information
adarsh-technocrat committed Jan 31, 2021
2 parents 045cc70 + 1fae13e commit 9f6c7f5
Show file tree
Hide file tree
Showing 26 changed files with 386 additions and 723 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ A collection of open source samples that illustrate best practices for
The easiest way to browse through the samples in this repo (as well as a few others!)
is the [visual samples index](https://flutter.github.io/samples).

## Tip: minimize download size

As this repository is quite big, you can use svn to download a single example.
For example:

```
svn co https://github.com/flutter/samples/trunk/provider_shopper
```

You can also use a shallow clone to download just the latest revision:

```
git clone --depth 1 https://github.com/flutter/samples.git
```

## Interested in contributing?

See the [contributor's guide](CONTRIBUTING.md)!
Expand Down
4 changes: 2 additions & 2 deletions experimental/desktop_photo_search/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class UnsplashHomePage extends StatelessWidget {
label: 'About ...',
onClicked: () {
showDialog<void>(
context: context,
builder: (context) => PolicyDialog(),
context: context,
builder: (context) => PolicyDialog(),
);
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class PolicyDialog extends StatelessWidget {
children: <TextSpan>[
TextSpan(
text: 'https://policies.google.com/terms',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.lightBlue),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.lightBlue),
recognizer: TapGestureRecognizer()
..onTap = () async {
final url = 'https://policies.google.com/terms';
Expand All @@ -65,7 +67,9 @@ class PolicyDialog extends StatelessWidget {
children: <TextSpan>[
TextSpan(
text: 'https://unsplash.com/terms',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.lightBlue),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.lightBlue),
recognizer: TapGestureRecognizer()
..onTap = () async {
final url = 'https://unsplash.com/terms';
Expand Down
6 changes: 6 additions & 0 deletions experimental/veggieseasons/lib/data/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class Preferences extends ChangeNotifier {
notifyListeners();
}

Future<void> restoreDefaults() async {
final prefs = await SharedPreferences.getInstance();
await prefs.clear();
load();
}

void load() {
_loading = _loadFromSharedPrefs();
}
Expand Down
3 changes: 1 addition & 2 deletions experimental/veggieseasons/lib/screens/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:flutter/widgets.dart';
import 'package:provider/provider.dart';
import 'package:veggieseasons/data/app_state.dart';
import 'package:veggieseasons/data/veggie.dart';
import 'package:veggieseasons/widgets/search_bar.dart';
import 'package:veggieseasons/widgets/veggie_headline.dart';

class SearchScreen extends StatefulWidget {
Expand Down Expand Up @@ -49,7 +48,7 @@ class _SearchScreenState extends State<SearchScreen> with RestorationMixin {
Widget _createSearchBox() {
return Padding(
padding: const EdgeInsets.all(8),
child: SearchBar(
child: CupertinoSearchTextField(
controller: controller.value,
focusNode: focusNode,
),
Expand Down
39 changes: 39 additions & 0 deletions experimental/veggieseasons/lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,44 @@ class SettingsScreen extends StatelessWidget {
);
}

SettingsItem _buildRestoreDefaultsItem(
BuildContext context, Preferences prefs) {
return SettingsItem(
label: 'Restore Defaults',
icon: SettingsIcon(
backgroundColor: CupertinoColors.systemRed,
icon: Styles.resetIcon,
),
content: SettingsNavigationIndicator(),
onPress: () {
showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Are you sure?'),
content: Text(
'Are you sure you want to reset the current settings?',
),
actions: <Widget>[
CupertinoDialogAction(
isDestructiveAction: true,
child: Text('Yes'),
onPressed: () async {
await prefs.restoreDefaults();
Navigator.pop(context);
},
),
CupertinoDialogAction(
isDefaultAction: true,
child: Text('No'),
onPressed: () => Navigator.pop(context),
)
],
),
);
},
);
}

@override
Widget build(BuildContext context) {
final prefs = Provider.of<Preferences>(context);
Expand All @@ -238,6 +276,7 @@ class SettingsScreen extends StatelessWidget {
items: [
_buildCaloriesItem(context, prefs),
_buildCategoriesItem(context, prefs),
_buildRestoreDefaultsItem(context, prefs),
],
),
],
Expand Down
18 changes: 8 additions & 10 deletions experimental/veggieseasons/lib/styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,12 @@ abstract class Styles {
? CupertinoColors.lightBackgroundGray
: null;

static Color searchBackground(CupertinoThemeData themeData) =>
themeData.barBackgroundColor;

static const frostedBackground = Color(0xccf8f8f8);

static const closeButtonUnpressed = Color(0xff101010);

static const closeButtonPressed = Color(0xff808080);

static TextStyle searchText(CupertinoThemeData themeData) =>
themeData.textTheme.textStyle.copyWith(
fontSize: 14,
);

static TextStyle settingsItemSubtitleText(CupertinoThemeData themeData) =>
themeData.textTheme.textStyle.copyWith(
fontSize: 12,
Expand Down Expand Up @@ -206,7 +198,7 @@ abstract class Styles {
: CupertinoColors.darkBackgroundGray;

static Color settingsLineation(Brightness brightness) =>
brightness == Brightness.light ? Color(0xffbcbbc1) : Color(0xFF4C4B4B);
brightness == Brightness.light ? Color(0xffbcbbc1) : Color(0xff4c4b4b);

static const Color settingsBackground = Color(0xffefeff4);

Expand All @@ -222,6 +214,12 @@ abstract class Styles {
fontPackage: CupertinoIcons.iconFontPackage,
);

static const resetIcon = IconData(
0xf4c4,
fontFamily: CupertinoIcons.iconFont,
fontPackage: CupertinoIcons.iconFontPackage,
);

static const calorieIcon = IconData(
0xf3bb,
fontFamily: CupertinoIcons.iconFont,
Expand All @@ -238,5 +236,5 @@ abstract class Styles {

static const ColorFilter desaturatedColorFilter =
// 222222 is a random color that has low color saturation.
ColorFilter.mode(Color(0xFF222222), BlendMode.saturation);
ColorFilter.mode(Color(0xff222222), BlendMode.saturation);
}
72 changes: 0 additions & 72 deletions experimental/veggieseasons/lib/widgets/search_bar.dart

This file was deleted.

21 changes: 8 additions & 13 deletions testing_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ would do.
Show how to perform:

- Widget Testing,
- Flutter Driver(Integration) Testing,
- Integration Testing,
- Performance Testing, and
- State Management Testing using the [Provider][] package.

Expand All @@ -27,20 +27,15 @@ The Flutter SDK can run unit tests and widget tests in a virtual machine, withou
### To run tests on a physical device/emulator:
- Widget Tests:
- Run `flutter run test/<file_path>`
- Flutter Driver Tests:
- Run `flutter drive --target=test_driver/<file_path>`
- eg. `flutter drive --target=test_driver/app.dart` to run the test in `test_driver/app_test.dart`
- Integration Tests:
- Run `flutter drive --driver=integration_test/driver.dart --target=integration_test/app_test.dart`
- Performance Tests:
- Run `flutter drive --target=test_driver/app.dart --driver test_driver/perf_test.dart --profile --trace-startup`
- Run `flutter drive --driver=integration_test/driver.dart --target=integration_test/perf_test.dart --profile --trace-startup`
- Using a physical device and running performance tests in profile mode is recommended.
- The `--trace-startup` option is used to avoid flushing older timeline events when the timeline gets long.
- [E2E](https://pub.dev/packages/e2e) Tests:
- Run `flutter drive --target test/perf_test_e2e.dart --driver test_driver/e2e_test.dart --profile`
- Similar to the above but the test is driven on device.
- You may also reference [E2E manual](https://github.com/flutter/plugins/tree/master/packages/e2e#firebase-test-lab) for how to run such test on Firebase Test Lab.
- State Management Tests:
- For testing state using Flutter Driver
- Run `flutter drive --target=test_driver/<file_path>`
- For testing state using Flutter Integration Tests
- Run `flutter drive --driver=integration_test/driver.dart --target=integration_test/state_mgmt_test.dart`

### To generate test coverage report:
- Install the `lcov` tool:
Expand All @@ -53,9 +48,9 @@ The Flutter SDK can run unit tests and widget tests in a virtual machine, withou
- Open `coverage/index/index.html` in your preferred browser.

### CI/CD
- Refer [.travis.yml](../.travis.yml) and the [tool](../tool) directory to see how to test Flutter projects using Travis-CI.
- Refer [.github](../.github) and the [tool](../tool) directory to see how to test Flutter projects using GitHub Actions.

Note that we aren't performing Flutter Driver tests using the Travis tool in this repo. That is because it's recommended to use physical devices to run Driver tests. You can use [Firebase Test Lab](https://firebase.google.com/docs/test-lab), [Codemagic](https://codemagic.io/) or any platform of your choice to do that.
Note that tools like GitHub Actions can't run tests on a physical device, which is required to run integration tests. Instead, you can use [Firebase Test Lab](https://firebase.google.com/docs/test-lab), [Codemagic](https://docs.codemagic.io/testing/aws/) or any platform of your choice to do that.

## Questions/issues

Expand Down
Loading

0 comments on commit 9f6c7f5

Please sign in to comment.