image.png

    1. import 'package:flutter/material.dart';
    2. main() => runApp(MyApp());
    3. class MyApp extends StatelessWidget {
    4. @override
    5. Widget build(BuildContext context) {
    6. return MaterialApp(
    7. home: HomePage(),
    8. );
    9. }
    10. }
    11. class HomePage extends StatelessWidget {
    12. @override
    13. Widget build(BuildContext context) {
    14. print("call HomePage build");
    15. return Scaffold(
    16. appBar: AppBar(
    17. title: Text("商品列表"),
    18. ),
    19. body: HomeContent(),
    20. // 右下角按钮
    21. floatingActionButton: FloatingActionButton(
    22. child: Icon(Icons.add),
    23. onPressed: () => print("clicked"),
    24. ),
    25. );
    26. }
    27. }
    28. class HomeContent extends StatefulWidget {
    29. @override
    30. _HomeContentState createState() => _HomeContentState();
    31. }
    32. class _HomeContentState extends State<HomeContent> {
    33. @override
    34. Widget build(BuildContext context) {
    35. return Column(
    36. children: [
    37. // 其它按钮
    38. ElevatedButton(
    39. onPressed: () => {print("ElevatedButton")},
    40. child: Text("ElevatedButton")),
    41. TextButton(
    42. onPressed: () => {print("TextButton")}, child: Text("TextButton")),
    43. OutlinedButton(
    44. onPressed: () => {print("OutlinedButton")},
    45. child: Text("OutlinedButton")),
    46. // 自定义按钮
    47. TextButton(
    48. style: ButtonStyle(
    49. backgroundColor: MaterialStateProperty.all(Colors.amberAccent),
    50. // 背景色
    51. shape: MaterialStateProperty.all<OutlinedBorder>(
    52. RoundedRectangleBorder(
    53. borderRadius: BorderRadius.circular(10)))),
    54. onPressed: () {},
    55. child: Row(
    56. mainAxisSize: MainAxisSize.min,
    57. children: [
    58. Icon(
    59. Icons.favorite,
    60. color: Colors.red,
    61. ),
    62. Text("喜欢作者")
    63. ],
    64. ),
    65. )
    66. ],
    67. );
    68. }
    69. }