briks.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import 'package:flutter/material.dart';
  2. const _COLOR_NORMAL = Colors.black87;
  3. const _COLOR_NULL = Colors.black12;
  4. const _COLOR_HIGHLIGHT = Color(0xFF560000);
  5. class BrikSize extends InheritedWidget {
  6. const BrikSize({
  7. Key key,
  8. @required this.size,
  9. @required Widget child,
  10. }) : assert(child != null),
  11. super(key: key, child: child);
  12. final Size size;
  13. static BrikSize of(BuildContext context) {
  14. final brikSize = context.inheritFromWidgetOfExactType(BrikSize) as BrikSize;
  15. assert(brikSize != null, "....");
  16. return brikSize;
  17. }
  18. @override
  19. bool updateShouldNotify(BrikSize old) {
  20. return old.size != size;
  21. }
  22. }
  23. ///the basic brik for game panel
  24. class Brik extends StatelessWidget {
  25. final Color color;
  26. const Brik._({Key key, this.color}) : super(key: key);
  27. const Brik.normal() : this._(color: _COLOR_NORMAL);
  28. const Brik.empty() : this._(color: _COLOR_NULL);
  29. const Brik.highlight() : this._(color: _COLOR_HIGHLIGHT);
  30. @override
  31. Widget build(BuildContext context) {
  32. final width = BrikSize.of(context).size.width;
  33. return SizedBox.fromSize(
  34. size: BrikSize.of(context).size,
  35. child: Container(
  36. margin: EdgeInsets.all(0.05 * width),
  37. padding: EdgeInsets.all(0.1 * width),
  38. decoration:
  39. BoxDecoration(border: Border.all(width: 0.10 * width, color: color)),
  40. child: Container(
  41. color: color,
  42. ),
  43. ),
  44. );
  45. }
  46. }