1. //
    2. // Stack 这个相当于 web 的父元素
    3. // Positioned 这个相当于 web 的子元素 x和y轴一般只设置一个方向
    4. // 如果同时设置了left和right 会出现元素被拉伸的情况
    5. // 也可以只设置一个方向 那另一个方向会默认使用 Stack 的 alignment 属性
    6. // 如果两个子元素有相交的地方,则会产生重叠
    7. import 'package:flutter/cupertino.dart';
    8. import 'package:flutter/material.dart';
    9. // import 'package:english_words/english_words.dart';
    10. void main() => runApp(new MyApp());
    11. class MyApp extends StatelessWidget {
    12. @override
    13. Widget build(BuildContext context) {
    14. return new MaterialApp(
    15. title: 'Welcome to Flutter',
    16. home: new Scaffold(
    17. appBar: new AppBar(
    18. title: new Text('Welcome to Flutter12'),
    19. ),
    20. body: Container(
    21. child: SizedBox(
    22. width: 400,
    23. height: 400,
    24. child: Stack(
    25. alignment: Alignment.center,
    26. children: [
    27. Positioned(
    28. bottom: 20,
    29. left: 20,
    30. child: Container(
    31. width: 100,
    32. height: 100,
    33. color: Colors.red,
    34. ),
    35. ),
    36. Positioned(
    37. top: 10,
    38. right: 10,
    39. child: Container(
    40. width: 200,
    41. height: 200,
    42. color: Colors.blue,
    43. ),
    44. ),
    45. ],
    46. ),
    47. ),
    48. ),
    49. ),
    50. );
    51. }
    52. }