diff --git a/lib/screens/rain_radar.dart b/lib/screens/rain_radar.dart index 6b7f208..25a03ed 100644 --- a/lib/screens/rain_radar.dart +++ b/lib/screens/rain_radar.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -// ignore: import_of_legacy_library_into_null_safe import 'package:flutter_gifimage/flutter_gifimage.dart'; class RainRadar extends StatefulWidget { @@ -12,33 +11,50 @@ class RainRadar extends StatefulWidget { class _RainRadarState extends State with SingleTickerProviderStateMixin { late GifController controller; + double controllerValue = 0; @override void initState() { super.initState(); controller = GifController(vsync: this); + controller.addListener(() { + setState(() { + controllerValue = controller.value; + }); + }); WidgetsBinding.instance.addPostFrameCallback((_) { - controller.repeat(min: 0, max: 24, period: const Duration(seconds: 10)); + controller.animateTo(24, duration: const Duration(seconds: 10)); }); } @override Widget build(BuildContext context) { - controller.stop(); return Scaffold( appBar: AppBar( title: const Text('Rain Radar'), ), body: Column(children: [ - GifImage( - controller: controller, - image: const NetworkImage( - 'https://www.dwd.de/DWD/wetter/radar/radarvhs.gif')), - ElevatedButton( - onPressed: () { - controller.stop(); - }, - child: const Text("Stop")), + Padding( + padding: const EdgeInsets.all(10), + child: GifImage( + controller: controller, + image: const NetworkImage( + 'https://www.dwd.de/DWD/wetter/radar/radarvhs.gif'))), + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + ElevatedButton( + onPressed: () { + int duration = ((10 / 24) * (24 - controller.value)).round(); + controller.animateTo(24, + duration: Duration(seconds: duration)); + }, + child: const Icon(Icons.play_arrow)), + const SizedBox(width: 10), + ElevatedButton( + onPressed: () { + controller.stop(); + }, + child: const Icon(Icons.pause)), + ]), Slider( onChanged: (v) { controller.value = v; @@ -46,7 +62,7 @@ class _RainRadarState extends State }, max: 24, min: 0, - value: controller.value, + value: controllerValue, ) ])); } diff --git a/pubspec.lock b/pubspec.lock index ca7ca55..d4b061f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -79,9 +79,9 @@ packages: flutter_gifimage: dependency: "direct main" description: - name: flutter_gifimage - url: "https://pub.dartlang.org" - source: hosted + path: "../flutter_gifimage-1.0.1" + relative: true + source: path version: "1.0.1" flutter_lints: dependency: "direct dev" diff --git a/pubspec.yaml b/pubspec.yaml index bbf622d..fd3189e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -30,7 +30,6 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 @@ -38,7 +37,8 @@ dependencies: weather_icons: ^3.0.0 intl: ^0.17.0 shared_preferences: ^2.0.15 - flutter_gifimage: ^1.0.1 + flutter_gifimage: + path: ../flutter_gifimage-1.0.1 dev_dependencies: flutter_test: @@ -56,7 +56,6 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class.