-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[material_ui, cupertino_ui] Add a main example for the Pub Example tab #11896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0xharkirat
wants to merge
1
commit into
flutter:main
Choose a base branch
from
0xharkirat:decouple/pub-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:cupertino_ui/cupertino_ui.dart'; | ||
|
|
||
| void main() { | ||
| runApp(const CupertinoExampleApp()); | ||
| } | ||
|
|
||
| /// A small showcase app for the cupertino_ui package. | ||
| class CupertinoExampleApp extends StatefulWidget { | ||
| const CupertinoExampleApp({super.key}); | ||
|
|
||
| @override | ||
| State<CupertinoExampleApp> createState() => _CupertinoExampleAppState(); | ||
| } | ||
|
|
||
| class _CupertinoExampleAppState extends State<CupertinoExampleApp> { | ||
| // A null brightness follows the system setting. | ||
| Brightness? _brightness; | ||
|
|
||
| void _setBrightness(Brightness? brightness) { | ||
| setState(() { | ||
| _brightness = brightness; | ||
| }); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return CupertinoApp( | ||
| title: 'cupertino_ui example', | ||
| debugShowCheckedModeBanner: false, | ||
| theme: CupertinoThemeData(brightness: _brightness), | ||
| home: _HomeScreen( | ||
| brightness: _brightness, | ||
| onBrightnessChanged: _setBrightness, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class _HomeScreen extends StatefulWidget { | ||
| const _HomeScreen({ | ||
| required this.brightness, | ||
| required this.onBrightnessChanged, | ||
| }); | ||
|
|
||
| final Brightness? brightness; | ||
| final ValueChanged<Brightness?> onBrightnessChanged; | ||
|
|
||
| @override | ||
| State<_HomeScreen> createState() => _HomeScreenState(); | ||
| } | ||
|
|
||
| class _HomeScreenState extends State<_HomeScreen> { | ||
| bool _notificationsEnabled = true; | ||
| double _volume = 0.5; | ||
| final TextEditingController _nameController = TextEditingController(); | ||
|
|
||
| @override | ||
| void dispose() { | ||
| _nameController.dispose(); | ||
| super.dispose(); | ||
| } | ||
|
|
||
| Future<void> _showInfoDialog() { | ||
| return showCupertinoDialog<void>( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return CupertinoAlertDialog( | ||
| title: const Text('cupertino_ui'), | ||
| content: const Text( | ||
| 'The official Cupertino widget library for Flutter, as a ' | ||
| 'standalone package.', | ||
| ), | ||
| actions: <Widget>[ | ||
| CupertinoDialogAction( | ||
| isDefaultAction: true, | ||
| onPressed: () => Navigator.pop(context), | ||
| child: const Text('OK'), | ||
| ), | ||
| ], | ||
| ); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return CupertinoPageScaffold( | ||
| navigationBar: const CupertinoNavigationBar(middle: Text('cupertino_ui')), | ||
| child: SafeArea( | ||
| child: ListView( | ||
| children: <Widget>[ | ||
| CupertinoListSection.insetGrouped( | ||
| header: const Text('Appearance'), | ||
| children: <Widget>[ | ||
| Padding( | ||
| padding: const EdgeInsets.symmetric( | ||
| horizontal: 16, | ||
| vertical: 6, | ||
| ), | ||
| child: SizedBox( | ||
| width: double.infinity, | ||
| child: CupertinoSlidingSegmentedControl<int>( | ||
| groupValue: _brightnessToSegment(widget.brightness), | ||
| onValueChanged: (int? value) { | ||
| if (value != null) { | ||
| widget.onBrightnessChanged( | ||
| _segmentToBrightness(value), | ||
| ); | ||
| } | ||
| }, | ||
| children: const <int, Widget>{ | ||
| 0: _SegmentLabel('Auto'), | ||
| 1: _SegmentLabel('Light'), | ||
| 2: _SegmentLabel('Dark'), | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| CupertinoListSection.insetGrouped( | ||
| header: const Text('Controls'), | ||
| hasLeading: false, | ||
| children: <Widget>[ | ||
| CupertinoListTile( | ||
| title: const Text('Notifications'), | ||
| trailing: CupertinoSwitch( | ||
| value: _notificationsEnabled, | ||
| onChanged: (bool value) { | ||
| setState(() => _notificationsEnabled = value); | ||
| }, | ||
| ), | ||
| ), | ||
| CupertinoListTile( | ||
| title: const Text('Volume'), | ||
| subtitle: CupertinoSlider( | ||
| value: _volume, | ||
| onChanged: (double value) { | ||
| setState(() => _volume = value); | ||
| }, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| CupertinoListSection.insetGrouped( | ||
| header: const Text('Profile'), | ||
| children: <Widget>[ | ||
| CupertinoTextField.borderless( | ||
| controller: _nameController, | ||
| placeholder: 'Name', | ||
| padding: const EdgeInsets.all(16), | ||
| ), | ||
| ], | ||
| ), | ||
| Padding( | ||
| padding: const EdgeInsets.symmetric(horizontal: 16), | ||
| child: CupertinoButton.filled( | ||
| onPressed: _showInfoDialog, | ||
| child: const Text('About this package'), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| static int _brightnessToSegment(Brightness? brightness) { | ||
| return switch (brightness) { | ||
| null => 0, | ||
| Brightness.light => 1, | ||
| Brightness.dark => 2, | ||
| }; | ||
| } | ||
|
|
||
| static Brightness? _segmentToBrightness(int segment) { | ||
| return switch (segment) { | ||
| 1 => Brightness.light, | ||
| 2 => Brightness.dark, | ||
| _ => null, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| class _SegmentLabel extends StatelessWidget { | ||
| const _SegmentLabel(this.text); | ||
|
|
||
| final String text; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Padding( | ||
| padding: const EdgeInsets.symmetric(horizontal: 12), | ||
| child: Text(text), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:cupertino_ui/cupertino_ui.dart'; | ||
| import 'package:cupertino_ui_examples/main.dart' as example; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void main() { | ||
| testWidgets('renders the showcase components', (WidgetTester tester) async { | ||
| await tester.pumpWidget(const example.CupertinoExampleApp()); | ||
|
|
||
| expect(find.byType(CupertinoListSection), findsNWidgets(3)); | ||
| expect(find.byType(CupertinoSlidingSegmentedControl<int>), findsOneWidget); | ||
| expect(find.byType(CupertinoSwitch), findsOneWidget); | ||
| expect(find.byType(CupertinoSlider), findsOneWidget); | ||
| expect(find.byType(CupertinoTextField), findsOneWidget); | ||
| expect(tester.takeException(), isNull); | ||
| }); | ||
|
|
||
| testWidgets('changes brightness via the segmented control', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| await tester.pumpWidget(const example.CupertinoExampleApp()); | ||
|
|
||
| CupertinoApp app = tester.widget(find.byType(CupertinoApp)); | ||
| expect(app.theme?.brightness, isNull); | ||
|
|
||
| await tester.tap(find.text('Dark')); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| app = tester.widget(find.byType(CupertinoApp)); | ||
| expect(app.theme?.brightness, Brightness.dark); | ||
| }); | ||
|
|
||
| testWidgets('opens and dismisses the info dialog', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| await tester.pumpWidget(const example.CupertinoExampleApp()); | ||
|
|
||
| await tester.tap(find.text('About this package')); | ||
| await tester.pumpAndSettle(); | ||
| expect(find.byType(CupertinoAlertDialog), findsOneWidget); | ||
|
|
||
| await tester.tap(find.text('OK')); | ||
| await tester.pumpAndSettle(); | ||
| expect(find.byType(CupertinoAlertDialog), findsNothing); | ||
| }); | ||
|
|
||
| testWidgets('toggles the notifications switch', (WidgetTester tester) async { | ||
| await tester.pumpWidget(const example.CupertinoExampleApp()); | ||
|
|
||
| CupertinoSwitch toggle = tester.widget(find.byType(CupertinoSwitch)); | ||
| expect(toggle.value, isTrue); | ||
|
|
||
| await tester.tap(find.byType(CupertinoSwitch)); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| toggle = tester.widget(find.byType(CupertinoSwitch)); | ||
| expect(toggle.value, isFalse); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.