• Source
    1. import 'package:flutter/material.dart';
    2.  
    3. class OpacityPage extends StatefulWidget {
    4. @override
    5. State<StatefulWidget> createState() => OpacityPageState();
    6. }
    7.  
    8. class OpacityPageState extends State<OpacityPage> {
    9. @override
    10. Widget build(BuildContext context) {
    11. return Scaffold(
    12. appBar: new AppBar(title: Text('Opacity')),
    13. body: Container(
    14. padding: EdgeInsets.all(8),
    15. color: Colors.amber,
    16. child: Row(
    17. children: <Widget>[
    18. Expanded(
    19. child: Container(
    20. color: Colors.greenAccent,
    21. child: Align(
    22. heightFactor: 1,
    23. child: Text(
    24. '生活文化',
    25. style: TextStyle(color: Colors.white),
    26. ),
    27. ),
    28. padding: EdgeInsets.all(8),
    29. ),
    30. ),
    31. Expanded(
    32. flex: 2,
    33. child: Opacity(
    34. opacity: 1.0, //在這裡改變這個方塊的透明度
    35. child: Container(
    36. color: Colors.redAccent,
    37. child: Align(
    38. heightFactor: 1,
    39. child: Text(
    40. '疫情專區',
    41. style: TextStyle(color: Colors.white),
    42. ),
    43. ),
    44. padding: EdgeInsets.all(8),
    45. ),
    46. ),
    47. ),
    48. Expanded(
    49. child: Container(
    50. color: Colors.blueAccent,
    51. child: Align(
    52. heightFactor: 1,
    53. child: Text(
    54. '國際政治',
    55. style: TextStyle(color: Colors.white),
    56. ),
    57. ),
    58. padding: EdgeInsets.all(8),
    59. ),
    60. ),
    61. ],
    62. ),
    63. ),
    64. );
    65. }
    66. }
    67.