-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
71 lines (61 loc) · 1.93 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2021 anaurelian. All rights reserved.
// https://anaurelian.com
//
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
import 'dart:math';
import 'package:blobs/blobs.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyTestApp());
}
class MyTestApp extends StatelessWidget {
const MyTestApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Blobs Duration Test',
theme: ThemeData(
primarySwatch: Colors.blueGrey,
),
home: const HomeScreen(),
);
}
}
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
final Random _random = Random();
Color _color = Colors.blueGrey;
// The duration of the animated blob seems to be stuck to this initial value, even if we change it using setState.
int _duration = 500;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Duration: $_duration milliseconds'), // display the current duration
),
body: Blob.animatedRandom(
size: 400,
edgesCount: 6,
minGrowth: 7,
// Apply the current color - this works.
styles: BlobStyles(color: _color),
loop: true,
// Apply the current duration - doesn't seem to work!
duration: Duration(milliseconds: _duration),
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.shuffle),
onPressed: () => setState(() {
// Randomize the duration and the color
_duration = _random.nextInt(20) * 500;
_color = Color.fromRGBO(_random.nextInt(256), _random.nextInt(256), _random.nextInt(256), 1.0);
}),
),
);
}
}