Add Material 3 FloatingActionButton and FloatingActionButton variants examples (#101105)
This commit is contained in:
@@ -11,25 +11,22 @@ 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 MaterialApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
home: FabExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({Key? key}) : super(key: key);
|
||||
class FabExample extends StatelessWidget {
|
||||
const FabExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Floating Action Button'),
|
||||
title: const Text('FloatingActionButton Sample'),
|
||||
),
|
||||
body: const Center(child: Text('Press the button below!')),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
|
||||
@@ -11,25 +11,22 @@ 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 MaterialApp(
|
||||
title: _title,
|
||||
home: MyStatelessWidget(),
|
||||
home: FabExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyStatelessWidget extends StatelessWidget {
|
||||
const MyStatelessWidget({Key? key}) : super(key: key);
|
||||
class FabExample extends StatelessWidget {
|
||||
const FabExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Floating Action Button Label'),
|
||||
title: const Text('FloatingActionButton Sample'),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('Press the button with a label below!'),
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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 FloatingActionButton
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
|
||||
home: const FabExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FabExample extends StatelessWidget {
|
||||
const FabExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('FloatingActionButton Sample'),
|
||||
),
|
||||
body: const Center(child: Text('Press the button below!')),
|
||||
// An example of the floating action button.
|
||||
//
|
||||
// https://m3.material.io/components/floating-action-button/specs
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
// Add your onPressed code here!
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// 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 FloatingActionButton
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
|
||||
home: const FabExample(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FabExample extends StatelessWidget {
|
||||
const FabExample({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('FloatingActionButton Sample'),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text('Small'),
|
||||
const SizedBox(width: 16),
|
||||
// An example of the small floating action button.
|
||||
//
|
||||
// https://m3.material.io/components/floating-action-button/specs#669a1be8-7271-48cb-a74d-dd502d73bda4
|
||||
FloatingActionButton.small(
|
||||
onPressed: () {
|
||||
// Add your onPressed code here!
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text('Regular'),
|
||||
const SizedBox(width: 16),
|
||||
// An example of the regular floating action button.
|
||||
//
|
||||
// https://m3.material.io/components/floating-action-button/specs#71504201-7bd1-423d-8bb7-07e0291743e5
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
// Add your onPressed code here!
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text('Large'),
|
||||
const SizedBox(width: 16),
|
||||
// An example of the large floating action button.
|
||||
//
|
||||
// https://m3.material.io/components/floating-action-button/specs#9d7d3d6a-bab7-47cb-be32-5596fbd660fe
|
||||
FloatingActionButton.large(
|
||||
onPressed: () {
|
||||
// Add your onPressed code here!
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text('Extended'),
|
||||
const SizedBox(width: 16),
|
||||
// An example of the extended floating action button.
|
||||
//
|
||||
// https://m3.material.io/components/extended-fab/specs#686cb8af-87c9-48e8-a3e1-db9da6f6c69b
|
||||
FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
// Add your onPressed code here!
|
||||
},
|
||||
label: const Text('Add'),
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user