File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [MaterialApp] .
8+
9+ class MaterialAppExample extends StatelessWidget {
10+ const MaterialAppExample ({super .key});
11+
12+ @override
13+ Widget build (BuildContext context) {
14+ return
15+ // #region body
16+ MaterialApp (
17+ home: Scaffold (appBar: AppBar (title: const Text ('Home' ))),
18+ debugShowCheckedModeBanner: false ,
19+ )
20+ // #endregion body
21+ ;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [MaterialApp] .
8+
9+ class MaterialAppExample extends StatelessWidget {
10+ const MaterialAppExample ({super .key});
11+
12+ @override
13+ Widget build (BuildContext context) {
14+ return
15+ // #region body
16+ MaterialApp (
17+ routes: < String , WidgetBuilder > {
18+ '/' : (BuildContext context) {
19+ return Scaffold (appBar: AppBar (title: const Text ('Home Route' )));
20+ },
21+ '/about' : (BuildContext context) {
22+ return Scaffold (appBar: AppBar (title: const Text ('About Route' )));
23+ },
24+ },
25+ )
26+ // #endregion body
27+ ;
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [MaterialApp] .
8+
9+ class MaterialAppExample extends StatelessWidget {
10+ const MaterialAppExample ({super .key});
11+
12+ @override
13+ Widget build (BuildContext context) {
14+ return
15+ // #region body
16+ MaterialApp (
17+ theme: ThemeData (
18+ brightness: Brightness .dark,
19+ primaryColor: Colors .blueGrey,
20+ ),
21+ home: Scaffold (appBar: AppBar (title: const Text ('MaterialApp Theme' ))),
22+ )
23+ // #endregion body
24+ ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter/services.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+
8+ /// Flutter code sample for [MaterialApp.shortcuts] .
9+
10+ class MaterialAppExample extends StatelessWidget {
11+ const MaterialAppExample ({super .key});
12+
13+ // #region body
14+ @override
15+ Widget build (BuildContext context) {
16+ return WidgetsApp (
17+ shortcuts: < ShortcutActivator , Intent > {
18+ ...WidgetsApp .defaultShortcuts,
19+ const SingleActivator (LogicalKeyboardKey .keyE): const ActivateIntent (),
20+ },
21+ color: const Color (0xFFFF0000 ),
22+ builder: (BuildContext context, Widget ? child) {
23+ return const Placeholder ();
24+ },
25+ );
26+ }
27+ // #endregion body
28+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:material_ui/material_ui.dart' ;
6+
7+ /// Flutter code sample for [MaterialApp.actions] .
8+
9+ class MaterialAppExample extends StatelessWidget {
10+ const MaterialAppExample ({super .key, this .onActivated});
11+
12+ final VoidCallback ? onActivated;
13+
14+ // #region body
15+ @override
16+ Widget build (BuildContext context) {
17+ return WidgetsApp (
18+ actions: < Type , Action <Intent >> {
19+ ...WidgetsApp .defaultActions,
20+ ActivateIntent : CallbackAction <Intent >(
21+ onInvoke: (Intent intent) {
22+ // Do something here...
23+ onActivated? .call ();
24+ return null ;
25+ },
26+ ),
27+ },
28+ color: const Color (0xFFFF0000 ),
29+ builder: (BuildContext context, Widget ? child) {
30+ return const Placeholder ();
31+ },
32+ );
33+ }
34+ // #endregion body
35+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/app/app.snippet.0.dart' as example;
8+
9+ void main () {
10+ testWidgets (
11+ 'MaterialApp displays home route and disables debug mode banner' ,
12+ (WidgetTester tester) async {
13+ await tester.pumpWidget (const example.MaterialAppExample ());
14+
15+ expect (find.byType (CheckedModeBanner ), findsNothing);
16+ expect (find.widgetWithText (AppBar , 'Home' ), findsOneWidget);
17+ },
18+ );
19+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/app/app.snippet.1.dart' as example;
8+
9+ void main () {
10+ testWidgets ('MaterialApp routes map navigates between Home and About' , (
11+ WidgetTester tester,
12+ ) async {
13+ await tester.pumpWidget (const example.MaterialAppExample ());
14+
15+ expect (find.widgetWithText (AppBar , 'Home Route' ), findsOneWidget);
16+ expect (find.widgetWithText (AppBar , 'About Route' ), findsNothing);
17+
18+ final BuildContext context = tester.element (find.text ('Home Route' ));
19+ Navigator .of (context).pushNamed ('/about' );
20+ await tester.pumpAndSettle ();
21+
22+ expect (find.widgetWithText (AppBar , 'About Route' ), findsOneWidget);
23+ });
24+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter_test/flutter_test.dart' ;
6+ import 'package:material_ui/material_ui.dart' ;
7+ import 'package:material_ui_examples/app/app.snippet.2.dart' as example;
8+
9+ void main () {
10+ testWidgets ('MaterialApp applies custom ThemeData' , (
11+ WidgetTester tester,
12+ ) async {
13+ await tester.pumpWidget (const example.MaterialAppExample ());
14+
15+ expect (find.widgetWithText (AppBar , 'MaterialApp Theme' ), findsOneWidget);
16+
17+ final BuildContext context = tester.element (find.text ('MaterialApp Theme' ));
18+ final ThemeData theme = Theme .of (context);
19+ expect (theme.brightness, Brightness .dark);
20+ expect (theme.primaryColor, Colors .blueGrey);
21+ });
22+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter/services.dart' ;
6+ import 'package:flutter_test/flutter_test.dart' ;
7+ import 'package:material_ui/material_ui.dart' ;
8+ import 'package:material_ui_examples/app/app.snippet.3.dart' as example;
9+
10+ void main () {
11+ testWidgets ('WidgetsApp shortcuts maps select key to ActivateIntent' , (
12+ WidgetTester tester,
13+ ) async {
14+ bool invoked = false ;
15+ await tester.pumpWidget (
16+ Actions (
17+ actions: < Type , Action <Intent >> {
18+ ActivateIntent : CallbackAction <ActivateIntent >(
19+ onInvoke: (ActivateIntent intent) {
20+ invoked = true ;
21+ return null ;
22+ },
23+ ),
24+ },
25+ child: const example.MaterialAppExample (),
26+ ),
27+ );
28+
29+ final Element placeholderElement = tester.element (find.byType (Placeholder ));
30+ final FocusNode focusNode = Focus .of (placeholderElement);
31+ focusNode.canRequestFocus = true ;
32+ focusNode.requestFocus ();
33+ await tester.pump ();
34+
35+ await tester.sendKeyEvent (LogicalKeyboardKey .keyE);
36+ expect (invoked, isTrue);
37+ });
38+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2013 The Flutter Authors
2+ // Use of this source code is governed by a BSD-style license that can be
3+ // found in the LICENSE file.
4+
5+ import 'package:flutter/services.dart' ;
6+ import 'package:flutter_test/flutter_test.dart' ;
7+ import 'package:material_ui/material_ui.dart' ;
8+ import 'package:material_ui_examples/app/app.snippet.4.dart' as example;
9+
10+ void main () {
11+ testWidgets ('WidgetsApp actions handles ActivateIntent' , (
12+ WidgetTester tester,
13+ ) async {
14+ bool activated = false ;
15+ await tester.pumpWidget (
16+ example.MaterialAppExample (
17+ onActivated: () {
18+ activated = true ;
19+ },
20+ ),
21+ );
22+
23+ final Element placeholderElement = tester.element (find.byType (Placeholder ));
24+ final FocusNode focusNode = Focus .of (placeholderElement);
25+ focusNode.canRequestFocus = true ;
26+ focusNode.requestFocus ();
27+ await tester.pump ();
28+
29+ await tester.sendKeyEvent (LogicalKeyboardKey .space);
30+ expect (activated, isTrue);
31+ });
32+ }
You can’t perform that action at this time.
0 commit comments