-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
184 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
mixin _RandomColor { | ||
static final Random _random = Random(); | ||
|
||
/// Returns a random color. | ||
static Color next() { | ||
return Color(0xFF000000 + _random.nextInt(0x00FFFFFF)); | ||
} | ||
} | ||
|
||
/// A Container Widget that takes up a given [width] and [height] and paints itself with a | ||
/// random color. | ||
class VxRandomBox extends StatefulWidget { | ||
final double width; | ||
final double height; | ||
final Widget child; | ||
final bool changeOnRedraw; | ||
|
||
const VxRandomBox( | ||
{this.width, this.height, this.child, this.changeOnRedraw = true}); | ||
|
||
@override | ||
_VxRandomBoxState createState() => _VxRandomBoxState(); | ||
} | ||
|
||
class _VxRandomBoxState extends State<VxRandomBox> { | ||
Color _randomColor; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_randomColor = _RandomColor.next(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
width: widget.width, | ||
height: widget.height, | ||
color: widget.changeOnRedraw == true ? _RandomColor.next() : _randomColor, | ||
child: widget.child, | ||
); | ||
} | ||
} | ||
|
||
extension RandomContainerWidgetExtension on Widget { | ||
VxRandomBox randomBox( | ||
{double width, double height, bool changeOnRedraw = true}) => | ||
VxRandomBox( | ||
child: this, | ||
height: height, | ||
width: width, | ||
changeOnRedraw: changeOnRedraw, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.