直接row包装

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. // This widget is the root of your application.
  5. @override
  6. Widget build(BuildContext context) {
  7. return MaterialApp(
  8. title: 'Flutter Demo',
  9. theme: ThemeData(
  10. primarySwatch: Colors.blue,
  11. ),
  12. home: Scaffold(
  13. appBar: new AppBar(title: new Text ('row 水平布局')),
  14. body: new Row(
  15. children: <Widget>[
  16. new RaisedButton( //按钮
  17. onPressed: (){},
  18. color: Colors.redAccent,
  19. child: new Text('red button'),
  20. ),
  21. new RaisedButton( //按钮
  22. onPressed: (){},
  23. color: Colors.blueAccent,
  24. child: new Text('blue button'),
  25. ),
  26. new RaisedButton( //按钮
  27. onPressed: (){},
  28. color: Colors.lightBlue,
  29. child: new Text('lightBlue button'),
  30. ),
  31. ],
  32. )
  33. )
  34. );
  35. }
  36. }

image.png

使用expanded 包装 填满水平 灵活布局

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. class MyApp extends StatelessWidget {
  4. // This widget is the root of your application.
  5. @override
  6. Widget build(BuildContext context) {
  7. return MaterialApp(
  8. title: 'Flutter Demo',
  9. theme: ThemeData(
  10. primarySwatch: Colors.blue,
  11. ),
  12. home: Scaffold(
  13. appBar: new AppBar(title: new Text ('row 水平布局')),
  14. body: new Row(
  15. children: <Widget>[
  16. Expanded(
  17. child: new RaisedButton( //按钮
  18. onPressed: (){},
  19. color: Colors.yellowAccent,
  20. child: new Text('yellow button'),
  21. ),
  22. ),
  23. Expanded(
  24. child: new RaisedButton( //按钮
  25. onPressed: (){},
  26. color: Colors.redAccent,
  27. child: new Text('red button'),
  28. ),
  29. ),
  30. Expanded(
  31. child: new RaisedButton( //按钮
  32. onPressed: (){},
  33. color: Colors.lightBlue,
  34. child: new Text('lightBlue button'),
  35. ),
  36. ),
  37. ],
  38. )
  39. )
  40. );
  41. }
  42. }

image.png