From f35b3806bb5e5757cbd6e75f2ae84b4062ca8d15 Mon Sep 17 00:00:00 2001 From: Maheen Ilyas Date: Wed, 22 May 2024 11:06:26 +0300 Subject: [PATCH] Added flower model to models --- lib/models/flower_model.dart | 13 +++++++ lib/pages/modules/flowers.dart | 69 ++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 lib/models/flower_model.dart diff --git a/lib/models/flower_model.dart b/lib/models/flower_model.dart new file mode 100644 index 0000000..7fe4d6e --- /dev/null +++ b/lib/models/flower_model.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class Flower { + final String name; + final String resource; + final Color background; + + Flower({ + required this.name, + required this.resource, + required this.background, + }); +} diff --git a/lib/pages/modules/flowers.dart b/lib/pages/modules/flowers.dart index 41aa7f5..61f4a92 100644 --- a/lib/pages/modules/flowers.dart +++ b/lib/pages/modules/flowers.dart @@ -1,18 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_tts/flutter_tts.dart'; +import 'package:learn/models/flower_model.dart'; import 'package:learn/utils/assets_path.dart'; - -class Flower{ - final String name; - final String resource; - final Color background; - - Flower({required this.name,required this.resource,required this.background}); -} - - class FlowerPage extends StatefulWidget { const FlowerPage({super.key}); @@ -21,26 +12,56 @@ class FlowerPage extends StatefulWidget { } class _FlowerPageState extends State { - final List flowers = [ - Flower(name: "Rose", resource: AssetsPath.getFlowerImage(Flowers.rose), background: Colors.redAccent), - Flower(name: "Sunflower", resource: AssetsPath.getFlowerImage(Flowers.sunflower), background: Colors.yellowAccent), - Flower(name: "Lily", resource: AssetsPath.getFlowerImage(Flowers.lily), background: Colors.greenAccent), - Flower(name: "Marigold", resource: AssetsPath.getFlowerImage(Flowers.marigold), background: Colors.yellow), - Flower(name: "Carnation", resource: AssetsPath.getFlowerImage(Flowers.carnation), background: Colors.redAccent), - Flower(name: "Daffodil", resource: AssetsPath.getFlowerImage(Flowers.daffodil), background: Colors.purpleAccent), - Flower(name: "Daisy", resource: AssetsPath.getFlowerImage(Flowers.daisy), background: Colors.green), - Flower(name: "Poppy", resource: AssetsPath.getFlowerImage(Flowers.poppy), background: Colors.redAccent), - Flower(name: "Tulip", resource: AssetsPath.getFlowerImage(Flowers.tulip), background: Colors.pink), - Flower(name: "Lavender", resource: AssetsPath.getFlowerImage(Flowers.lavender), background: Colors.purple), - Flower(name: "Hibiscus", resource: AssetsPath.getFlowerImage(Flowers.hibiscus), background: Colors.red), - + Flower( + name: "Rose", + resource: AssetsPath.getFlowerImage(Flowers.rose), + background: Colors.redAccent), + Flower( + name: "Sunflower", + resource: AssetsPath.getFlowerImage(Flowers.sunflower), + background: Colors.yellowAccent), + Flower( + name: "Lily", + resource: AssetsPath.getFlowerImage(Flowers.lily), + background: Colors.greenAccent), + Flower( + name: "Marigold", + resource: AssetsPath.getFlowerImage(Flowers.marigold), + background: Colors.yellow), + Flower( + name: "Carnation", + resource: AssetsPath.getFlowerImage(Flowers.carnation), + background: Colors.redAccent), + Flower( + name: "Daffodil", + resource: AssetsPath.getFlowerImage(Flowers.daffodil), + background: Colors.purpleAccent), + Flower( + name: "Daisy", + resource: AssetsPath.getFlowerImage(Flowers.daisy), + background: Colors.green), + Flower( + name: "Poppy", + resource: AssetsPath.getFlowerImage(Flowers.poppy), + background: Colors.redAccent), + Flower( + name: "Tulip", + resource: AssetsPath.getFlowerImage(Flowers.tulip), + background: Colors.pink), + Flower( + name: "Lavender", + resource: AssetsPath.getFlowerImage(Flowers.lavender), + background: Colors.purple), + Flower( + name: "Hibiscus", + resource: AssetsPath.getFlowerImage(Flowers.hibiscus), + background: Colors.red), ]; final FlutterTts flutterTts = FlutterTts(); int currentIndex = 0; - void _navigateToNextFlower() { setState(() { currentIndex = (currentIndex + 1) % flowers.length;