diff --git a/examples/api/lib/cupertino/button/cupertino_button.0.dart b/examples/api/lib/cupertino/button/cupertino_button.0.dart new file mode 100644 index 0000000000..6b82b26e39 --- /dev/null +++ b/examples/api/lib/cupertino/button/cupertino_button.0.dart @@ -0,0 +1,57 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flutter code sample for CupertinoButton + +import 'package:flutter/cupertino.dart'; + +void main() => runApp(const MyApp()); + +class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + + static const String _title = 'Flutter Code Sample'; + + @override + Widget build(BuildContext context) { + return const CupertinoApp( + title: _title, + home: MyStatelessWidget(), + ); + } +} + +class MyStatelessWidget extends StatelessWidget { + const MyStatelessWidget({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const CupertinoButton( + onPressed: null, + child: Text('Disabled'), + ), + const SizedBox(height: 30), + const CupertinoButton.filled( + onPressed: null, + child: Text('Disabled'), + ), + const SizedBox(height: 30), + CupertinoButton( + onPressed: () {}, + child: const Text('Enabled'), + ), + const SizedBox(height: 30), + CupertinoButton.filled( + onPressed: () {}, + child: const Text('Enabled'), + ), + ], + ), + ); + } +} diff --git a/examples/api/test/cupertino/button/cupertino_button.0_test.dart b/examples/api/test/cupertino/button/cupertino_button.0_test.dart new file mode 100644 index 0000000000..9d9397e3b9 --- /dev/null +++ b/examples/api/test/cupertino/button/cupertino_button.0_test.dart @@ -0,0 +1,19 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/cupertino.dart'; +import 'package:flutter_api_samples/cupertino/button/cupertino_button.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Has 4 CupertinoButton variants', (WidgetTester tester) async { + await tester.pumpWidget( + const example.MyApp(), + ); + + expect(find.byType(CupertinoButton), findsNWidgets(4)); + expect(find.ancestor(of: find.text('Enabled'), matching: find.byType(CupertinoButton)), findsNWidgets(2)); + expect(find.ancestor(of: find.text('Disabled'), matching: find.byType(CupertinoButton)), findsNWidgets(2)); + }); +} diff --git a/packages/flutter/lib/src/cupertino/button.dart b/packages/flutter/lib/src/cupertino/button.dart index 10a6dbdd60..57e3139fa9 100644 --- a/packages/flutter/lib/src/cupertino/button.dart +++ b/packages/flutter/lib/src/cupertino/button.dart @@ -26,6 +26,13 @@ const EdgeInsets _kBackgroundButtonPadding = EdgeInsets.symmetric( /// [EdgeInsets.zero], should be used to prevent clipping larger [child] /// widgets. /// +/// {@tool dartpad} +/// This sample shows produces an enabled and disabled [CupertinoButton] and +/// [CupertinoButton.filled]. +/// +/// ** See code in examples/api/lib/cupertino/button/cupertino_button.0.dart ** +/// {@end-tool} +/// /// See also: /// /// *