forked from firka/flutter
Add CupertinoButton interactive example (#93625)
This commit is contained in:
57
examples/api/lib/cupertino/button/cupertino_button.0.dart
Normal file
57
examples/api/lib/cupertino/button/cupertino_button.0.dart
Normal file
@@ -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: <Widget>[
|
||||
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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
});
|
||||
}
|
||||
@@ -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:
|
||||
///
|
||||
/// * <https://developer.apple.com/ios/human-interface-guidelines/controls/buttons/>
|
||||
|
||||
Reference in New Issue
Block a user