I am attempting to run a easy timer utilizing the timer_controller and timer_count_down libraries. I might just like the maintain the buttons in a separate file with a view to maintain the code clear, nevertheless when operating the primary app, the buttons not management the timer. I might prefer to know ‘import’ these capabilities so to talk.
I’ve searched a couple of methods and located quite a few sources, for instance utilizing
import ‘bundle:pattern/world.dart’; nevertheless, this did not appear to exist when coming into it into the dart file.
Web page 1:
import 'bundle:flutter/materials.dart';
import 'bundle:timer_app/util/buttons.dart';
import 'bundle:timer_count_down/timer_controller.dart';
import 'bundle:timer_count_down/timer_count_down.dart';
class TimerTile extends StatefulWidget {
const TimerTile({tremendous.key});
@override
State<TimerTile> createState() => _TimerTilesState();
}
class _TimerTilesState extends State<TimerTile> {
remaining CountdownController _controller =
new CountdownController(autoStart: false);
@override
Widget construct(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.heart,
crossAxisAlignment: CrossAxisAlignment.heart,
kids: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: MyButtons(),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: Countdown(
controller: _controller,
seconds: 5,
build: (_, double time) => Text(
time.toString(),
style: TextStyle(
fontSize: 100,
),
)))
]);
}
}
Web page 2
import 'bundle:flutter/materials.dart';
import 'bundle:timer_count_down/timer_controller.dart';
import 'bundle:timer_count_down/timer_count_down.dart';
class MyButtons extends StatefulWidget {
const MyButtons({tremendous.key});
@override
State<MyButtons> createState() => _MyButtonsState();
}
class _MyButtonsState extends State<MyButtons> {
remaining CountdownController _controller =
new CountdownController(autoStart: false);
@override
Widget construct(BuildContext context) {
return Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, kids: [
ElevatedButton(
onPressed: () {
_controller.start();
},
child: Text('Start')),
ElevatedButton(
onPressed: () {
_controller.pause();
},
child: Text('Pause')),
ElevatedButton(
onPressed: () {
_controller.resume();
},
child: Text('Resume')),
ElevatedButton(
onPressed: () {
_controller.restart();
},
child: Text('Restart'))
]);
;
}
}