├── README.md ├── multiplatform ├── device_enum.dart ├── check_device.dart ├── page_transformers.dart ├── news_model.dart ├── news_layout.dart └── main.dart ├── hero-2024 ├── main.dart ├── model │ ├── product_response.dart │ ├── review.dart │ └── product.dart ├── product_details.dart └── home.dart ├── searchbar ├── main.dart ├── model │ ├── product_response.dart │ ├── review.dart │ └── product.dart ├── product_item.dart ├── product_details.dart └── home.dart ├── gridview-2024 ├── main.dart ├── model │ ├── product_response.dart │ ├── review.dart │ └── product.dart ├── grid_example.dart ├── product_details.dart └── home.dart ├── search-delegates ├── main.dart ├── model │ ├── product_response.dart │ ├── review.dart │ └── product.dart ├── product_list.dart ├── search_delegates.dart ├── product_item.dart ├── home.dart └── product_details.dart ├── sidebar-menu ├── main.dart ├── dashboard.dart └── sidebar_menu.dart ├── statemanagement-getx ├── products.dart ├── product.dart ├── data_controller.dart └── main.dart ├── todo ├── todo_model.dart └── db_helper.dart ├── pagetransition ├── secondscreen.dart └── main.dart ├── getnavigation ├── screen_two.dart ├── screen_one.dart └── main.dart ├── hero ├── secondscreen.dart └── main.dart ├── razorpay ├── verify_signature.php └── main.dart ├── navigation ├── secondscreen.dart └── main.dart ├── snackbar └── main.dart ├── newsapp ├── page_transformer.dart └── news_model.dart ├── user-form ├── text_validator.dart ├── home_screen.dart └── main.dart ├── story ├── story_screen.dart └── main.dart ├── webview └── main.dart ├── GraphQL ├── api_call_dummy.dart └── main.dart ├── option menu └── main.dart ├── dropdownlist └── main.dart ├── gridview └── main.dart ├── alertdialog └── main.dart ├── jsonserialization ├── characters.dart └── main.dart ├── bottom navigation └── main.dart ├── bottom sheet └── main.dart ├── notification └── main.dart ├── gradient_border └── main.dart ├── spinthewheel └── main.dart ├── http └── main.dart ├── carouselview └── main.dart ├── number picker └── main.dart ├── render overflow └── main.dart ├── futurebuilder └── main.dart ├── cashfree_pg └── main.dart ├── pdf └── main.dart ├── add-to-cart-animation-demo └── main.dart └── url launcher └── main.dart /README.md: -------------------------------------------------------------------------------- 1 | YouTube Video Source Code 2 | -------------------------------------------------------------------------------- /multiplatform/device_enum.dart: -------------------------------------------------------------------------------- 1 | enum Devices { 2 | mobile, 3 | web, 4 | desktop, 5 | } 6 | -------------------------------------------------------------------------------- /hero-2024/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:testhero/home.dart'; 3 | 4 | void main() { 5 | runApp(const MyApp()); 6 | } 7 | 8 | class MyApp extends StatelessWidget { 9 | const MyApp({super.key}); 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /searchbar/main.dart: -------------------------------------------------------------------------------- 1 | //http: ^1.2.2 add this plugin 2 | import 'package:dummy/home.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | void main() { 6 | runApp(const MyApp()); 7 | } 8 | 9 | class MyApp extends StatelessWidget { 10 | const MyApp({super.key}); 11 | @override 12 | Widget build(BuildContext context) { 13 | return const MaterialApp( 14 | home: Home(), 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gridview-2024/main.dart: -------------------------------------------------------------------------------- 1 | //http: ^1.2.2 add this plugin 2 | import 'package:dummy/home.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | void main() { 6 | runApp(const MyApp()); 7 | } 8 | 9 | class MyApp extends StatelessWidget { 10 | const MyApp({super.key}); 11 | @override 12 | Widget build(BuildContext context) { 13 | return const MaterialApp( 14 | home: Home(), 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /search-delegates/main.dart: -------------------------------------------------------------------------------- 1 | //http: ^1.2.2 add this plugin 2 | import 'package:dummy/home.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | void main() { 6 | runApp(const MyApp()); 7 | } 8 | 9 | class MyApp extends StatelessWidget { 10 | const MyApp({super.key}); 11 | @override 12 | Widget build(BuildContext context) { 13 | return const MaterialApp( 14 | home: Home(), 15 | ); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /searchbar/model/product_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | 3 | class ProductResponse { 4 | List? products; 5 | ProductResponse({this.products}); 6 | 7 | factory ProductResponse.fromJson(Map? json) => 8 | ProductResponse( 9 | products: json?['products'] 10 | ?.map((e) => Product.fromJson(e)) 11 | .toList()); 12 | } 13 | -------------------------------------------------------------------------------- /gridview-2024/model/product_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | 3 | class ProductResponse { 4 | List? products; 5 | ProductResponse({this.products}); 6 | 7 | factory ProductResponse.fromJson(Map? json) => 8 | ProductResponse( 9 | products: json?['products'] 10 | ?.map((e) => Product.fromJson(e)) 11 | .toList()); 12 | } 13 | -------------------------------------------------------------------------------- /hero-2024/model/product_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:testhero/model/product.dart'; 2 | 3 | class ProductResponse { 4 | List? products; 5 | ProductResponse({this.products}); 6 | 7 | factory ProductResponse.fromJson(Map? json) => 8 | ProductResponse( 9 | products: json?['products'] 10 | ?.map((e) => Product.fromJson(e)) 11 | .toList()); 12 | } 13 | -------------------------------------------------------------------------------- /search-delegates/model/product_response.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | 3 | class ProductResponse { 4 | List? products; 5 | ProductResponse({this.products}); 6 | 7 | factory ProductResponse.fromJson(Map? json) => 8 | ProductResponse( 9 | products: json?['products'] 10 | ?.map((e) => Product.fromJson(e)) 11 | .toList()); 12 | } 13 | -------------------------------------------------------------------------------- /sidebar-menu/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:testhero/dashboard.dart'; 3 | 4 | void main() { 5 | runApp(const MyApp()); 6 | } 7 | 8 | class MyApp extends StatefulWidget { 9 | const MyApp({super.key}); 10 | 11 | @override 12 | State createState() => _MyAppState(); 13 | } 14 | 15 | class _MyAppState extends State { 16 | @override 17 | Widget build(BuildContext context) { 18 | return const MaterialApp( 19 | home: Dashboard(), 20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /statemanagement-getx/products.dart: -------------------------------------------------------------------------------- 1 | import 'package:skeletondemo/product.dart'; 2 | 3 | class Products { 4 | List products; 5 | 6 | Products({ 7 | required this.products, 8 | }); 9 | 10 | factory Products.fromJson(Map json) { 11 | return Products( 12 | products: 13 | json['products'].map((e) => Product.fromJson(e)).toList(), 14 | ); 15 | } 16 | 17 | Map toJson() => { 18 | "products": products.map((e) => e.toJson()).toList(), 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /search-delegates/product_list.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | import 'package:dummy/product_item.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class ProductList extends StatelessWidget { 6 | final List products; 7 | const ProductList({super.key, required this.products}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return ListView.builder( 12 | itemCount: products.length, 13 | itemBuilder: (context, index) { 14 | return ProductItem(product: products[index]); 15 | }); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /hero-2024/model/review.dart: -------------------------------------------------------------------------------- 1 | class Review { 2 | int? rating; 3 | String? comment; 4 | String? date; 5 | String? reviewerName; 6 | String? reviewerEmail; 7 | Review({ 8 | this.comment, 9 | this.date, 10 | this.rating, 11 | this.reviewerEmail, 12 | this.reviewerName, 13 | }); 14 | factory Review.fromJson(Map? json) => Review( 15 | comment: json?['comment'], 16 | date: json?['date'], 17 | rating: json?['rating'], 18 | reviewerEmail: json?['reviewerEmail'], 19 | reviewerName: json?['reviewerName'], 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /searchbar/model/review.dart: -------------------------------------------------------------------------------- 1 | class Review { 2 | int? rating; 3 | String? comment; 4 | String? date; 5 | String? reviewerName; 6 | String? reviewerEmail; 7 | Review({ 8 | this.comment, 9 | this.date, 10 | this.rating, 11 | this.reviewerEmail, 12 | this.reviewerName, 13 | }); 14 | factory Review.fromJson(Map? json) => Review( 15 | comment: json?['comment'], 16 | date: json?['date'], 17 | rating: json?['rating'], 18 | reviewerEmail: json?['reviewerEmail'], 19 | reviewerName: json?['reviewerName'], 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /gridview-2024/model/review.dart: -------------------------------------------------------------------------------- 1 | class Review { 2 | int? rating; 3 | String? comment; 4 | String? date; 5 | String? reviewerName; 6 | String? reviewerEmail; 7 | Review({ 8 | this.comment, 9 | this.date, 10 | this.rating, 11 | this.reviewerEmail, 12 | this.reviewerName, 13 | }); 14 | factory Review.fromJson(Map? json) => Review( 15 | comment: json?['comment'], 16 | date: json?['date'], 17 | rating: json?['rating'], 18 | reviewerEmail: json?['reviewerEmail'], 19 | reviewerName: json?['reviewerName'], 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /search-delegates/model/review.dart: -------------------------------------------------------------------------------- 1 | class Review { 2 | int? rating; 3 | String? comment; 4 | String? date; 5 | String? reviewerName; 6 | String? reviewerEmail; 7 | Review({ 8 | this.comment, 9 | this.date, 10 | this.rating, 11 | this.reviewerEmail, 12 | this.reviewerName, 13 | }); 14 | factory Review.fromJson(Map? json) => Review( 15 | comment: json?['comment'], 16 | date: json?['date'], 17 | rating: json?['rating'], 18 | reviewerEmail: json?['reviewerEmail'], 19 | reviewerName: json?['reviewerName'], 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /multiplatform/check_device.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:flutter/foundation.dart' show kIsWeb; 4 | import 'package:flutternews/device_enum.dart'; 5 | 6 | // this is the method i wrote to check on which device i am running 7 | 8 | getDevice() { 9 | if (kIsWeb) { // this is web 10 | // running on the web! 11 | return Devices.web; 12 | } else { 13 | if (Platform.isAndroid || Platform.isIOS) { // mobile 14 | return Devices.mobile; 15 | } else if (Platform.isMacOS || Platform.isWindows) { // desktop 16 | return Devices.desktop; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /todo/todo_model.dart: -------------------------------------------------------------------------------- 1 | class TODO { 2 | int? id; 3 | String label; 4 | String desc; 5 | int isComplete; 6 | String date; 7 | // nothing much just id, label desc, iscomplete to check if it;s done or not 8 | // and date which i am not using anywhere but still 9 | TODO({ 10 | this.id, 11 | required this.date, 12 | required this.desc, 13 | required this.label, 14 | this.isComplete = 0, 15 | }); 16 | 17 | // to map function to convert objet to map 18 | // okay now let's see db helper 19 | Map toMap() { 20 | return { 21 | 'id': id, 22 | 'date': date, 23 | 'desc': desc, 24 | 'label': label, 25 | 'isComplete': isComplete, 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sidebar-menu/dashboard.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:testhero/sidebar_menu.dart'; 3 | 4 | class Dashboard extends StatefulWidget { 5 | const Dashboard({super.key}); 6 | 7 | @override 8 | State createState() => _DashboardState(); 9 | } 10 | 11 | class _DashboardState extends State { 12 | @override 13 | Widget build(BuildContext context) { 14 | return Scaffold( 15 | appBar: AppBar( 16 | title: const Text("Sidebar Menu Demo"), 17 | backgroundColor: Colors.amber, 18 | ), 19 | drawer: const SidebarMenu(), 20 | body: Container( 21 | color: Colors.blueAccent, 22 | alignment: Alignment.center, 23 | child: const Text("Dashboard"), 24 | ), 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pagetransition/secondscreen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class SecondScreen extends StatelessWidget { 4 | const SecondScreen({ 5 | Key? key, 6 | }) : super(key: key); 7 | 8 | @override 9 | Widget build(BuildContext context) { 10 | return Scaffold( 11 | backgroundColor: Colors.amberAccent, 12 | appBar: AppBar( 13 | title: const Text("Second Screen"), 14 | ), 15 | body: SizedBox( 16 | height: double.infinity, 17 | width: double.infinity, 18 | child: Column( 19 | mainAxisAlignment: MainAxisAlignment.center, 20 | crossAxisAlignment: CrossAxisAlignment.center, 21 | children: const [ 22 | Text("Page 2"), 23 | ], 24 | ), 25 | ), 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /getnavigation/screen_two.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:get/get.dart'; // you have to import this 3 | 4 | class ScreenTwo extends StatefulWidget { 5 | const ScreenTwo({super.key}); 6 | 7 | @override 8 | State createState() => _ScreenTwoState(); 9 | } 10 | 11 | // let run first 12 | class _ScreenTwoState extends State { 13 | @override 14 | Widget build(BuildContext context) { 15 | return Scaffold( 16 | appBar: AppBar( 17 | title: const Text("Screen Two"), 18 | ), 19 | body: Center( 20 | child: ElevatedButton( 21 | onPressed: () { 22 | // to go back use 23 | Get.back(); 24 | // now let see samee with name routes 25 | }, 26 | child: const Text("Go Back"), 27 | ), 28 | ), 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /statemanagement-getx/product.dart: -------------------------------------------------------------------------------- 1 | class Product { 2 | num id; 3 | String title; 4 | String description; 5 | num price; 6 | String brand; 7 | String thumbnail; 8 | 9 | Product({ 10 | required this.brand, 11 | required this.description, 12 | required this.id, 13 | required this.price, 14 | required this.thumbnail, 15 | required this.title, 16 | }); 17 | 18 | factory Product.fromJson(Map json) { 19 | return Product( 20 | brand: json["brand"], 21 | description: json["description"], 22 | id: json["id"], 23 | price: json["price"], 24 | thumbnail: json["thumbnail"], 25 | title: json["title"], 26 | ); 27 | } 28 | 29 | Map toJson() => { 30 | "brand": brand, 31 | "description": description, 32 | "id": id, 33 | "price": price, 34 | "thumbnail": thumbnail, 35 | "title": title, 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /searchbar/model/product.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/review.dart'; 2 | 3 | class Product { 4 | int? id; 5 | String? title; 6 | String? description; 7 | String? category; 8 | double? price; 9 | double? rating; 10 | String? brand; 11 | List? reviews; 12 | String? thumbnail; 13 | Product({ 14 | this.brand, 15 | this.category, 16 | this.description, 17 | this.id, 18 | this.price, 19 | this.rating, 20 | this.reviews, 21 | this.title, 22 | this.thumbnail, 23 | }); 24 | 25 | factory Product.fromJson(Map? json) => Product( 26 | brand: json?['brand'], 27 | category: json?['category'], 28 | description: json?['description'], 29 | id: json?['id'], 30 | price: json?['price'], 31 | rating: json?['rating'], 32 | reviews: 33 | json?['reviews']?.map((e) => Review.fromJson(e)).toList(), 34 | title: json?['title'], 35 | thumbnail: json?['thumbnail'], 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /gridview-2024/model/product.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/review.dart'; 2 | 3 | class Product { 4 | int? id; 5 | String? title; 6 | String? description; 7 | String? category; 8 | double? price; 9 | double? rating; 10 | String? brand; 11 | List? reviews; 12 | String? thumbnail; 13 | Product({ 14 | this.brand, 15 | this.category, 16 | this.description, 17 | this.id, 18 | this.price, 19 | this.rating, 20 | this.reviews, 21 | this.title, 22 | this.thumbnail, 23 | }); 24 | 25 | factory Product.fromJson(Map? json) => Product( 26 | brand: json?['brand'], 27 | category: json?['category'], 28 | description: json?['description'], 29 | id: json?['id'], 30 | price: json?['price'], 31 | rating: json?['rating'], 32 | reviews: 33 | json?['reviews']?.map((e) => Review.fromJson(e)).toList(), 34 | title: json?['title'], 35 | thumbnail: json?['thumbnail'], 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /hero-2024/model/product.dart: -------------------------------------------------------------------------------- 1 | import 'package:testhero/model/review.dart'; 2 | 3 | class Product { 4 | int? id; 5 | String? title; 6 | String? description; 7 | String? category; 8 | double? price; 9 | double? rating; 10 | String? brand; 11 | List? reviews; 12 | String? thumbnail; 13 | Product({ 14 | this.brand, 15 | this.category, 16 | this.description, 17 | this.id, 18 | this.price, 19 | this.rating, 20 | this.reviews, 21 | this.title, 22 | this.thumbnail, 23 | }); 24 | 25 | factory Product.fromJson(Map? json) => Product( 26 | brand: json?['brand'], 27 | category: json?['category'], 28 | description: json?['description'], 29 | id: json?['id'], 30 | price: json?['price'], 31 | rating: json?['rating'], 32 | reviews: 33 | json?['reviews']?.map((e) => Review.fromJson(e)).toList(), 34 | title: json?['title'], 35 | thumbnail: json?['thumbnail'], 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /search-delegates/model/product.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/review.dart'; 2 | 3 | class Product { 4 | int? id; 5 | String? title; 6 | String? description; 7 | String? category; 8 | double? price; 9 | double? rating; 10 | String? brand; 11 | List? reviews; 12 | String? thumbnail; 13 | Product({ 14 | this.brand, 15 | this.category, 16 | this.description, 17 | this.id, 18 | this.price, 19 | this.rating, 20 | this.reviews, 21 | this.title, 22 | this.thumbnail, 23 | }); 24 | 25 | factory Product.fromJson(Map? json) => Product( 26 | brand: json?['brand'], 27 | category: json?['category'], 28 | description: json?['description'], 29 | id: json?['id'], 30 | price: json?['price'], 31 | rating: json?['rating'], 32 | reviews: 33 | json?['reviews']?.map((e) => Review.fromJson(e)).toList(), 34 | title: json?['title'], 35 | thumbnail: json?['thumbnail'], 36 | ); 37 | } 38 | -------------------------------------------------------------------------------- /getnavigation/screen_one.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:get/get.dart'; 3 | 4 | class ScreenOne extends StatefulWidget { 5 | const ScreenOne({super.key}); 6 | 7 | @override 8 | State createState() => _ScreenOneState(); 9 | } 10 | 11 | class _ScreenOneState extends State { 12 | @override 13 | Widget build(BuildContext context) { 14 | return Scaffold( 15 | appBar: AppBar( 16 | title: const Text("Screen One"), 17 | ), 18 | body: Center( 19 | child: ElevatedButton( 20 | onPressed: () { 21 | // to navigate to next you just have to use 22 | // Get.to(const ScreenTwo()); // done , see how simple 23 | // for named route 24 | Get.toNamed("/two"); 25 | // to see all the navigation method just CTR click on 26 | // that's it for today thanks for watching 27 | }, 28 | child: const Text("Open Screen Two"), 29 | ), 30 | ), 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gridview-2024/grid_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class GridExample extends StatefulWidget { 4 | const GridExample({super.key}); 5 | 6 | @override 7 | State createState() => _GridExampleState(); 8 | } 9 | 10 | class _GridExampleState extends State { 11 | @override 12 | Widget build(BuildContext context) { 13 | return Scaffold( 14 | appBar: AppBar( 15 | backgroundColor: Colors.blueAccent, 16 | title: const Text( 17 | "GridView Widget", 18 | style: TextStyle( 19 | color: Colors.white, 20 | ), 21 | ), 22 | ), 23 | body: GridView.builder( 24 | itemCount: 30, 25 | itemBuilder: (context, index) => Padding( 26 | padding: const EdgeInsets.all(8.0), 27 | child: Container( 28 | color: Colors.blue, 29 | ), 30 | ), 31 | gridDelegate: 32 | const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), 33 | ), 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hero/secondscreen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class SecondScreen extends StatelessWidget { 4 | const SecondScreen({ 5 | Key? key, 6 | }) : super(key: key); 7 | 8 | @override 9 | Widget build(BuildContext context) { 10 | return Scaffold( 11 | appBar: AppBar( 12 | title: const Text("Second Screen"), 13 | ), 14 | body: SizedBox( 15 | height: double.infinity, 16 | width: double.infinity, 17 | child: Column( 18 | mainAxisAlignment: MainAxisAlignment.center, 19 | crossAxisAlignment: CrossAxisAlignment.center, 20 | children: const [ 21 | // wrap both the widget in both screen 22 | Hero( 23 | tag: "Zoro", 24 | child: Image( 25 | image: NetworkImage( 26 | "https://i.pinimg.com/originals/3a/bd/73/3abd731ea1a036bbab68e33aa9305434.jpg"), 27 | height: 300, 28 | width: 300, 29 | ), 30 | ), 31 | ], 32 | ), 33 | ), 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /razorpay/verify_signature.php: -------------------------------------------------------------------------------- 1 | $razorpaySignature, 'razorpay_payment_id' => $razorpayPaymentId , 'razorpay_order_id' => $razorpayOrderId); 20 | $order = $api->utility->verifyPaymentSignature($attributes); 21 | }catch(SignatureVerificationError $e){ 22 | $success = false; 23 | $error = 'Razorpay Error : ' . $e->getMessage(); 24 | } 25 | if ($success === true) { 26 | $message = "Your payment was successful\nPayment ID: {$_POST['razorpay_payment_id']}"; 27 | } else { 28 | $message = "Your payment failed\n{$error}"; 29 | } 30 | echo $message; 31 | ?> 32 | -------------------------------------------------------------------------------- /navigation/secondscreen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class SecondScreen extends StatelessWidget { 4 | final String name; 5 | const SecondScreen({Key? key, required this.name}) : super(key: key); 6 | 7 | @override 8 | Widget build(BuildContext context) { 9 | return Scaffold( 10 | appBar: AppBar( 11 | title: const Text("Second Screen"), 12 | ), 13 | body: SizedBox( 14 | height: double.infinity, 15 | width: double.infinity, 16 | child: Column( 17 | mainAxisAlignment: MainAxisAlignment.center, 18 | crossAxisAlignment: CrossAxisAlignment.center, 19 | children: [ 20 | Text("Message from Home Screen:- $name"), 21 | const SizedBox( 22 | height: 20, 23 | ), 24 | ElevatedButton( 25 | onPressed: () { 26 | // now let's see how to close this screen 27 | Navigator.of(context).pop(); 28 | }, 29 | child: const Text("Close screen"), 30 | ), 31 | ], 32 | ), 33 | ), 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /statemanagement-getx/data_controller.dart: -------------------------------------------------------------------------------- 1 | // 2 | 3 | import 'dart:convert'; 4 | 5 | import 'package:get/get.dart'; 6 | import 'package:http/http.dart' as http; 7 | import 'package:skeletondemo/product.dart'; 8 | import 'package:skeletondemo/products.dart'; 9 | 10 | class DataController extends GetxController { 11 | // you need to extend to GetxController 12 | // 13 | 14 | // create a list to store these product 15 | RxList products = [].obs; // obs make variable observable , 16 | 17 | RxBool loading = false.obs; 18 | 19 | void getProducts() async { 20 | try { 21 | loading.value = true; 22 | var res = await http.get(Uri.parse("https://dummyjson.com/products")); 23 | if (res.statusCode == 200) { 24 | Products prod = 25 | Products.fromJson(jsonDecode(res.body)); // Products is model class 26 | products.value = prod 27 | .products; // variable . value is use to assign value , when to assing new value like this it will rebuild widget where it is been used 28 | } 29 | } catch (e) { 30 | print(e); 31 | } finally { 32 | loading.value = false; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /snackbar/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | 18 | class Home extends StatefulWidget { 19 | const Home({Key? key}) : super(key: key); 20 | 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | 27 | 28 | @override 29 | Widget build(BuildContext context) { 30 | return Scaffold( 31 | appBar: AppBar( 32 | title: const FittedBox( 33 | child: Text( 34 | "Snackbar View", 35 | ), 36 | ), 37 | ), 38 | body: Center( 39 | child: ElevatedButton( 40 | child: Text("Show Message"), 41 | onPressed: showMessage, 42 | ), 43 | )); 44 | } 45 | 46 | void showMessage() { 47 | ScaffoldMessenger.of(context).showSnackBar(SnackBar( 48 | content: Text("Hi, I am snackbar"), 49 | )); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /newsapp/page_transformer.dart: -------------------------------------------------------------------------------- 1 | import 'package:another_transformer_page_view/another_transformer_page_view.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class DepthPageTransformer extends PageTransformer { 5 | DepthPageTransformer() : super(reverse: true); 6 | 7 | @override 8 | Widget transform(Widget child, TransformInfo info) { 9 | final position = info.position!; 10 | if (position <= 0) { 11 | return Opacity( 12 | opacity: 1.0, 13 | child: Transform.translate( 14 | offset: Offset.zero, 15 | child: Transform.scale( 16 | scale: 1.0, 17 | child: child, 18 | ), 19 | ), 20 | ); 21 | } else if (position <= 1) { 22 | const minScale = 0.75; 23 | // Scale the page down (between minScale and 1) 24 | final scaleFactor = minScale + (1 - minScale) * (1 - position); 25 | 26 | return Opacity( 27 | opacity: 1.0 - position, 28 | child: Transform.translate( 29 | offset: Offset(0.0, info.width! * -position), 30 | child: Transform.scale( 31 | scale: scaleFactor, 32 | child: child, 33 | ), 34 | ), 35 | ); 36 | } 37 | 38 | return child; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /multiplatform/page_transformers.dart: -------------------------------------------------------------------------------- 1 | import 'package:another_transformer_page_view/another_transformer_page_view.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class DepthPageTransformer extends PageTransformer { 5 | DepthPageTransformer() : super(reverse: true); 6 | 7 | @override 8 | Widget transform(Widget child, TransformInfo info) { 9 | final position = info.position!; 10 | if (position <= 0) { 11 | return Opacity( 12 | opacity: 1.0, 13 | child: Transform.translate( 14 | offset: Offset.zero, 15 | child: Transform.scale( 16 | scale: 1.0, 17 | child: child, 18 | ), 19 | ), 20 | ); 21 | } else if (position <= 1) { 22 | const minScale = 0.75; 23 | // Scale the page down (between minScale and 1) 24 | final scaleFactor = minScale + (1 - minScale) * (1 - position); 25 | 26 | return Opacity( 27 | opacity: 1.0 - position, 28 | child: Transform.translate( 29 | offset: Offset(0.0, info.width! * -position), 30 | child: Transform.scale( 31 | scale: scaleFactor, 32 | child: child, 33 | ), 34 | ), 35 | ); 36 | } 37 | 38 | return child; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /user-form/text_validator.dart: -------------------------------------------------------------------------------- 1 | class TextValidator { 2 | final String validationType; 3 | 4 | TextValidator(this.validationType); 5 | 6 | // Define the call method 7 | String? call(String value) { 8 | if (validationType == 'email') { 9 | return _validateEmail(value); 10 | } else if (validationType == 'username') { 11 | return _validateUsername(value); 12 | } else if (validationType == 'password') { 13 | return _validatePassword(value); 14 | } 15 | return null; 16 | } 17 | 18 | // Email validation logic 19 | String? _validateEmail(String email) { 20 | final RegExp emailRegex = RegExp( 21 | r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$', 22 | ); 23 | if (!emailRegex.hasMatch(email)) { 24 | return 'Enter a valid email address'; 25 | } 26 | return null; 27 | } 28 | 29 | // Username validation logic 30 | String? _validateUsername(String username) { 31 | if (username.isEmpty || username.length < 3) { 32 | return 'Username must be at least 3 characters long'; 33 | } 34 | return null; 35 | } 36 | 37 | // Password validation logic 38 | String? _validatePassword(String password) { 39 | if (password.length < 6) { 40 | return 'Password must be at least 6 characters long'; 41 | } 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /story/story_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:story_view/story_view.dart'; 3 | 4 | class StoryScreen extends StatelessWidget { 5 | final StoryController controller; 6 | final List storyItems; 7 | const StoryScreen({ 8 | super.key, 9 | required this.controller, 10 | required this.storyItems, 11 | }); 12 | 13 | @override 14 | Widget build(BuildContext context) { 15 | return Scaffold( 16 | body: StoryView( 17 | controller: controller, // pass controller here too 18 | 19 | onStoryShow: (s) { 20 | print(s); 21 | // this get called on every story screen 22 | }, 23 | onComplete: () { 24 | print("complete"); 25 | Navigator.pop(context); 26 | // on completing all slide i am closing this screen 27 | // in case of where we have more than 1 user we would move to next user's data 28 | }, 29 | onVerticalSwipeComplete: (direction) { 30 | // like whatsapp and intagram you can close stgory by upward swipe 31 | if (direction == Direction.down) { 32 | Navigator.pop(context); 33 | } 34 | }, 35 | storyItems: storyItems, // this is our story item list 36 | ), 37 | ); 38 | } 39 | } 40 | // that's all you need to show this story/status 41 | -------------------------------------------------------------------------------- /getnavigation/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Add plugin to pubspec.yaml 3 | get: ^4.6.5 4 | 5 | 6 | */ 7 | 8 | import 'package:flutter/material.dart'; 9 | import 'package:get/route_manager.dart'; 10 | import 'package:gexnavigation/screen_one.dart'; 11 | import 'package:gexnavigation/screen_two.dart'; 12 | 13 | void main() { 14 | runApp(const MyApp()); 15 | } 16 | 17 | class MyApp extends StatelessWidget { 18 | const MyApp({super.key}); 19 | 20 | /* 21 | 22 | Hey everyone , Today we will how to use Get navigation 23 | doing navigation with Get plugin is very easy to let's let started 24 | with installing plugin 25 | 26 | 27 | 28 | 29 | */ 30 | 31 | @override 32 | Widget build(BuildContext context) { 33 | return GetMaterialApp( 34 | // TO use Get navigation we have to replace MaterialApp with GetMaterialApp 35 | // that's it now we can do navigation 36 | // I have here 2 screen 37 | // while it's running let me explain existing code we have 2 screen i'll navigation from one to screen two 38 | 39 | routes: { 40 | "/": (_) => 41 | const ScreenOne(), // '/' is default route ,or first screen to be shown when app runs 42 | "/two": (_) => const ScreenTwo(), 43 | }, 44 | title: 'Flutter Demo', 45 | theme: ThemeData( 46 | colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), 47 | useMaterial3: true, 48 | ), 49 | // home: const ScreenOne(), // remove this now 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /webview/main.dart: -------------------------------------------------------------------------------- 1 | // webview_flutter: ^4.9.0 # add this plugin 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:webview_flutter/webview_flutter.dart'; 5 | 6 | void main() { 7 | runApp(const MyApp()); 8 | } 9 | 10 | class MyApp extends StatelessWidget { 11 | const MyApp({super.key}); 12 | 13 | @override 14 | Widget build(BuildContext context) { 15 | return const MaterialApp( 16 | home: Home(), 17 | ); 18 | } 19 | } 20 | 21 | class Home extends StatefulWidget { 22 | const Home({super.key}); 23 | 24 | @override 25 | State createState() => _HomeState(); 26 | } 27 | 28 | class _HomeState extends State { 29 | WebViewController? webViewController; 30 | @override 31 | void initState() { 32 | webViewController = WebViewController() 33 | ..setJavaScriptMode(JavaScriptMode.unrestricted) 34 | ..setNavigationDelegate(NavigationDelegate( 35 | onNavigationRequest: (request) { 36 | if (request.url == "https://flutter.dev/multi-platform") { 37 | return NavigationDecision.prevent; 38 | } else { 39 | return NavigationDecision.navigate; 40 | } 41 | }, 42 | )) 43 | ..loadRequest(Uri.https("flutter.dev")); 44 | super.initState(); 45 | } 46 | 47 | @override 48 | Widget build(BuildContext context) { 49 | return Scaffold( 50 | body: SafeArea( 51 | child: webViewController != null 52 | ? WebViewWidget(controller: webViewController!) 53 | : Container()), 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /GraphQL/api_call_dummy.dart: -------------------------------------------------------------------------------- 1 | // NOTE: 2 | // here authorization and key field is to just show how you can use. 3 | // actual api link used here does not support authorization key and api key 4 | 5 | void fetchData() async { 6 | setState(() { 7 | _loading = true; 8 | }); 9 | 10 | 11 | HttpLink httpLink = HttpLink("https://rickandmortyapi.com/graphql"); 12 | AuthLink authLink = AuthLink( 13 | getToken: () async => 'Bearer ${await SessionManager.getAuthToken()}', 14 | ); 15 | 16 | AuthLink apiKey = AuthLink( 17 | getToken: () async => await SessionManager.getAPI(), 18 | headerKey: 'apiKey', 19 | ); 20 | Link link = authLink.concat(apiKey).concat(httpLink); 21 | 22 | GraphQLClient qlClient = GraphQLClient( 23 | 24 | link: link, 25 | cache: GraphQLCache( 26 | store: 27 | HiveStore(), 28 | ), 29 | ); 30 | QueryResult queryResult = await qlClient.query( 31 | QueryOptions( 32 | document: gql( 33 | """query { 34 | characters() { 35 | results { 36 | name 37 | image 38 | } 39 | } 40 | 41 | }""", 42 | ), 43 | ), 44 | ); 45 | 46 | // queryResult.data // contains data 47 | // queryResult.exception // will give what exception you got /errors 48 | // queryResult.hasException // you can check if you have any exception 49 | 50 | // queryResult.context.entry()?.statusCode // to get status code of response 51 | 52 | setState(() { 53 | characters = queryResult.data!['characters'][ 54 | 'results']; 55 | _loading = false; 56 | }); 57 | } 58 | -------------------------------------------------------------------------------- /option menu/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | 18 | class Home extends StatefulWidget { 19 | const Home({Key? key}) : super(key: key); 20 | 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | // menu options 27 | final List _options = [ 28 | "Filter", 29 | "Settings", 30 | "Logout", 31 | ]; 32 | 33 | @override 34 | Widget build(BuildContext context) { 35 | return Scaffold( 36 | appBar: AppBar( 37 | title: const Text("Option Menu"), 38 | actions: [ 39 | PopupMenuButton( 40 | onSelected: handleClick, 41 | itemBuilder: (context) { 42 | return _options.map((e) { 43 | return PopupMenuItem(value: e, child: Text(e)); 44 | }).toList(); 45 | }) 46 | ], 47 | ), 48 | body: Container(), 49 | ); 50 | } 51 | 52 | void handleClick(String value) { 53 | // you can you switch to perform different action 54 | switch (value) { 55 | case "Filter": 56 | print("Filter selected"); 57 | break; 58 | case "Settings": 59 | print("Settings selected"); 60 | break; 61 | case "Logout": 62 | print("Logout selected"); 63 | break; 64 | default: 65 | print("this will be called if non of above case matched"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /dropdownlist/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | 18 | class Home extends StatefulWidget { 19 | const Home({Key? key}) : super(key: key); 20 | 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | // data for dropdown 27 | final List _languages = [ 28 | "Java", 29 | "Dart", 30 | "Python", 31 | "C++", 32 | "C", 33 | ]; 34 | 35 | String? selectedLanguage; 36 | 37 | @override 38 | Widget build(BuildContext context) { 39 | return Scaffold( 40 | appBar: AppBar( 41 | title: const Text("Dropdown"), 42 | ), 43 | body: Center( 44 | child: Column( 45 | mainAxisAlignment: MainAxisAlignment.center, 46 | children: [ 47 | DropdownButton( 48 | hint: const Text( 49 | "Select Language", 50 | ), 51 | value: selectedLanguage, 52 | items: _languages.map((String language) { 53 | return DropdownMenuItem( 54 | value: language, 55 | child: Text(language), 56 | ); 57 | }).toList(), 58 | onChanged: (String? dropdownValue) { 59 | setState(() { 60 | selectedLanguage = dropdownValue; 61 | }); 62 | }), 63 | ], 64 | ), 65 | ), 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /search-delegates/search_delegates.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | import 'package:dummy/product_list.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class ProductSearchDelegates extends SearchDelegate { 6 | ProductSearchDelegates({required this.products}); 7 | 8 | final List products; 9 | List results = []; 10 | 11 | @override 12 | String? get searchFieldLabel => "Enter keywords..."; 13 | 14 | @override 15 | ThemeData appBarTheme(BuildContext context) { 16 | return ThemeData( 17 | appBarTheme: const AppBarTheme( 18 | backgroundColor: Colors.amberAccent, 19 | )); 20 | } 21 | 22 | @override 23 | List? buildActions(BuildContext context) { 24 | return [ 25 | IconButton( 26 | icon: const Icon(Icons.clear), 27 | onPressed: () => query.isEmpty ? close(context, null) : query = '', 28 | ), 29 | ]; 30 | } 31 | 32 | @override 33 | Widget? buildLeading(BuildContext context) { 34 | return IconButton( 35 | icon: const Icon(Icons.arrow_back), 36 | onPressed: () => close(context, null), 37 | ); 38 | } 39 | 40 | @override 41 | Widget buildResults(BuildContext context) { 42 | return results.isEmpty 43 | ? const Center( 44 | child: Text('No Results', style: TextStyle(fontSize: 20)), 45 | ) 46 | : ProductList(products: results); 47 | } 48 | 49 | @override 50 | Widget buildSuggestions(BuildContext context) { 51 | results = 52 | [...products].where((e) => e.title?.contains(query) == true).toList(); 53 | return results.isEmpty 54 | ? const Center( 55 | child: Text('No Results', style: TextStyle(fontSize: 24)), 56 | ) 57 | : ProductList(products: results); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /gridview/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | 18 | class Home extends StatefulWidget { 19 | const Home({Key? key}) : super(key: key); 20 | 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | // data to show 27 | List _products = [ 28 | "https://dummyjson.com/image/i/products/1/thumbnail.jpg", 29 | "https://dummyjson.com/image/i/products/2/thumbnail.jpg", 30 | "https://dummyjson.com/image/i/products/3/thumbnail.jpg", 31 | "https://dummyjson.com/image/i/products/4/thumbnail.jpg", 32 | "https://dummyjson.com/image/i/products/5/thumbnail.jpg", 33 | "https://dummyjson.com/image/i/products/6/thumbnail.png", 34 | "https://dummyjson.com/image/i/products/7/thumbnail.jpg", 35 | "https://dummyjson.com/image/i/products/8/thumbnail.jpg", 36 | "https://dummyjson.com/image/i/products/9/thumbnail.jpg", 37 | ]; 38 | 39 | @override 40 | Widget build(BuildContext context) { 41 | return Scaffold( 42 | appBar: AppBar( 43 | title: const FittedBox( 44 | child: Text( 45 | "Grid View", 46 | ), 47 | ), 48 | ), 49 | body: Padding( 50 | padding: const EdgeInsets.all(8.0), 51 | child: GridView.builder( 52 | itemCount: _products.length, 53 | gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( 54 | crossAxisCount: 3, 55 | childAspectRatio: 0.8, 56 | crossAxisSpacing: 20.0, 57 | mainAxisSpacing: 20.0, 58 | ), 59 | itemBuilder: (context, index) { 60 | return Card( 61 | child: Image.network(_products[index]), 62 | ); 63 | }), 64 | )); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /hero/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/screen2.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | void main() { 5 | runApp(const MyApp()); 6 | } 7 | 8 | class MyApp extends StatelessWidget { 9 | const MyApp({Key? key}) : super(key: key); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return const MaterialApp( 14 | home: Home(), 15 | ); 16 | } 17 | } 18 | 19 | class Home extends StatefulWidget { 20 | const Home({Key? key}) : super(key: key); 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | /* 27 | hey everyone let's see how to animate a widget across two screen 28 | with Hero 29 | i have already created UI let's first see it 30 | okay now let's animate it 31 | */ 32 | 33 | @override 34 | Widget build(BuildContext context) { 35 | return Scaffold( 36 | appBar: AppBar( 37 | title: const FittedBox( 38 | child: Text( 39 | "Hero", 40 | ), 41 | ), 42 | ), 43 | body: SizedBox( 44 | height: double.infinity, 45 | width: double.infinity, 46 | child: Column( 47 | mainAxisAlignment: MainAxisAlignment.center, 48 | crossAxisAlignment: CrossAxisAlignment.center, 49 | children: [ 50 | // you have to wrap your widget with Hero widget and give it a tag 51 | // that's all you have to do now let's see 52 | // like this youe can animate any widget you want 53 | // thanks for watching 54 | const Hero( 55 | tag: "Zoro", 56 | child: Image( 57 | image: NetworkImage( 58 | "https://i.pinimg.com/originals/3a/bd/73/3abd731ea1a036bbab68e33aa9305434.jpg"), 59 | height: 100, 60 | width: 100, 61 | ), 62 | ), 63 | ElevatedButton( 64 | onPressed: () { 65 | Navigator.of(context).push(MaterialPageRoute( 66 | builder: (context) => const SecondScreen())); 67 | }, 68 | child: const Text("Open next Screen")), 69 | ], 70 | ), 71 | ), 72 | ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /alertdialog/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | 18 | class Home extends StatefulWidget { 19 | const Home({Key? key}) : super(key: key); 20 | 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | @override 27 | Widget build(BuildContext context) { 28 | return Scaffold( 29 | appBar: AppBar( 30 | title: const FittedBox( 31 | child: Text( 32 | "Alert Dialog", 33 | ), 34 | ), 35 | ), 36 | body: SizedBox( 37 | height: double.infinity, 38 | width: double.infinity, 39 | child: Column( 40 | children: [ 41 | ElevatedButton( 42 | onPressed: () { 43 | showDialog( 44 | context: context, 45 | builder: (context) { 46 | return AlertDialog( 47 | title: const Text("Delete Record"), 48 | content: const Text("Do you want to delete"), 49 | actions: [ 50 | TextButton( 51 | onPressed: () { 52 | // add you delete logic here 53 | Navigator.of(context).pop(); 54 | }, 55 | child: const Text("Yes")), 56 | TextButton( 57 | onPressed: () { 58 | // and just close on no 59 | Navigator.of(context).pop(); 60 | }, 61 | child: const Text("No")) 62 | ], 63 | ); 64 | }); 65 | }, 66 | child: const Text("Show Dialog")), 67 | ], 68 | ), 69 | ), 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /jsonserialization/characters.dart: -------------------------------------------------------------------------------- 1 | /* 2 | TO BUILD RUN 3 | 4 | flutter pub run build_runner build 5 | 6 | 7 | */ 8 | 9 | 10 | // you can create by any name you want here my data is list of characters 11 | 12 | // so characters name is more suitable 13 | 14 | // as is said start from inner 15 | // oh! i forgot most import thing 16 | // adding annotatin 17 | import 'package:json_annotation/json_annotation.dart'; // import this 18 | 19 | // 1 more thing 20 | // this file show only our field and class and data type etc this is not actual data class 21 | // we will build that with command 22 | 23 | // so we have to declare that file name 24 | // format -part thisfilename.g.dart 25 | // here our file name is characters so characters.g.dart; 26 | part 'characters.g.dart'; 27 | 28 | @JsonSerializable() // add this to your class 29 | class Character { 30 | // i prefer using null so that if i don't let value it will not break 31 | String? name; 32 | String? image; 33 | // create default constructor 34 | Character({this.image, this.name}); 35 | // this is a fix format / method class.fromJson(Map json) => _$classNameFromJson(json); 36 | // this is to convert json into class object 37 | factory Character.fromJson(Map json) => 38 | _$CharacterFromJson(json); 39 | 40 | // now from class object to json 41 | // format-: Map toJson() => _$classNameToJson(this); 42 | Map toJson() => _$CharacterToJson(this); 43 | } 44 | 45 | // okay we are done with inner most json class now 2 more 46 | // they are same 47 | 48 | @JsonSerializable() 49 | class Results { 50 | List? results; //this is list of character 51 | Results({this.results}); 52 | factory Results.fromJson(Map json) => 53 | _$ResultsFromJson(json); 54 | 55 | Map toJson() => _$ResultsToJson(this); 56 | } 57 | 58 | // this is our outermost json to i named it as response 59 | @JsonSerializable() 60 | class CharactersResponse { 61 | Results? characters; 62 | 63 | CharactersResponse({this.characters}); 64 | 65 | factory CharactersResponse.fromJson(Map json) => 66 | _$CharactersResponseFromJson(json); 67 | 68 | Map toJson() => _$CharactersResponseToJson(this); 69 | } 70 | -------------------------------------------------------------------------------- /navigation/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/screen2.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | void main() { 5 | runApp(const MyApp()); 6 | } 7 | 8 | class MyApp extends StatelessWidget { 9 | const MyApp({Key? key}) : super(key: key); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return const MaterialApp( 14 | home: Home(), 15 | ); 16 | } 17 | } 18 | 19 | class Home extends StatefulWidget { 20 | const Home({Key? key}) : super(key: key); 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | /* 27 | Hey evryone let's see how to navigate between screen 28 | i have already created UI 29 | 30 | */ 31 | 32 | final TextEditingController _editingController = TextEditingController(); 33 | @override 34 | Widget build(BuildContext context) { 35 | return Scaffold( 36 | appBar: AppBar( 37 | title: const FittedBox( 38 | child: Text( 39 | "Navigation", 40 | ), 41 | ), 42 | ), 43 | body: SizedBox( 44 | height: double.infinity, 45 | width: double.infinity, 46 | child: Column( 47 | mainAxisAlignment: MainAxisAlignment.center, 48 | crossAxisAlignment: CrossAxisAlignment.center, 49 | children: [ 50 | Container( 51 | margin: const EdgeInsets.all(20), 52 | child: TextField( 53 | decoration: const InputDecoration( 54 | border: OutlineInputBorder(), 55 | hintText: "Enter Message", 56 | ), 57 | controller: _editingController, 58 | ), 59 | ), 60 | ElevatedButton( 61 | onPressed: () { 62 | String message = _editingController.text.trim(); 63 | // let's see how to open next screen 64 | // now how to pass data from one screen to next 65 | Navigator.of(context).push(MaterialPageRoute( 66 | builder: (context) => SecondScreen(name: message))); 67 | // that's how you move to next screen 68 | 69 | }, 70 | child: const Text("next screen"), 71 | ), 72 | ], 73 | ), 74 | ), 75 | ); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /bottom navigation/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | 18 | class Home extends StatefulWidget { 19 | const Home({Key? key}) : super(key: key); 20 | 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | late PageController _pageController; 27 | 28 | @override 29 | void initState() { 30 | super.initState(); 31 | _pageController = PageController(); 32 | } 33 | 34 | final List _screens = [ 35 | Container( 36 | color: Colors.redAccent, 37 | child: const Text("HOME"), 38 | alignment: Alignment.center, 39 | ), 40 | Container( 41 | color: Colors.greenAccent, 42 | child: const Text("MAP"), 43 | alignment: Alignment.center, 44 | ), 45 | Container( 46 | color: Colors.orangeAccent, 47 | child: const Text("SETTINGS"), 48 | alignment: Alignment.center, 49 | ), 50 | ]; 51 | 52 | int _currentIndex = 0; 53 | @override 54 | Widget build(BuildContext context) { 55 | return Scaffold( 56 | appBar: AppBar( 57 | title: const Text("Bottom Navigation"), 58 | ), 59 | bottomNavigationBar: BottomNavigationBar( 60 | currentIndex: _currentIndex, 61 | onTap: onTabClick, 62 | showSelectedLabels: true, 63 | showUnselectedLabels: false, 64 | items: const [ 65 | BottomNavigationBarItem( 66 | icon: Icon(Icons.house), 67 | label: "Home", 68 | ), 69 | BottomNavigationBarItem( 70 | icon: Icon(Icons.map), 71 | label: "Map", 72 | ), 73 | BottomNavigationBarItem( 74 | icon: Icon(Icons.settings), 75 | label: "Settings", 76 | ), 77 | ]), 78 | body: PageView( 79 | children: _screens, 80 | controller: _pageController, 81 | onPageChanged: pageChanged, 82 | ), 83 | ); 84 | } 85 | 86 | void pageChanged(int index) { 87 | setState(() { 88 | _currentIndex = index; 89 | }); 90 | } 91 | 92 | void onTabClick(int index) { 93 | _pageController.jumpToPage(index); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /sidebar-menu/sidebar_menu.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:testhero/search.dart'; 3 | 4 | class SidebarMenu extends StatefulWidget { 5 | const SidebarMenu({super.key}); 6 | 7 | @override 8 | State createState() => _SidebarMenuState(); 9 | } 10 | 11 | class _SidebarMenuState extends State { 12 | @override 13 | Widget build(BuildContext context) { 14 | return Drawer( 15 | child: ListView( 16 | padding: EdgeInsets.zero, 17 | children: [ 18 | UserAccountsDrawerHeader( 19 | accountName: const Text("User XYZ"), 20 | accountEmail: const Text("userxyz@gmail.com"), 21 | currentAccountPicture: CircleAvatar( 22 | child: ClipOval( 23 | child: Image.network( 24 | "https://images.unsplash.com/photo-1494790108377-be9c29b29330", 25 | height: 90, 26 | width: 90, 27 | fit: BoxFit.cover, 28 | ), 29 | ), 30 | ), 31 | decoration: const BoxDecoration( 32 | image: DecorationImage( 33 | image: NetworkImage( 34 | "https://images.unsplash.com/photo-1701205395454-eafa6ea02920", 35 | ), 36 | fit: BoxFit.cover, 37 | ), 38 | ), 39 | ), 40 | const ListTile( 41 | leading: Icon(Icons.home), 42 | title: Text("Home"), 43 | ), 44 | InkWell( 45 | onTap: () { 46 | Navigator.of(context).pop(); 47 | Navigator.of(context) 48 | .push(MaterialPageRoute(builder: (_) => const Search())); 49 | }, 50 | child: const ListTile( 51 | leading: Icon(Icons.search), 52 | title: Text("Search"), 53 | ), 54 | ), 55 | const ListTile( 56 | leading: Icon(Icons.share), 57 | title: Text("Share"), 58 | ), 59 | const Divider(), 60 | const ListTile( 61 | leading: Icon(Icons.security), 62 | title: Text("Privacy Policy"), 63 | ), 64 | const ListTile( 65 | leading: Icon(Icons.settings), 66 | title: Text("Settings"), 67 | ), 68 | const ListTile( 69 | leading: Icon( 70 | Icons.logout, 71 | color: Colors.redAccent, 72 | ), 73 | title: Text("Logout"), 74 | ) 75 | 76 | ], 77 | ), 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /bottom sheet/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return const MaterialApp( 13 | home: Home(), 14 | ); 15 | } 16 | } 17 | 18 | class Home extends StatefulWidget { 19 | const Home({Key? key}) : super(key: key); 20 | @override 21 | State createState() => _HomeState(); 22 | } 23 | 24 | class _HomeState extends State { 25 | 26 | @override 27 | Widget build(BuildContext context) { 28 | return Scaffold( 29 | appBar: AppBar( 30 | title: const FittedBox( 31 | child: Text( 32 | "Bottom Sheet", 33 | ), 34 | ), 35 | ), 36 | body: Column( 37 | children: [ 38 | ElevatedButton( 39 | onPressed: () { 40 | showModalBottomSheet( 41 | context: context, 42 | backgroundColor: Colors.grey.shade100, 43 | constraints: const BoxConstraints(maxHeight: 200), 44 | shape: const RoundedRectangleBorder( 45 | borderRadius: BorderRadius.only( 46 | topLeft: Radius.circular(20), 47 | topRight: Radius.circular(20), 48 | )), 49 | builder: (context) { 50 | return Container( 51 | padding: const EdgeInsets.all(20), 52 | child: Column( 53 | children: [ 54 | const TextField( 55 | decoration: InputDecoration( 56 | border: OutlineInputBorder(), 57 | hintText: "Enter your age"), 58 | ), 59 | const SizedBox( 60 | height: 10, 61 | ), 62 | SizedBox( 63 | width: double.infinity, 64 | child: ElevatedButton( 65 | onPressed: () {}, 66 | child: const Text('Submit'), 67 | ), 68 | ), 69 | ], 70 | ), 71 | ); 72 | }); 73 | }, 74 | child: const Text('Show Bottom Sheet')), 75 | ], 76 | ), 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /notification/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:awesome_notifications/awesome_notifications.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | void main() async { 5 | AwesomeNotifications().initialize( 6 | null, 7 | 8 | [ 9 | NotificationChannel( 10 | 11 | channelGroupKey: 'basic_tests', 12 | channelKey: 'basic_channel', 13 | channelName: 'Basic notifications', 14 | channelDescription: 'Notification channel for basic tests', 15 | defaultColor: const Color(0xFF9D50DD), 16 | ledColor: Colors.white, 17 | importance: NotificationImportance 18 | .High, 19 | ), 20 | ]); 21 | 22 | runApp(const MyApp()); 23 | } 24 | 25 | class MyApp extends StatelessWidget { 26 | const MyApp({Key? key}) : super(key: key); 27 | 28 | @override 29 | Widget build(BuildContext context) { 30 | return const MaterialApp( 31 | home: Home(), 32 | ); 33 | } 34 | } 35 | 36 | class Home extends StatefulWidget { 37 | const Home({Key? key}) : super(key: key); 38 | 39 | @override 40 | State createState() => _HomeState(); 41 | } 42 | 43 | class _HomeState extends State { 44 | 45 | 46 | @override 47 | void initState() { 48 | AwesomeNotifications().actionStream.listen((event) { 49 | print(event.body); 50 | }); 51 | super.initState(); 52 | } 53 | 54 | @override 55 | Widget build(BuildContext context) { 56 | return Scaffold( 57 | backgroundColor: Colors.grey.shade300, 58 | appBar: AppBar( 59 | title: const Text("Local Notification"), 60 | ), 61 | body: SizedBox( 62 | height: double.infinity, 63 | width: double.infinity, 64 | child: Column( 65 | mainAxisAlignment: MainAxisAlignment.center, 66 | crossAxisAlignment: CrossAxisAlignment.center, 67 | children: [ 68 | ElevatedButton( 69 | onPressed: () { 70 | AwesomeNotifications().createNotification( 71 | content: NotificationContent( 72 | channelKey: "basic_channel", 73 | id: 1, 74 | title: "Notification title", 75 | body: "Notification body", 76 | bigPicture: 77 | "https://images.unsplash.com/photo-1656274990019-979c5d603bb5", 78 | notificationLayout: NotificationLayout.BigPicture, 79 | ), 80 | ); 81 | }, 82 | child: const Text("Show Notification"), 83 | ) 84 | ], 85 | ), 86 | ), 87 | 88 | ); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /newsapp/news_model.dart: -------------------------------------------------------------------------------- 1 | // this is our model class 2 | // let me show you a simplest way to create this 3 | // that's how i created this 4 | 5 | class NewsResponse { 6 | String? status; 7 | int? totalResults; 8 | List? articles; 9 | 10 | NewsResponse({this.status, this.totalResults, this.articles}); 11 | 12 | NewsResponse.fromJson(Map json) { 13 | status = json['status']; 14 | totalResults = json['totalResults']; 15 | if (json['articles'] != null) { 16 | articles = []; 17 | json['articles'].forEach((v) { 18 | articles!.add(Articles.fromJson(v)); 19 | }); 20 | } 21 | } 22 | 23 | Map toJson() { 24 | final Map data = {}; 25 | data['status'] = status; 26 | data['totalResults'] = totalResults; 27 | if (articles != null) { 28 | data['articles'] = articles!.map((v) => v.toJson()).toList(); 29 | } 30 | return data; 31 | } 32 | } 33 | 34 | class Articles { 35 | Source? source; 36 | String? author; 37 | String? title; 38 | String? description; 39 | String? url; 40 | String? urlToImage; 41 | String? publishedAt; 42 | String? content; 43 | 44 | Articles( 45 | {this.source, 46 | this.author, 47 | this.title, 48 | this.description, 49 | this.url, 50 | this.urlToImage, 51 | this.publishedAt, 52 | this.content}); 53 | 54 | Articles.fromJson(Map json) { 55 | source = json['source'] != null ? Source.fromJson(json['source']) : null; 56 | author = json['author']; 57 | title = json['title']; 58 | description = json['description']; 59 | url = json['url']; 60 | urlToImage = json['urlToImage']; 61 | publishedAt = json['publishedAt']; 62 | content = json['content']; 63 | } 64 | 65 | Map toJson() { 66 | final Map data = {}; 67 | if (source != null) { 68 | data['source'] = source!.toJson(); 69 | } 70 | data['author'] = author; 71 | data['title'] = title; 72 | data['description'] = description; 73 | data['url'] = url; 74 | data['urlToImage'] = urlToImage; 75 | data['publishedAt'] = publishedAt; 76 | data['content'] = content; 77 | return data; 78 | } 79 | } 80 | 81 | class Source { 82 | String? id; 83 | String? name; 84 | 85 | Source({this.id, this.name}); 86 | 87 | Source.fromJson(Map json) { 88 | id = json['id']; 89 | name = json['name']; 90 | } 91 | 92 | Map toJson() { 93 | final Map data = {}; 94 | data['id'] = id; 95 | data['name'] = name; 96 | return data; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /gradient_border/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:gradient_borders/gradient_borders.dart'; 3 | 4 | void main() { 5 | runApp(const MyApp()); 6 | } 7 | 8 | class MyApp extends StatelessWidget { 9 | const MyApp({Key? key}) : super(key: key); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return const MaterialApp( 14 | home: Home(), 15 | ); 16 | } 17 | } 18 | 19 | class Home extends StatefulWidget { 20 | const Home({Key? key}) : super(key: key); 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | /* 27 | hey everyone , let's see how can we give gradient border to a textfield and image 28 | you may have see instagram it's showing gradient border around story 29 | so to do this we will use a plugin 30 | let's start 31 | 32 | thanks for watching 33 | */ 34 | @override 35 | Widget build(BuildContext context) { 36 | return Scaffold( 37 | appBar: AppBar( 38 | title: const FittedBox( 39 | child: Text( 40 | "Gradient Border", 41 | ), 42 | ), 43 | ), 44 | body: Column( 45 | children: [ 46 | Container( 47 | margin: const EdgeInsets.all(20), 48 | child: const TextField( 49 | decoration: InputDecoration( 50 | hintText: "Enter your name", 51 | border: GradientOutlineInputBorder( 52 | width: 2.0, 53 | borderRadius: BorderRadius.all(Radius.circular(10)), 54 | gradient: LinearGradient(colors: [Colors.green, Colors.red]), 55 | ), 56 | ), 57 | ), 58 | ), //that's how you can give gradient border to textfield 59 | 60 | // now lets how to give rounded gradient to a image 61 | Container( 62 | height: 100, 63 | width: 100, 64 | decoration: BoxDecoration( 65 | border: const GradientBoxBorder( 66 | gradient: LinearGradient(colors: [ 67 | Colors.redAccent, 68 | Colors.greenAccent, 69 | Colors.blue 70 | ]), 71 | width: 5, 72 | ), 73 | borderRadius: BorderRadius.circular(50), 74 | ), 75 | child: ClipRRect( 76 | borderRadius: BorderRadius.circular(50), 77 | child: const Image( 78 | image: NetworkImage( 79 | "https://w0.peakpx.com/wallpaper/331/150/HD-wallpaper-sad-boy-hotaro-art-cartoon-sadboy-dark-hotarooreki-feeling-anime-thumbnail.jpg", 80 | ), 81 | ), 82 | ), 83 | ) 84 | ], 85 | ), 86 | ); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /multiplatform/news_model.dart: -------------------------------------------------------------------------------- 1 | // this is our model class 2 | // let me show you a simplest way to create this 3 | // that's how i created this 4 | 5 | class NewsResponse { 6 | String? status; 7 | int? totalResults; 8 | List? articles; 9 | 10 | NewsResponse({this.status, this.totalResults, this.articles}); 11 | 12 | NewsResponse.fromJson(Map json) { 13 | status = json['status']; 14 | totalResults = json['totalResults']; 15 | if (json['articles'] != null) { 16 | articles = []; 17 | json['articles'].forEach((v) { 18 | articles!.add(Articles.fromJson(v)); 19 | }); 20 | } 21 | } 22 | 23 | Map toJson() { 24 | final Map data = {}; 25 | data['status'] = status; 26 | data['totalResults'] = totalResults; 27 | if (articles != null) { 28 | data['articles'] = articles!.map((v) => v.toJson()).toList(); 29 | } 30 | return data; 31 | } 32 | } 33 | 34 | class Articles { 35 | Source? source; 36 | String? author; 37 | String? title; 38 | String? description; 39 | String? url; 40 | String? urlToImage; 41 | String? publishedAt; 42 | String? content; 43 | 44 | Articles( 45 | {this.source, 46 | this.author, 47 | this.title, 48 | this.description, 49 | this.url, 50 | this.urlToImage, 51 | this.publishedAt, 52 | this.content}); 53 | 54 | Articles.fromJson(Map json) { 55 | source = json['source'] != null ? Source.fromJson(json['source']) : null; 56 | author = json['author']; 57 | title = json['title']; 58 | description = json['description']; 59 | url = json['url']; 60 | urlToImage = json['urlToImage']; 61 | publishedAt = json['publishedAt']; 62 | content = json['content']; 63 | } 64 | 65 | Map toJson() { 66 | final Map data = {}; 67 | if (source != null) { 68 | data['source'] = source!.toJson(); 69 | } 70 | data['author'] = author; 71 | data['title'] = title; 72 | data['description'] = description; 73 | data['url'] = url; 74 | data['urlToImage'] = urlToImage; 75 | data['publishedAt'] = publishedAt; 76 | data['content'] = content; 77 | return data; 78 | } 79 | } 80 | 81 | class Source { 82 | String? id; 83 | String? name; 84 | 85 | Source({this.id, this.name}); 86 | 87 | Source.fromJson(Map json) { 88 | id = json['id']; 89 | name = json['name']; 90 | } 91 | 92 | Map toJson() { 93 | final Map data = {}; 94 | data['id'] = id; 95 | data['name'] = name; 96 | return data; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /spinthewheel/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | 5 | void main() { 6 | runApp(const MyApp()); 7 | } 8 | 9 | class MyApp extends StatelessWidget { 10 | const MyApp({super.key}); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return const MaterialApp( 15 | home: SpinTheWheel(), 16 | ); 17 | } 18 | } 19 | 20 | class SpinTheWheel extends StatefulWidget { 21 | const SpinTheWheel({super.key}); 22 | 23 | @override 24 | State createState() => SpinTheWheelState(); 25 | } 26 | 27 | class SpinTheWheelState extends State { 28 | double turns = 0.0; 29 | Random random = Random(); 30 | int rotation = 1; 31 | int luck = 0; 32 | void _changeRotation() { 33 | rotation++; 34 | luck = random.nextInt(10); 35 | setState(() => turns = (10 * rotation) + ((luck % 10) / 10)); 36 | } 37 | 38 | List options = [ 39 | "Jackpot", 40 | "200", 41 | "500", 42 | "Lose", 43 | "100", 44 | "1000", 45 | "200", 46 | "500", 47 | "Lose", 48 | "100", 49 | ]; 50 | 51 | String selected = ""; 52 | @override 53 | Widget build(BuildContext context) { 54 | return Scaffold( 55 | backgroundColor: const Color(0xFF030307), 56 | body: Column( 57 | mainAxisAlignment: MainAxisAlignment.center, 58 | children: [ 59 | Transform.translate( 60 | offset: const Offset(0, 80), 61 | child: const Image( 62 | image: AssetImage("assets/bottom_arrow.png"), 63 | height: 60, 64 | ), 65 | ), 66 | Padding( 67 | padding: const EdgeInsets.symmetric( 68 | horizontal: 50, 69 | vertical: 10, 70 | ), 71 | child: AnimatedRotation( 72 | onEnd: () { 73 | setState(() { 74 | selected = options[luck % 10]; 75 | }); 76 | }, 77 | turns: turns, 78 | duration: const Duration(seconds: 1), 79 | child: const Image( 80 | image: AssetImage("assets/wheel.png"), 81 | height: 400, 82 | width: 400, 83 | fit: BoxFit.cover, 84 | ), 85 | ), 86 | ), 87 | if (selected.isNotEmpty) 88 | Text( 89 | "You Got : $selected", 90 | style: const TextStyle( 91 | fontSize: 20, 92 | color: Colors.white, 93 | ), 94 | ), 95 | ElevatedButton( 96 | onPressed: _changeRotation, 97 | child: const Text('Spin'), 98 | ), 99 | ], 100 | ), 101 | ); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /user-form/home_screen.dart: -------------------------------------------------------------------------------- 1 | // Home Screen Widget 2 | import 'package:flutter/material.dart'; 3 | 4 | class HomeScreen extends StatelessWidget { 5 | const HomeScreen({super.key}); 6 | 7 | @override 8 | Widget build(BuildContext context) { 9 | return Scaffold( 10 | appBar: AppBar( 11 | title: const Text( 12 | 'Welcome Home!', 13 | style: TextStyle( 14 | color: Colors.white, 15 | ), 16 | ), 17 | iconTheme: const IconThemeData( 18 | color: Colors.white, 19 | ), 20 | backgroundColor: Colors.blueAccent, 21 | ), 22 | body: Container( 23 | decoration: const BoxDecoration( 24 | gradient: LinearGradient( 25 | colors: [ 26 | Colors.blueAccent, 27 | Colors.lightBlueAccent, 28 | ], 29 | begin: Alignment.topCenter, 30 | end: Alignment.bottomCenter, 31 | ), 32 | ), 33 | child: Center( 34 | child: Padding( 35 | padding: const EdgeInsets.all(20.0), 36 | child: Column( 37 | mainAxisAlignment: MainAxisAlignment.center, 38 | crossAxisAlignment: CrossAxisAlignment.center, 39 | children: [ 40 | AnimatedContainer( 41 | duration: const Duration(seconds: 1), 42 | curve: Curves.easeInOut, 43 | height: 120, 44 | width: 120, 45 | decoration: BoxDecoration( 46 | shape: BoxShape.circle, 47 | color: Colors.white.withOpacity(0.9), 48 | boxShadow: const [ 49 | BoxShadow( 50 | color: Colors.black26, 51 | blurRadius: 10, 52 | offset: Offset(0, 5), 53 | ), 54 | ], 55 | ), 56 | child: const Icon( 57 | Icons.check_circle_outline, 58 | size: 80, 59 | color: Colors.green, 60 | ), 61 | ), 62 | const SizedBox(height: 20), 63 | const Text( 64 | 'Congratulations!', 65 | style: TextStyle( 66 | fontSize: 30, 67 | fontWeight: FontWeight.bold, 68 | color: Colors.white, 69 | ), 70 | ), 71 | const SizedBox(height: 10), 72 | const Text( 73 | 'You have successfully completed the form.', 74 | style: TextStyle( 75 | fontSize: 18, 76 | color: Colors.white70, 77 | ), 78 | textAlign: TextAlign.center, 79 | ), 80 | ], 81 | ), 82 | ), 83 | ), 84 | ), 85 | ); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /http/main.dart: -------------------------------------------------------------------------------- 1 | // add http plugin 2 | 3 | import 'dart:convert'; 4 | 5 | import 'package:flutter/material.dart'; 6 | import 'package:http/http.dart' as http; 7 | 8 | void main() { 9 | runApp(const MyApp()); 10 | } 11 | 12 | class MyApp extends StatelessWidget { 13 | const MyApp({Key? key}) : super(key: key); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | return const MaterialApp( 18 | home: Home(), 19 | ); 20 | } 21 | } 22 | 23 | class Home extends StatefulWidget { 24 | const Home({Key? key}) : super(key: key); 25 | 26 | @override 27 | State createState() => _HomeState(); 28 | } 29 | 30 | class _HomeState extends State { 31 | bool _loading = false; 32 | List _users = []; 33 | 34 | @override 35 | Widget build(BuildContext context) { 36 | return Scaffold( 37 | appBar: AppBar( 38 | title: const FittedBox( 39 | child: Text( 40 | "API Call", 41 | ), 42 | ), 43 | ), 44 | body: _users.isNotEmpty 45 | ? ListView.builder( 46 | itemCount: _users.length, 47 | itemBuilder: ((context, index) { 48 | return Card( 49 | margin: const EdgeInsets.symmetric( 50 | horizontal: 15.0, 51 | vertical: 10.0, 52 | ), 53 | child: Padding( 54 | padding: const EdgeInsets.all(8.0), 55 | child: Row( 56 | children: [ 57 | Image.network(_users[index]['image']), 58 | Column( 59 | mainAxisAlignment: MainAxisAlignment.start, 60 | crossAxisAlignment: CrossAxisAlignment.start, 61 | children: [ 62 | Text(_users[index]['firstName']), 63 | Text(_users[index]['email']), 64 | Text(_users[index]['phone']), 65 | ], 66 | ) 67 | ], 68 | ), 69 | ), 70 | ); 71 | }), 72 | ) 73 | : Center( 74 | child: _loading 75 | ? CircularProgressIndicator() 76 | : ElevatedButton( 77 | child: const Text("fetch users"), 78 | onPressed: loadUserList, 79 | ), 80 | ), 81 | ); 82 | } 83 | 84 | loadUserList() async { 85 | setState(() { 86 | _loading = true; 87 | }); 88 | var res = await http.get(Uri.https("dummyjson.com", "users")); 89 | if (res.statusCode == 200) { 90 | var jsonData = jsonDecode(res.body); 91 | if (jsonData['users'].isNotEmpty) { 92 | setState(() { 93 | _users = jsonData['users']; 94 | _loading = false; 95 | }); 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /pagetransition/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/screen2.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | void main() { 5 | runApp(const MyApp()); 6 | } 7 | 8 | class MyApp extends StatelessWidget { 9 | const MyApp({Key? key}) : super(key: key); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | return const MaterialApp( 14 | home: Home(), 15 | ); 16 | } 17 | } 18 | 19 | class Home extends StatefulWidget { 20 | const Home({Key? key}) : super(key: key); 21 | @override 22 | State createState() => _HomeState(); 23 | } 24 | 25 | class _HomeState extends State { 26 | /* 27 | Hey Everyone let's see how you can animation page transition 28 | so we are going to see slide animation 29 | first let's see UI 30 | it's a simple UI with Text and button to open next screen 31 | let's animate new screen opening 32 | 33 | 34 | */ 35 | 36 | @override 37 | Widget build(BuildContext context) { 38 | return Scaffold( 39 | backgroundColor: Colors.cyanAccent, 40 | appBar: AppBar( 41 | title: const FittedBox( 42 | child: Text( 43 | "Page Transition", 44 | ), 45 | ), 46 | ), 47 | body: SizedBox( 48 | height: double.infinity, 49 | width: double.infinity, 50 | child: Column( 51 | mainAxisAlignment: MainAxisAlignment.center, 52 | crossAxisAlignment: CrossAxisAlignment.center, 53 | children: [ 54 | const Text("Page 1"), 55 | ElevatedButton( 56 | onPressed: () { 57 | // this is normal code opening screen 58 | 59 | Navigator.of(context).push( 60 | PageRouteBuilder( 61 | transitionDuration: const Duration( 62 | milliseconds: 700), //you can set duration 63 | reverseTransitionDuration: 64 | const Duration(milliseconds: 700), 65 | pageBuilder: (context, animation, secondaryAnimation) => 66 | const SecondScreen(), 67 | transitionsBuilder: 68 | (context, animation, secondaryAnimation, child) { 69 | const begin = Offset(1.0, 0.0); // initial page position 70 | const end = Offset.zero; // last page position 71 | const curve = Curves.easeInToLinear; // try whatever you like 72 | // that's it thanks for watching 73 | 74 | 75 | var tween = Tween(begin: begin, end: end) 76 | .chain(CurveTween(curve: curve)); 77 | 78 | return SlideTransition( 79 | position: animation.drive(tween), 80 | child: child, 81 | ); 82 | }), // that's it let run it 83 | ); 84 | }, 85 | child: const Text("Open next Screen"), 86 | ), 87 | ], 88 | ), 89 | ), 90 | ); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /carouselview/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() { 4 | runApp(const MyApp()); 5 | } 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({super.key}); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return MaterialApp( 13 | title: 'Flutter Demo', 14 | theme: ThemeData( 15 | colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), 16 | useMaterial3: true, 17 | ), 18 | home: const MyHomePage(title: 'Flutter Demo Home Page'), 19 | ); 20 | } 21 | } 22 | 23 | class MyHomePage extends StatefulWidget { 24 | const MyHomePage({super.key, required this.title}); 25 | 26 | final String title; 27 | 28 | @override 29 | State createState() => _MyHomePageState(); 30 | } 31 | 32 | class _MyHomePageState extends State { 33 | @override 34 | Widget build(BuildContext context) { 35 | return Scaffold( 36 | appBar: AppBar( 37 | backgroundColor: Theme.of(context).colorScheme.inversePrimary, 38 | title: Text(widget.title), 39 | ), 40 | body: Column( 41 | children: [ 42 | SizedBox( 43 | // remember carousel is a widget which requires height , so don't miss this 44 | height: 250, 45 | child: CarouselView( 46 | // here is our new widget 47 | elevation: 2, 48 | onTap: (tapIndex) { 49 | // this also give onTap option 50 | _showImageDialog( 51 | context, // here we are just popping the image on Tap 52 | "https://api.slingacademy.com/public/sample-photos/${tapIndex + 1}.jpeg"); 53 | }, 54 | padding: const EdgeInsets.all(10), 55 | itemExtent: MediaQuery.of(context).size.width - 56 | 30, // this is required field , this defines the width of the item/slide 57 | itemSnapping: 58 | true, // this is to ensure we slide complete between to item 59 | children: List.generate(10, (index) { 60 | // i'm just useing List generate to show 10 image 61 | return Image( 62 | image: NetworkImage( 63 | "https://api.slingacademy.com/public/sample-photos/${index + 1}.jpeg"), 64 | ); 65 | }), 66 | ), 67 | ), 68 | ], 69 | ), 70 | ); 71 | } 72 | 73 | void _showImageDialog(BuildContext context, String imageUrl) { 74 | // this is our simple dialog display code 75 | showDialog( 76 | context: context, 77 | builder: (BuildContext context) { 78 | return Dialog( 79 | child: Column( 80 | mainAxisSize: MainAxisSize.min, 81 | children: [ 82 | Image.network(imageUrl), 83 | TextButton( 84 | onPressed: () { 85 | Navigator.of(context).pop(); 86 | }, 87 | child: const Text('Close'), 88 | ), 89 | ], 90 | ), 91 | ); 92 | }, 93 | ); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /searchbar/product_item.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | import 'package:dummy/product_details.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class ProductItem extends StatelessWidget { 6 | final Product product; 7 | const ProductItem({super.key, required this.product}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Container( 12 | margin: const EdgeInsets.symmetric( 13 | horizontal: 15, 14 | vertical: 8, 15 | ), 16 | decoration: BoxDecoration( 17 | borderRadius: BorderRadius.circular(10), 18 | border: Border.all(color: Colors.grey), 19 | ), 20 | padding: const EdgeInsets.all(15), 21 | alignment: Alignment.center, 22 | child: Column( 23 | mainAxisAlignment: MainAxisAlignment.start, 24 | crossAxisAlignment: CrossAxisAlignment.start, 25 | children: [ 26 | InkWell( 27 | onTap: () { 28 | FocusScope.of(context).requestFocus(FocusNode()); 29 | Navigator.of(context).push( 30 | MaterialPageRoute( 31 | builder: (context) => ProductDetails( 32 | product: product, 33 | ), 34 | ), 35 | ); 36 | }, 37 | child: Hero( 38 | tag: product.thumbnail ?? '', 39 | child: Container( 40 | height: 120, 41 | decoration: BoxDecoration( 42 | color: const Color(0xFFD5DCDE), 43 | borderRadius: BorderRadius.circular(10), 44 | ), 45 | alignment: Alignment.center, 46 | child: Image.network( 47 | product.thumbnail ?? '', 48 | ), 49 | ), 50 | ), 51 | ), 52 | const SizedBox( 53 | height: 10, 54 | ), 55 | Material( 56 | color: Colors.transparent, 57 | child: Hero( 58 | tag: product.title ?? '', 59 | child: Material( 60 | color: Colors.transparent, 61 | child: Text( 62 | product.title ?? '', 63 | style: const TextStyle( 64 | fontWeight: FontWeight.w500, 65 | fontSize: 16, 66 | overflow: TextOverflow.ellipsis, 67 | ), 68 | ), 69 | ), 70 | ), 71 | ), 72 | Row( 73 | children: [ 74 | Text( 75 | "\$ ${product.price}", 76 | style: const TextStyle( 77 | fontWeight: FontWeight.w500, 78 | fontSize: 14, 79 | ), 80 | ), 81 | const SizedBox( 82 | width: 10, 83 | ), 84 | const Icon( 85 | Icons.star, 86 | color: Colors.amberAccent, 87 | ), 88 | Text( 89 | "${product.rating}", 90 | style: const TextStyle( 91 | fontWeight: FontWeight.w500, 92 | fontSize: 14, 93 | ), 94 | ), 95 | ], 96 | ) 97 | ], 98 | ), 99 | ); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /search-delegates/product_item.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | import 'package:dummy/product_details.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | class ProductItem extends StatelessWidget { 6 | final Product product; 7 | const ProductItem({super.key, required this.product}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Container( 12 | margin: const EdgeInsets.symmetric( 13 | horizontal: 15, 14 | vertical: 8, 15 | ), 16 | decoration: BoxDecoration( 17 | borderRadius: BorderRadius.circular(10), 18 | border: Border.all(color: Colors.grey), 19 | ), 20 | padding: const EdgeInsets.all(15), 21 | alignment: Alignment.center, 22 | child: Column( 23 | mainAxisAlignment: MainAxisAlignment.start, 24 | crossAxisAlignment: CrossAxisAlignment.start, 25 | children: [ 26 | InkWell( 27 | onTap: () { 28 | FocusScope.of(context).requestFocus(FocusNode()); 29 | Navigator.of(context).push( 30 | MaterialPageRoute( 31 | builder: (context) => ProductDetails( 32 | product: product, 33 | ), 34 | ), 35 | ); 36 | }, 37 | child: Hero( 38 | tag: product.thumbnail ?? '', 39 | child: Container( 40 | height: 120, 41 | decoration: BoxDecoration( 42 | color: const Color(0xFFD5DCDE), 43 | borderRadius: BorderRadius.circular(10), 44 | ), 45 | alignment: Alignment.center, 46 | child: Image.network( 47 | product.thumbnail ?? '', 48 | ), 49 | ), 50 | ), 51 | ), 52 | const SizedBox( 53 | height: 10, 54 | ), 55 | Material( 56 | color: Colors.transparent, 57 | child: Hero( 58 | tag: product.title ?? '', 59 | child: Material( 60 | color: Colors.transparent, 61 | child: Text( 62 | product.title ?? '', 63 | style: const TextStyle( 64 | fontWeight: FontWeight.w500, 65 | fontSize: 16, 66 | overflow: TextOverflow.ellipsis, 67 | ), 68 | ), 69 | ), 70 | ), 71 | ), 72 | Row( 73 | children: [ 74 | Text( 75 | "\$ ${product.price}", 76 | style: const TextStyle( 77 | fontWeight: FontWeight.w500, 78 | fontSize: 14, 79 | ), 80 | ), 81 | const SizedBox( 82 | width: 10, 83 | ), 84 | const Icon( 85 | Icons.star, 86 | color: Colors.amberAccent, 87 | ), 88 | Text( 89 | "${product.rating}", 90 | style: const TextStyle( 91 | fontWeight: FontWeight.w500, 92 | fontSize: 14, 93 | ), 94 | ), 95 | ], 96 | ) 97 | ], 98 | ), 99 | ); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /multiplatform/news_layout.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutternews/news_model.dart'; 3 | import 'package:intl/intl.dart'; 4 | 5 | class NewsLayout extends StatelessWidget { 6 | final Articles news; 7 | const NewsLayout({super.key, required this.news}); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Container( 12 | color: const Color(0xFF060930), 13 | child: Column( 14 | children: [ 15 | // first we have image 16 | Image( 17 | image: NetworkImage(news.urlToImage ?? 18 | ''), // network image for showing image with url 19 | 20 | fit: BoxFit.cover, 21 | errorBuilder: (context, error, stackTrace) { 22 | // on error we are showing this 23 | return Container( 24 | height: 200, 25 | alignment: Alignment.center, 26 | child: const Text( 27 | "Failed to load image", 28 | style: TextStyle( 29 | fontSize: 12, 30 | color: Colors.white60, 31 | ), 32 | ), 33 | ); 34 | }, 35 | ), 36 | 37 | // then we are showing author if it's null then unknown 38 | Container( 39 | margin: const EdgeInsets.symmetric( 40 | vertical: 10, 41 | horizontal: 15, 42 | ), 43 | child: Row( 44 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 45 | children: [ 46 | Text( 47 | news.author ?? 'Unknown', 48 | style: const TextStyle( 49 | fontSize: 12, 50 | color: Colors.white60, 51 | ), 52 | ), 53 | // date time ,fot this DateTime format you need plugin intl 54 | 55 | Text( 56 | DateFormat("dd MMM").format( 57 | DateTime.parse(news.publishedAt ?? ''), 58 | ), 59 | style: const TextStyle( 60 | fontSize: 12, 61 | color: Colors.white60, 62 | ), 63 | ) 64 | ], 65 | ), 66 | ), 67 | // title of news 68 | Container( 69 | margin: const EdgeInsets.symmetric( 70 | horizontal: 15, 71 | ), 72 | child: Text( 73 | news.title ?? '', 74 | style: const TextStyle( 75 | fontSize: 16, 76 | color: Colors.white, 77 | fontWeight: FontWeight.w500, 78 | ), 79 | ), 80 | ), 81 | // and finally content 82 | // simple right 83 | 84 | Container( 85 | margin: const EdgeInsets.symmetric( 86 | horizontal: 15, 87 | vertical: 15, 88 | ), 89 | child: Text( 90 | news.content ?? '', 91 | style: const TextStyle( 92 | fontSize: 14, 93 | color: Colors.white, 94 | ), 95 | ), 96 | ), 97 | ], 98 | ), 99 | ); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /story/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | story_view: ^0.14.0 # add this plugin 4 | 5 | https://pub.dev/packages/story_view 6 | 7 | */ 8 | 9 | 10 | import 'package:flutter/material.dart'; 11 | import 'package:flutterdemo/story_screen.dart'; 12 | import 'package:story_view/story_view.dart'; 13 | 14 | void main() { 15 | runApp(const MyApp()); 16 | } 17 | 18 | class MyApp extends StatelessWidget { 19 | const MyApp({super.key}); 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | return const MaterialApp( 24 | home: Home(), 25 | debugShowCheckedModeBanner: false, 26 | ); 27 | } 28 | } 29 | 30 | class Home extends StatefulWidget { 31 | const Home({super.key}); 32 | 33 | @override 34 | State createState() => _HomeState(); 35 | } 36 | 37 | /* 38 | 39 | Hi everyone , today we will see how to show status like whatsapp or story like instagram 40 | 41 | first let's see demo then we will see code 42 | okay now let's see how to build this 43 | first plugin 44 | so flow for this demo is when you click on this image it open a screen with these image and video which shows them as story with story widget 45 | 46 | so let's see data first 47 | 48 | 49 | thanks for watching 50 | please like and subcribe 51 | 52 | */ 53 | 54 | class _HomeState extends State { 55 | final controller = StoryController(); // controller 56 | List storyItems = []; // empty story item list , storyitem can be video/image etc 57 | @override 58 | void initState() { 59 | storyItems = [ 60 | StoryItem.pageImage( 61 | url: 'https://images.pexels.com/photos/674010/pexels-photo-674010.jpeg', 62 | controller: controller, 63 | ), 64 | StoryItem.pageImage( 65 | url: 'https://images.unsplash.com/photo-1616578492900-ea5a8fc6c341', 66 | controller: controller, 67 | ), 68 | StoryItem.pageImage( 69 | url: 'https://images.unsplash.com/photo-1604311795833-25e1d5c128c6', 70 | controller: controller, 71 | ), 72 | StoryItem.pageVideo( 73 | 'https://static.videezy.com/system/resources/previews/000/049/065/original/Sequence-05.mp4', 74 | controller: controller, 75 | ), 76 | StoryItem.pageVideo( 77 | 'https://static.videezy.com/system/resources/previews/000/047/810/original/Christmas_Decoration_42.mp4', 78 | controller: controller, 79 | ), 80 | ]; // we got 3 images and 2 video here 81 | 82 | super.initState(); 83 | } 84 | 85 | @override 86 | Widget build(BuildContext context) { 87 | return Scaffold( 88 | appBar: AppBar( 89 | title: const Text("Story Demo"), 90 | ), 91 | body: Column( 92 | mainAxisAlignment: MainAxisAlignment.center, 93 | crossAxisAlignment: CrossAxisAlignment.center, 94 | mainAxisSize: MainAxisSize.max, 95 | children: [ 96 | // this is our image which you can see 97 | GestureDetector( 98 | onTap: () { 99 | // on click open StoryScreen with controller and storyItems 100 | // now lets see our storyscreen 101 | Navigator.of(context).push( 102 | MaterialPageRoute( 103 | builder: (context) => StoryScreen( 104 | controller: controller, storyItems: storyItems), 105 | ), 106 | ); 107 | }, 108 | child: const Center( 109 | child: CircleAvatar( 110 | radius: 30, 111 | backgroundImage: AssetImage("assets/aniket.jpg"), 112 | ), 113 | ), 114 | ), 115 | ], 116 | ), 117 | ); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /GraphQL/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | add plugins 4 | http: ^0.13.4 5 | graphql_flutter: ^5.1.0 6 | 7 | */ 8 | 9 | import 'package:flutter/material.dart'; 10 | import 'package:graphql_flutter/graphql_flutter.dart'; 11 | 12 | void main() async { 13 | WidgetsFlutterBinding.ensureInitialized(); 14 | await initHiveForFlutter(); // for cache 15 | runApp(const MyApp()); 16 | } 17 | 18 | class MyApp extends StatelessWidget { 19 | const MyApp({Key? key}) : super(key: key); 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | return MaterialApp( 24 | title: 'GraphQL Demo', 25 | theme: ThemeData( 26 | primarySwatch: Colors.blue, 27 | ), 28 | home: const MyHomePage(title: 'GraphQL Demo'), 29 | ); 30 | } 31 | } 32 | 33 | class MyHomePage extends StatefulWidget { 34 | const MyHomePage({Key? key, required this.title}) : super(key: key); 35 | final String title; 36 | @override 37 | State createState() => _MyHomePageState(); 38 | } 39 | 40 | class _MyHomePageState extends State { 41 | List characters = []; 42 | bool _loading = false; 43 | 44 | @override 45 | Widget build(BuildContext context) { 46 | return Scaffold( 47 | appBar: AppBar( 48 | title: Text(widget.title), 49 | ), 50 | body: _loading 51 | ? const CircularProgressIndicator() 52 | : characters.isEmpty 53 | ? Center( 54 | child: ElevatedButton( 55 | child: const Text("Fetch Data"), 56 | onPressed: () { 57 | fetchData(); 58 | }, 59 | ), 60 | ) 61 | : Padding( 62 | padding: const EdgeInsets.all(8.0), 63 | child: ListView.builder( 64 | itemCount: characters.length, 65 | itemBuilder: (context, index) { 66 | return Card( 67 | child: ListTile( 68 | leading: Image( 69 | image: NetworkImage( 70 | characters[index]['image'], 71 | ), 72 | ), 73 | title: Text( 74 | characters[index]['name'], 75 | ), 76 | ), 77 | ); 78 | }), 79 | ), 80 | ); 81 | } 82 | 83 | void fetchData() async { 84 | setState(() { 85 | _loading = true; 86 | }); 87 | HttpLink link = 88 | HttpLink("https://rickandmortyapi.com/graphql"); 89 | GraphQLClient qlClient = GraphQLClient( 90 | 91 | link: link, 92 | cache: GraphQLCache( 93 | store: 94 | HiveStore(), 95 | ), 96 | ); 97 | QueryResult queryResult = await qlClient.query( 98 | QueryOptions( 99 | document: gql( 100 | """query { 101 | characters() { 102 | results { 103 | name 104 | image 105 | } 106 | } 107 | 108 | }""", 109 | ), 110 | ), 111 | ); 112 | 113 | // queryResult.data // contains data 114 | // queryResult.exception // will give what exception you got /errors 115 | // queryResult.hasException // you can check if you have any exception 116 | 117 | // queryResult.context.entry()?.statusCode // to get status code of response 118 | 119 | setState(() { 120 | characters = queryResult.data!['characters'][ 121 | 'results']; 122 | _loading = false; 123 | }); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /number picker/main.dart: -------------------------------------------------------------------------------- 1 | 2 | // add numberpicker plugin first 3 | 4 | import 'package:flutter/material.dart'; 5 | import 'package:numberpicker/numberpicker.dart'; 6 | 7 | void main() => runApp(const MyApp()); 8 | 9 | class MyApp extends StatelessWidget { 10 | const MyApp({Key? key}) : super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return const MaterialApp( 15 | home: Home(), 16 | ); 17 | } 18 | } 19 | 20 | class Home extends StatefulWidget { 21 | const Home({Key? key}) : super(key: key); 22 | 23 | @override 24 | State createState() => _HomeState(); 25 | } 26 | 27 | class _HomeState extends State { 28 | int _currentValue = 0; 29 | 30 | @override 31 | Widget build(BuildContext context) { 32 | return Scaffold( 33 | backgroundColor: Colors.grey.shade300, 34 | body: SizedBox( 35 | height: double.infinity, 36 | width: double.infinity, 37 | child: Column( 38 | mainAxisAlignment: MainAxisAlignment.center, 39 | crossAxisAlignment: CrossAxisAlignment.center, 40 | children: [ 41 | Stack( 42 | alignment: Alignment.center, 43 | children: [ 44 | Container( 45 | margin: const EdgeInsets.symmetric( 46 | horizontal: 15.0, 47 | vertical: 15.0, 48 | ), 49 | decoration: BoxDecoration( 50 | color: const Color(0xFFFFFFFF), 51 | borderRadius: BorderRadius.circular(20), 52 | border: Border.all( 53 | color: Colors.grey.shade200, 54 | ), 55 | ), 56 | padding: const EdgeInsets.symmetric( 57 | horizontal: 15.0, 58 | ), 59 | alignment: Alignment.center, 60 | height: 40, 61 | ), 62 | Positioned( 63 | child: Container( 64 | height: 50, 65 | width: 50, 66 | decoration: BoxDecoration( 67 | color: Colors.white, 68 | borderRadius: BorderRadius.circular(50), 69 | boxShadow: [ 70 | BoxShadow( 71 | color: Colors.grey.shade300, 72 | blurRadius: 15.0, 73 | spreadRadius: 1.0, 74 | offset: const Offset( 75 | 0.0, 76 | 0.0, 77 | ), 78 | ), 79 | ], 80 | ), 81 | )), 82 | Container( 83 | alignment: Alignment.center, 84 | child: NumberPicker( 85 | axis: Axis.horizontal, 86 | itemHeight: 45, 87 | itemWidth: 45.0, 88 | step: 1, 89 | selectedTextStyle: const TextStyle( 90 | fontSize: 20.0, 91 | color: Colors.blue, 92 | fontWeight: FontWeight.w500, 93 | ), 94 | textStyle: const TextStyle( 95 | color: Colors.black, 96 | fontSize: 12.0, 97 | ), 98 | itemCount: 7, 99 | value: _currentValue, 100 | minValue: 0, 101 | maxValue: 100, 102 | onChanged: (v) { 103 | setState(() { 104 | _currentValue = v; 105 | }); 106 | }, 107 | ), 108 | ), 109 | ], 110 | ), 111 | Container( 112 | margin: const EdgeInsets.only(top: 50), 113 | child: Text( 114 | "Selected Value:- $_currentValue", 115 | style: const TextStyle( 116 | fontSize: 20, 117 | ), 118 | ), 119 | ), 120 | ], 121 | ), 122 | ), 123 | ); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /todo/db_helper.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/todo_model.dart'; 2 | import 'package:path/path.dart'; 3 | import 'package:sqflite/sqflite.dart'; 4 | 5 | class DBHelper { 6 | static const _db = 'todo_db.db'; // our database name 7 | static const _version = 8 | 1; // version of our db , remember if you have created a db and then want to update this db then update you version too. 9 | 10 | // singleton 11 | DBHelper._privateConstructor(); 12 | static final DBHelper instance = 13 | DBHelper._privateConstructor(); // creating a instance 14 | 15 | static Database? _database; //db instance 16 | 17 | Future get database async { 18 | // here we are checking if data is initiated or not if not then creating 19 | if (_database != null) return _database!; 20 | 21 | _database = await _createDB(); 22 | return _database!; 23 | } 24 | 25 | // create db method 26 | Future _createDB() async { 27 | return openDatabase( 28 | join(await getDatabasesPath(), 29 | _db), // using getDatabasePath for path and joining it with db using join method 30 | onCreate: _onCreate, // on create as name say this will get on oncreate 31 | version: _version, // passing our version here 32 | ); 33 | } 34 | 35 | // oncreate 36 | _onCreate(db, version) { 37 | db.execute( 38 | ''' 39 | CREATE TABLE todos( 40 | id INTEGER PRIMARY KEY AUTOINCREMENT, 41 | label TEXT, desc TEXT, 42 | isComplete INTEGER, 43 | date TEXT 44 | ) 45 | ''', 46 | ); 47 | } 48 | 49 | // this sql to create table todos with id as primary key and also autoincrement 50 | 51 | // this method is to insert 52 | Future insertTodo(TODO todo) async { 53 | final db = await instance.database; // take db instance 54 | 55 | await db.insert( 56 | 'todos', //table name 57 | todo.toMap(), //user data model to map, 58 | conflictAlgorithm: 59 | ConflictAlgorithm.replace, // you can give different policy here 60 | ); 61 | } 62 | 63 | // to get all todos 64 | Future> todos() async { 65 | final db = await instance.database; 66 | 67 | final List> maps = 68 | await db.query('todos'); // to get all data just query table 69 | 70 | return List.generate(maps.length, (i) { 71 | // here i am creating a list and converting our map list output of query to TODO type of list 72 | return TODO( 73 | id: maps[i]['id'], 74 | date: maps[i]['date'], 75 | desc: maps[i]['desc'], 76 | label: maps[i]['label'], 77 | isComplete: maps[i]['isComplete'], 78 | ); 79 | }); 80 | } 81 | 82 | // i am not using single data check of filter in this example but this is how you can do 83 | Future getTodo(int id) async { 84 | final db = await instance.database; 85 | // here i am filtering data with id , you can do whatever you want 86 | final List> maps = await db.query( 87 | 'todos', 88 | where: 'id = ?', // your field name /column name in terms of table 89 | whereArgs: [id], // value for that column 90 | ); 91 | // and here i am only returning one value 92 | // i suggest you to check size before using this , you may get index out of bound error if not data found 93 | if (maps.isNotEmpty) { 94 | return TODO( 95 | id: maps[0]['id'], 96 | date: maps[0]['date'], 97 | desc: maps[0]['desc'], 98 | label: maps[0]['label'], 99 | isComplete: maps[0]['isComplete'], 100 | ); 101 | } 102 | // return null if nothing found 103 | return null; 104 | } 105 | 106 | // this method is to update 107 | Future updateTodo(TODO todo) async { 108 | final db = await instance.database; 109 | 110 | await db.update( 111 | 'todos', //table 112 | todo.toMap(),// data 113 | where: 'id = ?',//column 114 | whereArgs: [todo.id],// value for that column , if you don't use any filter here it will update whole table value 115 | ); 116 | } 117 | // and last if delete pass id of todo to delete 118 | Future deleteTodo(int id) async { 119 | final db = await instance.database; 120 | 121 | await db.delete( 122 | 'todos', 123 | where: 'id = ?', 124 | whereArgs: [id], 125 | ); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /render overflow/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | void main() => runApp(const MyApp()); 4 | 5 | class MyApp extends StatelessWidget { 6 | const MyApp({Key? key}) : super(key: key); 7 | 8 | @override 9 | Widget build(BuildContext context) { 10 | return const MaterialApp( 11 | home: Home(), 12 | ); 13 | } 14 | } 15 | 16 | class Home extends StatefulWidget { 17 | const Home({Key? key}) : super(key: key); 18 | 19 | @override 20 | State createState() => _HomeState(); 21 | } 22 | 23 | class _HomeState extends State { 24 | /* 25 | Hey Evryone let see how to solve this yellow black pattern issue 26 | i.e render flow issue 27 | we can solve it in 2 ways 28 | let's see 1st one 29 | 30 | okay now let's see 2nd method to do it 31 | that's all thanks for watching 32 | */ 33 | @override 34 | Widget build(BuildContext context) { 35 | return Scaffold( 36 | // in scaffold 37 | // resizeToAvoidBottomInset: false, // add this , that's is it solve but remember you can not scroll here 38 | backgroundColor: const Color.fromARGB(255, 10, 4, 26), 39 | body: SafeArea( 40 | child: Column( 41 | children: [ 42 | Container( 43 | margin: const EdgeInsets.only(top: 120), 44 | alignment: Alignment.center, 45 | child: const Text( 46 | "LOGIN", 47 | style: TextStyle( 48 | fontSize: 40, 49 | color: Colors.white, 50 | fontWeight: FontWeight.bold, 51 | fontStyle: FontStyle.italic, 52 | ), 53 | ), 54 | ), 55 | Container( 56 | width: double.infinity, 57 | padding: const EdgeInsets.symmetric( 58 | vertical: 30, 59 | horizontal: 20.0, 60 | ), 61 | margin: const EdgeInsets.symmetric( 62 | vertical: 30, 63 | horizontal: 20, 64 | ), 65 | decoration: BoxDecoration( 66 | color: Colors.white, 67 | borderRadius: BorderRadius.circular(10), 68 | ), 69 | child: Column( 70 | mainAxisAlignment: MainAxisAlignment.start, 71 | crossAxisAlignment: CrossAxisAlignment.start, 72 | children: [ 73 | const Text( 74 | "Username", 75 | style: TextStyle( 76 | fontSize: 14.0, 77 | color: Colors.black, 78 | ), 79 | ), 80 | Container( 81 | margin: const EdgeInsets.symmetric(vertical: 10), 82 | height: 45, 83 | child: const TextField( 84 | decoration: InputDecoration( 85 | border: OutlineInputBorder(), 86 | ), 87 | ), 88 | ), 89 | const SizedBox( 90 | height: 30, 91 | ), 92 | const Text( 93 | "Password", 94 | style: TextStyle( 95 | fontSize: 14.0, 96 | color: Colors.black, 97 | ), 98 | ), 99 | Container( 100 | margin: const EdgeInsets.symmetric(vertical: 10), 101 | height: 45, 102 | child: const TextField( 103 | decoration: InputDecoration( 104 | border: OutlineInputBorder(), 105 | ), 106 | ), 107 | ), 108 | ], 109 | ), 110 | ), 111 | Container( 112 | margin: const EdgeInsets.symmetric( 113 | horizontal: 15.0, 114 | ), 115 | height: 50, 116 | width: double.infinity, 117 | child: ElevatedButton( 118 | child: const Text("Login"), 119 | onPressed: () { 120 | FocusScope.of(context).requestFocus(FocusNode()); 121 | }, 122 | ), 123 | ) 124 | ], 125 | ), 126 | ), 127 | ); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /futurebuilder/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:http/http.dart' as http; 4 | 5 | void main() { 6 | runApp(const MyApp()); 7 | } 8 | 9 | class MyApp extends StatelessWidget { 10 | const MyApp({Key? key}) : super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return const MaterialApp( 15 | home: Home(), 16 | ); 17 | } 18 | } 19 | 20 | class Home extends StatefulWidget { 21 | const Home({Key? key}) : super(key: key); 22 | 23 | @override 24 | State createState() => _HomeState(); 25 | } 26 | 27 | class _HomeState extends State { 28 | // here we have to variable one for loading state and other for storing users 29 | // we dont's need it in futurebuilder 30 | 31 | /* 32 | 33 | Hey everyone today we are going to see how to use futurebuilder 34 | future builder uses future to build widgets 35 | that means - you call api or anyother data process which will take somw time then use that data to build ui 36 | for this we will use our api calling code 37 | 38 | i am going to change this code with future builder 39 | first let's see how it works currently 40 | we got a button on click of that a api call occur and we get a users list 41 | okay it's looking bad 42 | okay let's start implementing futurebuilder 43 | 44 | it's done 45 | thanks for watching 46 | */ 47 | 48 | @override 49 | Widget build(BuildContext context) { 50 | return Scaffold( 51 | appBar: AppBar( 52 | title: const FittedBox( 53 | child: Text( 54 | "API Call", 55 | ), 56 | ), 57 | ), 58 | body: FutureBuilder( 59 | future: loadUserList(), // user future goes here , 60 | builder: (context, snapshot) { 61 | // your data will be in snapshot 62 | // to access it you need to use snapshot.data 63 | 64 | // future builder provides state to check if data is being load or loading or error happened 65 | // connectionState gives state like waiting ,done active etc 66 | // done means data is loaded or process is done , waiting means it's loading 67 | if (snapshot.connectionState == ConnectionState.done && 68 | snapshot.hasData) { 69 | return ListView.builder( 70 | itemCount: snapshot.data?.length, 71 | itemBuilder: (context, index) { 72 | return Card( 73 | margin: const EdgeInsets.symmetric( 74 | horizontal: 15.0, 75 | vertical: 10.0, 76 | ), 77 | child: Padding( 78 | padding: const EdgeInsets.all(8.0), 79 | child: Row( 80 | children: [ 81 | SizedBox( 82 | height: 40, 83 | child: Image.network( 84 | snapshot.data?[index]['image'])), 85 | Column( 86 | mainAxisAlignment: MainAxisAlignment.start, 87 | crossAxisAlignment: CrossAxisAlignment.start, 88 | children: [ 89 | Text(snapshot.data?[index]['firstName']), 90 | Text(snapshot.data?[index]['email']), 91 | Text(snapshot.data?[index]['phone']), 92 | ], 93 | ) 94 | ], 95 | ), 96 | ), 97 | ); 98 | }); 99 | } else if (snapshot.connectionState == ConnectionState.waiting) { 100 | // waiting state means loading 101 | return const Center( 102 | child: CircularProgressIndicator(), 103 | ); 104 | } else if (snapshot.hasError) { 105 | // you can also handle error like this 106 | return Container( 107 | alignment: Alignment.center, 108 | child: const Text("Something went wrong"), 109 | ); 110 | } else { 111 | return Container(); 112 | } 113 | })); 114 | } 115 | 116 | Future loadUserList() async { 117 | // here we are going api with http plugin 118 | var res = await http.get(Uri.https( 119 | "dummyjson.com", "users")); // url -: https://dummyjson.com/users 120 | var jsonData = jsonDecode(res.body); 121 | return jsonData['users']; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /cashfree_pg/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:math'; 3 | 4 | import 'package:cashfree_pg/cashfree_pg.dart'; 5 | import 'package:flutter/material.dart'; 6 | import 'package:flutter/services.dart'; 7 | import 'package:http/http.dart' as http; 8 | 9 | void main() { 10 | runApp(const MyApp()); 11 | } 12 | 13 | class MyApp extends StatelessWidget { 14 | const MyApp({Key? key}) : super(key: key); 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | return const MaterialApp( 19 | home: Home(), 20 | ); 21 | } 22 | } 23 | 24 | class Home extends StatefulWidget { 25 | const Home({Key? key}) : super(key: key); 26 | 27 | @override 28 | State createState() => _HomeState(); 29 | } 30 | 31 | class _HomeState extends State { 32 | final TextEditingController _amountController = TextEditingController(); 33 | @override 34 | Widget build(BuildContext context) { 35 | return Scaffold( 36 | appBar: AppBar( 37 | title: const FittedBox( 38 | child: Text( 39 | "CashFree Payment gateway integration", 40 | ), 41 | ), 42 | ), 43 | body: Column( 44 | mainAxisAlignment: MainAxisAlignment.center, 45 | crossAxisAlignment: CrossAxisAlignment.center, 46 | children: [ 47 | // amount input field 48 | Container( 49 | margin: const EdgeInsets.symmetric( 50 | horizontal: 15.0, 51 | vertical: 20, 52 | ), 53 | child: TextField( 54 | controller: _amountController, 55 | decoration: const InputDecoration( 56 | border: OutlineInputBorder(), 57 | prefixIcon: Icon(Icons.currency_rupee), 58 | hintText: "Enter amount", 59 | ), 60 | inputFormatters: [FilteringTextInputFormatter.digitsOnly], 61 | ), 62 | ), 63 | // pay button 64 | ElevatedButton( 65 | child: const Text("Pay"), 66 | onPressed: () { 67 | FocusScope.of(context).requestFocus(FocusNode()); 68 | final amount = _amountController.text.trim(); 69 | if (amount.isEmpty) { 70 | ScaffoldMessenger.of(context).showSnackBar( 71 | const SnackBar( 72 | content: Text("Enter amount"), 73 | ), 74 | ); 75 | return; 76 | } 77 | 78 | num orderId = Random().nextInt(1000) ; 79 | 80 | num payableAmount = num.parse(amount); 81 | getAccessToken(payableAmount,orderId).then((tokenData) { 82 | Map _params = { 83 | 'stage': 'TEST', 84 | 'orderAmount': amount, 85 | 'orderId': '$orderId', 86 | 'orderCurrency': 'INR', 87 | 'customerName': '', 88 | 'customerPhone': '', 89 | 'customerEmail': '', 90 | 'tokenData': tokenData, 91 | 'appId': '', 92 | }; 93 | CashfreePGSDK.doPayment(_params).then((value) { 94 | print(value); 95 | if (value != null) { 96 | if (value['txStatus'] == 'SUCCESS') { 97 | ScaffoldMessenger.of(context).showSnackBar( 98 | const SnackBar( 99 | content: Text("Payment Success"), 100 | ), 101 | ); 102 | } else { 103 | ScaffoldMessenger.of(context).showSnackBar( 104 | const SnackBar( 105 | content: Text("Payment Failed"), 106 | ), 107 | ); 108 | } 109 | } 110 | }); 111 | }); 112 | }, 113 | ), 114 | ], 115 | ), 116 | ); 117 | } 118 | 119 | // 120 | Future getAccessToken(num amount,num orderId) async { 121 | var res = await http.post( 122 | Uri.https("test.cashfree.com", "api/v2/cftoken/order"), 123 | headers: { 124 | 'Content-Type': 'application/json', 125 | 'x-client-id': "", 126 | 'x-client-secret': "", 127 | }, 128 | body: jsonEncode( 129 | { 130 | "orderId": '$orderId', 131 | "orderAmount": amount, 132 | "orderCurrency": "INR", 133 | }, 134 | ), 135 | ); 136 | if (res.statusCode == 200) { 137 | var jsonResponse = jsonDecode(res.body); 138 | if (jsonResponse['status'] == 'OK') { 139 | return jsonResponse['cftoken']; 140 | } 141 | } 142 | return ''; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /pdf/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | pdf: ^3.10.7 # for pdf 4 | open_filex: ^4.4.0 # to open file 5 | path_provider: ^2.1.2 # it's to get directory /folder for storing 6 | path: ^1.8.3 # this is for path joining 7 | printing: ^5.11.1 # this give customization thing for pdf 8 | 9 | 10 | // create a folder in root assets and and image logo.png 11 | 12 | 13 | */ 14 | 15 | 16 | 17 | import 'dart:io'; 18 | 19 | import 'package:flutter/material.dart'; 20 | import 'package:flutter/services.dart'; 21 | import 'package:open_filex/open_filex.dart'; 22 | import 'package:path/path.dart' as path; 23 | import 'package:path_provider/path_provider.dart'; 24 | import 'package:pdf/pdf.dart'; 25 | import 'package:pdf/widgets.dart' 26 | as pw; // imported pdf widget as pw , so that it doesn't conflict with material widget 27 | import 'package:printing/printing.dart'; 28 | 29 | void main() { 30 | runApp(const MyApp()); 31 | } 32 | 33 | class MyApp extends StatelessWidget { 34 | const MyApp({super.key}); 35 | 36 | @override 37 | Widget build(BuildContext context) { 38 | return const MaterialApp( 39 | home: Home(), 40 | ); 41 | } 42 | } 43 | 44 | class Home extends StatefulWidget { 45 | const Home({super.key}); 46 | 47 | @override 48 | State createState() => _HomeState(); 49 | } 50 | 51 | class _HomeState extends State { 52 | /* 53 | 54 | 55 | Hey Everyone today we are going to see how to create PDF 56 | 57 | let's start with plugins 58 | 59 | i have also added a logo png 60 | 61 | 62 | 63 | UI is just a button 64 | on click of that we are calling a method createPDf 65 | 66 | 67 | 68 | Thanks for Watching 69 | 70 | */ 71 | @override 72 | Widget build(BuildContext context) { 73 | return Scaffold( 74 | appBar: AppBar(), 75 | body: Center( 76 | child: ElevatedButton( 77 | onPressed: () { 78 | createPDF(); 79 | }, 80 | child: const Text("Create PDF"), 81 | ), 82 | ), 83 | ); 84 | } 85 | 86 | createPDF() async { 87 | // creating pdf is really simple 88 | var logo = (await rootBundle.load('assets/logo.png')).buffer.asUint8List(); 89 | final doc = pw.Document(); // create doc 90 | final fontFamily = await PdfGoogleFonts.poppinsRegular(); // custom fonts 91 | doc.addPage( 92 | // add page 93 | // if you want to add multi page 94 | // 95 | // that's it for multi page 96 | // when you use multi page you also get option for header and footer 97 | pw.MultiPage( 98 | pageFormat: PdfPageFormat.a4, 99 | theme: pw.ThemeData( 100 | defaultTextStyle: pw.TextStyle( 101 | fontSize: 10, 102 | font: fontFamily, 103 | color: PdfColor.fromHex("#444444"), 104 | ), 105 | ), // theme for whole doc file 106 | footer: (context) => pw.Container( 107 | child: pw.Text("Footer"), 108 | ), 109 | header: (context) => pw.Container( 110 | child: pw.Text("Header"), 111 | ), // you can create UI as you like , i am just writing these 112 | build: (context) { 113 | // here you have to create your UI / PDF content same as you do in screen here with PDF widgets 114 | return [ 115 | // it takes list 116 | pw.Column( 117 | // pdf only contains image and text as you can see 118 | children: [ 119 | pw.Image( 120 | pw.MemoryImage(logo), // for image 121 | height: 60, 122 | ), 123 | pw.SizedBox(height: 5), 124 | pw.Text( 125 | "Flutter is an open-source UI software development toolkit created by Google, which enables developers to build natively compiled applications for mobile, web, and desktop from a single codebase. It uses the Dart programming language and offers a rich set of pre-built widgets, allowing developers to create stunning, expressive, and flexible user interfaces. With its hot reload feature, developers can see changes in real-time, making the development process more efficient and productive. Flutter's reactive framework helps to create smooth animations and transitions, providing a delightful user experience across different platforms. Its popularity continues to grow rapidly among developers due to its fast development cycle, excellent performance, and ability to target multiple platforms with a single codebase.", 126 | ), 127 | ], 128 | ) 129 | ]; 130 | }, 131 | ), 132 | ); 133 | 134 | final dir = await getTemporaryDirectory(); // get temperary dir 135 | const fileName = "sample.pdf"; 136 | final savePath = path.join(dir.path, fileName); 137 | final file = File(savePath); 138 | await file.writeAsBytes(await doc.save()); // saving content in file 139 | OpenFilex.open(file.path); // OPEN FILEX to open this PDF 140 | } 141 | } 142 | 143 | // that's it 144 | // let's see 145 | -------------------------------------------------------------------------------- /jsonserialization/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | http: ^0.13.4 3 | graphql_flutter: ^5.1.0 4 | json_serializable: ^6.3.1 5 | json_annotation: ^4.6.0 6 | 7 | dev_dependencies: 8 | build_runner: ^2.2.0 9 | 10 | 11 | */ 12 | 13 | import 'package:dummy/characters.dart'; 14 | import 'package:flutter/material.dart'; 15 | import 'package:graphql_flutter/graphql_flutter.dart'; 16 | 17 | void main() async { 18 | WidgetsFlutterBinding.ensureInitialized(); 19 | await initHiveForFlutter(); 20 | runApp(const MyApp()); 21 | } 22 | 23 | class MyApp extends StatelessWidget { 24 | const MyApp({Key? key}) : super(key: key); 25 | 26 | @override 27 | Widget build(BuildContext context) { 28 | return MaterialApp( 29 | title: 'Json Serialization', 30 | theme: ThemeData( 31 | primarySwatch: Colors.blue, 32 | ), 33 | home: const MyHomePage(title: 'Json Serialization'), 34 | ); 35 | } 36 | } 37 | 38 | class MyHomePage extends StatefulWidget { 39 | const MyHomePage({Key? key, required this.title}) : super(key: key); 40 | final String title; 41 | @override 42 | State createState() => _MyHomePageState(); 43 | } 44 | 45 | /* 46 | 47 | if you see our response is something like this 48 | here as we see we need 3 data clasess to convert this 49 | if you ever get confuse in how many data class or class you need just see no of bracket opening /closeing 50 | { -> 1 51 | characters:{->2 52 | results:[ 53 | {->3 always create inner most first 54 | name:"Aniket", 55 | image:"http:image.png" 56 | } 57 | ] 58 | } 59 | } 60 | 61 | so we are create class class manually or we have plugin to do that 62 | let's see by plugin in this video 63 | 64 | 65 | */ 66 | 67 | class _MyHomePageState extends State { 68 | List characters = []; 69 | bool _loading = false; 70 | /* 71 | Hey everyone today we are going to see json serialization/data parsing or json to object 72 | whetever you like to say all are same 73 | 74 | 75 | i am going to use my one of old video/code where i have shown you how to use graphql api call 76 | 77 | so let's start assuming you have seen that video if not please go and watch 78 | 79 | first let's see our response 80 | 81 | so we got our data class now let's use them 82 | okay everything done now let see if it working as before 83 | yes it's working 84 | thanks for watching 85 | 86 | */ 87 | @override 88 | Widget build(BuildContext context) { 89 | return Scaffold( 90 | appBar: AppBar( 91 | title: Text(widget.title), 92 | ), 93 | body: _loading 94 | ? const CircularProgressIndicator() 95 | : characters.isEmpty 96 | ? Center( 97 | child: ElevatedButton( 98 | child: const Text("Fetch Data"), 99 | onPressed: () { 100 | fetchData(); 101 | }, 102 | ), 103 | ) 104 | : Padding( 105 | padding: const EdgeInsets.all(8.0), 106 | child: ListView.builder( 107 | itemCount: characters.length, 108 | itemBuilder: (context, index) { 109 | return Card( 110 | child: ListTile( 111 | leading: characters[index].image != null // i am checking for null if this get null value it will break 112 | ? Image( 113 | image: NetworkImage( 114 | characters[index].image ?? '', 115 | ), 116 | ) 117 | : null, 118 | title: Text( 119 | characters[index].name ?? '', 120 | ), 121 | ), 122 | ); 123 | }), 124 | ), 125 | ); 126 | } 127 | 128 | void fetchData() async { 129 | setState(() { 130 | _loading = true; 131 | }); 132 | HttpLink link = HttpLink("https://rickandmortyapi.com/graphql"); 133 | GraphQLClient qlClient = GraphQLClient( 134 | link: link, 135 | cache: GraphQLCache( 136 | store: HiveStore(), 137 | ), 138 | ); 139 | QueryResult queryResult = await qlClient.query( 140 | QueryOptions( 141 | document: gql( 142 | """query { 143 | characters() { 144 | results { 145 | name 146 | image 147 | } 148 | } 149 | 150 | }""", 151 | ), 152 | ), 153 | ); 154 | 155 | print(queryResult.data); 156 | 157 | // here queryResult.data give json to no need to convert it into json or using jsonDecode 158 | // i am just checking if any error or not and data is not null 159 | if (!queryResult.hasException && queryResult.data != null) { 160 | CharactersResponse response = 161 | CharactersResponse.fromJson(queryResult.data!); 162 | setState(() { 163 | characters = response.characters?.results ?? []; 164 | 165 | /// now we can access field like object 166 | _loading = false; 167 | }); 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /gridview-2024/product_details.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class ProductDetails extends StatefulWidget { 5 | final Product product; 6 | const ProductDetails({super.key, required this.product}); 7 | 8 | @override 9 | State createState() => _ProductDetailsState(); 10 | } 11 | 12 | class _ProductDetailsState extends State { 13 | @override 14 | Widget build(BuildContext context) { 15 | return Scaffold( 16 | appBar: AppBar( 17 | backgroundColor: Colors.amberAccent, 18 | title: Hero( 19 | tag: widget.product.title ?? '', 20 | child: Material( 21 | color: Colors.transparent, 22 | child: Text( 23 | widget.product.title ?? '', 24 | style: const TextStyle( 25 | fontSize: 15, 26 | ), 27 | ), 28 | ), 29 | ), 30 | ), 31 | body: Container( 32 | margin: const EdgeInsets.all(20), 33 | child: Column( 34 | mainAxisAlignment: MainAxisAlignment.start, 35 | crossAxisAlignment: CrossAxisAlignment.start, 36 | children: [ 37 | Hero( 38 | tag: widget.product.thumbnail ?? '', 39 | child: Container( 40 | height: 170, 41 | decoration: BoxDecoration( 42 | color: const Color(0xFFD5DCDE), 43 | borderRadius: BorderRadius.circular(10), 44 | ), 45 | alignment: Alignment.center, 46 | child: Image.network( 47 | widget.product.thumbnail ?? '', 48 | ), 49 | ), 50 | ), 51 | const SizedBox( 52 | height: 10, 53 | ), 54 | Text( 55 | widget.product.title ?? '', 56 | style: const TextStyle( 57 | fontWeight: FontWeight.w500, 58 | fontSize: 18, 59 | ), 60 | ), 61 | Row( 62 | children: [ 63 | Text( 64 | "\$ ${widget.product.price}", 65 | style: const TextStyle( 66 | fontWeight: FontWeight.w500, 67 | fontSize: 20, 68 | ), 69 | ), 70 | const SizedBox( 71 | width: 10, 72 | ), 73 | const Icon( 74 | Icons.star, 75 | color: Colors.amberAccent, 76 | ), 77 | Text( 78 | "${widget.product.rating}", 79 | style: const TextStyle( 80 | fontWeight: FontWeight.w500, 81 | fontSize: 15, 82 | ), 83 | ), 84 | const Spacer(), 85 | Hero( 86 | tag: ValueKey(widget.product), 87 | child: ElevatedButton( 88 | style: const ButtonStyle( 89 | backgroundColor: 90 | WidgetStatePropertyAll(Colors.amberAccent), 91 | ), 92 | onPressed: () {}, 93 | child: const Text("Add To Cart"), 94 | ), 95 | ) 96 | ], 97 | ), 98 | const Divider(), 99 | const SizedBox( 100 | height: 10, 101 | ), 102 | Text( 103 | widget.product.description ?? '', 104 | style: const TextStyle( 105 | fontSize: 14, 106 | ), 107 | ), 108 | const Divider(), 109 | ...?widget.product.reviews?.map( 110 | (e) => Container( 111 | margin: const EdgeInsets.symmetric( 112 | vertical: 8, 113 | ), 114 | child: Column( 115 | mainAxisAlignment: MainAxisAlignment.start, 116 | crossAxisAlignment: CrossAxisAlignment.start, 117 | children: [ 118 | Text( 119 | e.reviewerName ?? '', 120 | style: const TextStyle( 121 | fontWeight: FontWeight.w500, 122 | ), 123 | ), 124 | Row( 125 | children: [ 126 | const Icon( 127 | Icons.star, 128 | color: Colors.amberAccent, 129 | ), 130 | const SizedBox( 131 | width: 6, 132 | ), 133 | Text( 134 | "${e.rating}", 135 | style: const TextStyle( 136 | fontSize: 15, 137 | ), 138 | ), 139 | ], 140 | ), 141 | Text( 142 | e.comment ?? "", 143 | ) 144 | ], 145 | ), 146 | ), 147 | ) 148 | ], 149 | ), 150 | ), 151 | ); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /hero-2024/product_details.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:testhero/model/product.dart'; 3 | 4 | class ProductDetails extends StatefulWidget { 5 | final Product product; 6 | const ProductDetails({super.key, required this.product}); 7 | 8 | @override 9 | State createState() => _ProductDetailsState(); 10 | } 11 | 12 | class _ProductDetailsState extends State { 13 | @override 14 | Widget build(BuildContext context) { 15 | return Scaffold( 16 | appBar: AppBar( 17 | backgroundColor: Colors.amberAccent, 18 | title: Hero( 19 | tag: widget.product.title ?? '', 20 | child: Material( 21 | color: Colors.transparent, 22 | child: Text( 23 | widget.product.title ?? '', 24 | style: const TextStyle( 25 | fontSize: 15, 26 | ), 27 | ), 28 | ), 29 | ), 30 | ), 31 | body: Container( 32 | margin: const EdgeInsets.all(20), 33 | child: Column( 34 | mainAxisAlignment: MainAxisAlignment.start, 35 | crossAxisAlignment: CrossAxisAlignment.start, 36 | children: [ 37 | Hero( 38 | tag: widget.product.thumbnail ?? '', 39 | child: Container( 40 | height: 170, 41 | decoration: BoxDecoration( 42 | color: const Color(0xFFD5DCDE), 43 | borderRadius: BorderRadius.circular(10), 44 | ), 45 | alignment: Alignment.center, 46 | child: Image.network( 47 | widget.product.thumbnail ?? '', 48 | ), 49 | ), 50 | ), 51 | const SizedBox( 52 | height: 10, 53 | ), 54 | Text( 55 | widget.product.title ?? '', 56 | style: const TextStyle( 57 | fontWeight: FontWeight.w500, 58 | fontSize: 18, 59 | ), 60 | ), 61 | Row( 62 | children: [ 63 | Text( 64 | "\$ ${widget.product.price}", 65 | style: const TextStyle( 66 | fontWeight: FontWeight.w500, 67 | fontSize: 20, 68 | ), 69 | ), 70 | const SizedBox( 71 | width: 10, 72 | ), 73 | const Icon( 74 | Icons.star, 75 | color: Colors.amberAccent, 76 | ), 77 | Text( 78 | "${widget.product.rating}", 79 | style: const TextStyle( 80 | fontWeight: FontWeight.w500, 81 | fontSize: 15, 82 | ), 83 | ), 84 | const Spacer(), 85 | Hero( 86 | tag: ValueKey(widget.product), 87 | child: ElevatedButton( 88 | style: const ButtonStyle( 89 | backgroundColor: 90 | WidgetStatePropertyAll(Colors.amberAccent), 91 | ), 92 | onPressed: () {}, 93 | child: const Text("Add To Cart"), 94 | ), 95 | ) 96 | ], 97 | ), 98 | const Divider(), 99 | const SizedBox( 100 | height: 10, 101 | ), 102 | Text( 103 | widget.product.description ?? '', 104 | style: const TextStyle( 105 | fontSize: 14, 106 | ), 107 | ), 108 | const Divider(), 109 | ...?widget.product.reviews?.map( 110 | (e) => Container( 111 | margin: const EdgeInsets.symmetric( 112 | vertical: 8, 113 | ), 114 | child: Column( 115 | mainAxisAlignment: MainAxisAlignment.start, 116 | crossAxisAlignment: CrossAxisAlignment.start, 117 | children: [ 118 | Text( 119 | e.reviewerName ?? '', 120 | style: const TextStyle( 121 | fontWeight: FontWeight.w500, 122 | ), 123 | ), 124 | Row( 125 | children: [ 126 | const Icon( 127 | Icons.star, 128 | color: Colors.amberAccent, 129 | ), 130 | const SizedBox( 131 | width: 6, 132 | ), 133 | Text( 134 | "${e.rating}", 135 | style: const TextStyle( 136 | fontSize: 15, 137 | ), 138 | ), 139 | ], 140 | ), 141 | Text( 142 | e.comment ?? "", 143 | ) 144 | ], 145 | ), 146 | ), 147 | ) 148 | ], 149 | ), 150 | ), 151 | ); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /hero-2024/home.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:http/http.dart' as http; 5 | import 'package:testhero/model/product.dart'; 6 | import 'package:testhero/model/product_response.dart'; 7 | import 'package:testhero/product_details.dart'; 8 | 9 | class Home extends StatefulWidget { 10 | const Home({super.key}); 11 | 12 | @override 13 | State createState() => _HomeState(); 14 | } 15 | 16 | class _HomeState extends State { 17 | @override 18 | void initState() { 19 | super.initState(); 20 | getProducts(); 21 | } 22 | 23 | List products = List.empty(); 24 | @override 25 | Widget build(BuildContext context) { 26 | return Scaffold( 27 | appBar: AppBar( 28 | backgroundColor: Colors.amberAccent, 29 | title: const Text("Products"), 30 | elevation: 6, 31 | ), 32 | body: ListView.builder( 33 | itemCount: products.length, 34 | itemBuilder: (context, index) { 35 | return Container( 36 | margin: const EdgeInsets.symmetric( 37 | horizontal: 15, 38 | vertical: 8, 39 | ), 40 | decoration: BoxDecoration( 41 | borderRadius: BorderRadius.circular(10), 42 | border: Border.all(color: Colors.grey), 43 | ), 44 | padding: const EdgeInsets.all(15), 45 | alignment: Alignment.center, 46 | child: Column( 47 | mainAxisAlignment: MainAxisAlignment.start, 48 | crossAxisAlignment: CrossAxisAlignment.start, 49 | children: [ 50 | InkWell( 51 | onTap: () { 52 | Navigator.of(context).push( 53 | MaterialPageRoute( 54 | builder: (context) => ProductDetails( 55 | product: products[index], 56 | ), 57 | ), 58 | ); 59 | }, 60 | child: Hero( 61 | tag: products[index].thumbnail ?? '', 62 | child: Container( 63 | height: 170, 64 | decoration: BoxDecoration( 65 | color: const Color(0xFFD5DCDE), 66 | borderRadius: BorderRadius.circular(10), 67 | ), 68 | alignment: Alignment.center, 69 | child: Image.network( 70 | products[index].thumbnail ?? '', 71 | ), 72 | ), 73 | ), 74 | ), 75 | const SizedBox( 76 | height: 10, 77 | ), 78 | Material( 79 | color: Colors.transparent, 80 | child: Hero( 81 | tag: products[index].title ?? '', 82 | child: Material( 83 | color: Colors.transparent, 84 | child: Text( 85 | products[index].title ?? '', 86 | style: const TextStyle( 87 | fontWeight: FontWeight.w500, 88 | fontSize: 16, 89 | ), 90 | ), 91 | ), 92 | ), 93 | ), 94 | Row( 95 | children: [ 96 | Text( 97 | "\$ ${products[index].price}", 98 | style: const TextStyle( 99 | fontWeight: FontWeight.w500, 100 | fontSize: 20, 101 | ), 102 | ), 103 | const SizedBox( 104 | width: 10, 105 | ), 106 | const Icon( 107 | Icons.star, 108 | color: Colors.amberAccent, 109 | ), 110 | Text( 111 | "${products[index].rating}", 112 | style: const TextStyle( 113 | fontWeight: FontWeight.w500, 114 | fontSize: 15, 115 | ), 116 | ), 117 | const Spacer(), 118 | Hero( 119 | tag: ValueKey(products[index]), 120 | child: ElevatedButton( 121 | style: const ButtonStyle( 122 | backgroundColor: 123 | WidgetStatePropertyAll(Colors.amberAccent), 124 | ), 125 | onPressed: () {}, 126 | child: const Text("Add To Cart"), 127 | ), 128 | ) 129 | ], 130 | ) 131 | ], 132 | ), 133 | ); 134 | }, 135 | ), 136 | ); 137 | } 138 | 139 | getProducts() async { 140 | var res = await http.get(Uri.https("dummyjson.com", "products")); 141 | ProductResponse response = ProductResponse.fromJson(jsonDecode(res.body)); 142 | setState(() { 143 | products = response.products ?? []; 144 | }); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /search-delegates/home.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dummy/model/product.dart'; 4 | import 'package:dummy/model/product_response.dart'; 5 | import 'package:dummy/product_details.dart'; 6 | import 'package:dummy/product_search_delegates.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:http/http.dart' as http; 9 | 10 | class Home extends StatefulWidget { 11 | const Home({super.key}); 12 | 13 | @override 14 | State createState() => _HomeState(); 15 | } 16 | 17 | class _HomeState extends State { 18 | @override 19 | void initState() { 20 | super.initState(); 21 | getProducts(); 22 | } 23 | 24 | List products = List.empty(); 25 | @override 26 | Widget build(BuildContext context) { 27 | return Scaffold( 28 | appBar: AppBar( 29 | backgroundColor: Colors.amberAccent, 30 | title: const Text("Products"), 31 | elevation: 6, 32 | actions: [ 33 | IconButton( 34 | onPressed: () { 35 | showSearch( 36 | context: context, 37 | delegate: ProductSearchDelegates(products: products)); 38 | }, 39 | icon: const Icon(Icons.search), 40 | ) 41 | ], 42 | ), 43 | body: GridView.builder( 44 | itemCount: products.length, 45 | gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( 46 | crossAxisCount: 2, 47 | childAspectRatio: 0.9, 48 | ), 49 | itemBuilder: (context, index) { 50 | return Container( 51 | margin: const EdgeInsets.symmetric( 52 | horizontal: 15, 53 | vertical: 8, 54 | ), 55 | decoration: BoxDecoration( 56 | borderRadius: BorderRadius.circular(10), 57 | border: Border.all(color: Colors.grey), 58 | ), 59 | padding: const EdgeInsets.all(15), 60 | alignment: Alignment.center, 61 | child: Column( 62 | mainAxisAlignment: MainAxisAlignment.start, 63 | crossAxisAlignment: CrossAxisAlignment.start, 64 | children: [ 65 | InkWell( 66 | onTap: () { 67 | Navigator.of(context).push( 68 | MaterialPageRoute( 69 | builder: (context) => ProductDetails( 70 | product: products[index], 71 | ), 72 | ), 73 | ); 74 | }, 75 | child: Hero( 76 | tag: products[index].thumbnail ?? '', 77 | child: Container( 78 | height: 90, 79 | decoration: BoxDecoration( 80 | color: const Color(0xFFD5DCDE), 81 | borderRadius: BorderRadius.circular(10), 82 | ), 83 | alignment: Alignment.center, 84 | child: Image.network( 85 | products[index].thumbnail ?? '', 86 | ), 87 | ), 88 | ), 89 | ), 90 | const SizedBox( 91 | height: 10, 92 | ), 93 | Material( 94 | color: Colors.transparent, 95 | child: Hero( 96 | tag: products[index].title ?? '', 97 | child: Material( 98 | color: Colors.transparent, 99 | child: Text( 100 | products[index].title ?? '', 101 | style: const TextStyle( 102 | fontWeight: FontWeight.w500, 103 | fontSize: 14, 104 | overflow: TextOverflow.ellipsis, 105 | ), 106 | ), 107 | ), 108 | ), 109 | ), 110 | Row( 111 | children: [ 112 | Text( 113 | "\$ ${products[index].price}", 114 | style: const TextStyle( 115 | fontWeight: FontWeight.w500, 116 | fontSize: 12, 117 | ), 118 | ), 119 | const SizedBox( 120 | width: 10, 121 | ), 122 | const Icon( 123 | Icons.star, 124 | color: Colors.amberAccent, 125 | ), 126 | Text( 127 | "${products[index].rating}", 128 | style: const TextStyle( 129 | fontWeight: FontWeight.w500, 130 | fontSize: 12, 131 | ), 132 | ), 133 | ], 134 | ) 135 | ], 136 | ), 137 | ); 138 | }, 139 | ), 140 | ); 141 | } 142 | 143 | getProducts() async { 144 | var res = await http.get(Uri.https("dummyjson.com", "products")); 145 | ProductResponse response = ProductResponse.fromJson(jsonDecode(res.body)); 146 | setState(() { 147 | products = response.products ?? []; 148 | }); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /gridview-2024/home.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dummy/model/product.dart'; 4 | import 'package:dummy/model/product_response.dart'; 5 | import 'package:dummy/product_details.dart'; 6 | import 'package:flutter/material.dart'; 7 | import 'package:http/http.dart' as http; 8 | 9 | class Home extends StatefulWidget { 10 | const Home({super.key}); 11 | 12 | @override 13 | State createState() => _HomeState(); 14 | } 15 | 16 | class _HomeState extends State { 17 | @override 18 | void initState() { 19 | super.initState(); 20 | getProducts(); 21 | } 22 | 23 | List products = List.empty(); 24 | @override 25 | Widget build(BuildContext context) { 26 | return Scaffold( 27 | appBar: AppBar( 28 | backgroundColor: Colors.amberAccent, 29 | title: const Text("Products"), 30 | elevation: 6, 31 | ), 32 | body: GridView.builder( 33 | itemCount: products.length, 34 | gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( 35 | crossAxisCount: 2, 36 | childAspectRatio: 0.9, 37 | ), 38 | itemBuilder: (context, index) { 39 | return Container( 40 | margin: const EdgeInsets.symmetric( 41 | horizontal: 15, 42 | vertical: 8, 43 | ), 44 | decoration: BoxDecoration( 45 | borderRadius: BorderRadius.circular(10), 46 | border: Border.all(color: Colors.grey), 47 | ), 48 | padding: const EdgeInsets.all(15), 49 | alignment: Alignment.center, 50 | child: Column( 51 | mainAxisAlignment: MainAxisAlignment.start, 52 | crossAxisAlignment: CrossAxisAlignment.start, 53 | children: [ 54 | InkWell( 55 | onTap: () { 56 | Navigator.of(context).push( 57 | MaterialPageRoute( 58 | builder: (context) => ProductDetails( 59 | product: products[index], 60 | ), 61 | ), 62 | ); 63 | }, 64 | child: Hero( 65 | tag: products[index].thumbnail ?? '', 66 | child: Container( 67 | height: 90, 68 | decoration: BoxDecoration( 69 | color: const Color(0xFFD5DCDE), 70 | borderRadius: BorderRadius.circular(10), 71 | ), 72 | alignment: Alignment.center, 73 | child: Image.network( 74 | products[index].thumbnail ?? '', 75 | ), 76 | ), 77 | ), 78 | ), 79 | const SizedBox( 80 | height: 10, 81 | ), 82 | Material( 83 | color: Colors.transparent, 84 | child: Hero( 85 | tag: products[index].title ?? '', 86 | child: Material( 87 | color: Colors.transparent, 88 | child: Text( 89 | products[index].title ?? '', 90 | style: const TextStyle( 91 | fontWeight: FontWeight.w500, 92 | fontSize: 14, 93 | overflow: TextOverflow.ellipsis, 94 | ), 95 | ), 96 | ), 97 | ), 98 | ), 99 | Row( 100 | children: [ 101 | Text( 102 | "\$ ${products[index].price}", 103 | style: const TextStyle( 104 | fontWeight: FontWeight.w500, 105 | fontSize: 12, 106 | ), 107 | ), 108 | const SizedBox( 109 | width: 10, 110 | ), 111 | const Icon( 112 | Icons.star, 113 | color: Colors.amberAccent, 114 | ), 115 | Text( 116 | "${products[index].rating}", 117 | style: const TextStyle( 118 | fontWeight: FontWeight.w500, 119 | fontSize: 12, 120 | ), 121 | ), 122 | // const Spacer(), 123 | // Hero( 124 | // tag: ValueKey(products[index]), 125 | // child: ElevatedButton( 126 | // style: const ButtonStyle( 127 | // backgroundColor: 128 | // WidgetStatePropertyAll(Colors.amberAccent), 129 | // ), 130 | // onPressed: () {}, 131 | // child: const Text("Add To Cart"), 132 | // ), 133 | // ) 134 | ], 135 | ) 136 | ], 137 | ), 138 | ); 139 | }, 140 | ), 141 | ); 142 | } 143 | 144 | getProducts() async { 145 | var res = await http.get(Uri.https("dummyjson.com", "products")); 146 | ProductResponse response = ProductResponse.fromJson(jsonDecode(res.body)); 147 | setState(() { 148 | products = response.products ?? []; 149 | }); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /searchbar/product_details.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class ProductDetails extends StatefulWidget { 5 | final Product product; 6 | const ProductDetails({super.key, required this.product}); 7 | 8 | @override 9 | State createState() => _ProductDetailsState(); 10 | } 11 | 12 | class _ProductDetailsState extends State { 13 | @override 14 | Widget build(BuildContext context) { 15 | return Scaffold( 16 | appBar: AppBar( 17 | backgroundColor: Colors.amberAccent, 18 | title: Hero( 19 | tag: widget.product.title ?? '', 20 | child: Material( 21 | color: Colors.transparent, 22 | child: Text( 23 | widget.product.title ?? '', 24 | style: const TextStyle( 25 | fontSize: 15, 26 | ), 27 | ), 28 | ), 29 | ), 30 | ), 31 | body: Container( 32 | margin: const EdgeInsets.all(20), 33 | child: SingleChildScrollView( 34 | child: Column( 35 | mainAxisAlignment: MainAxisAlignment.start, 36 | crossAxisAlignment: CrossAxisAlignment.start, 37 | children: [ 38 | Hero( 39 | tag: widget.product.thumbnail ?? '', 40 | child: Container( 41 | height: 170, 42 | decoration: BoxDecoration( 43 | color: const Color(0xFFD5DCDE), 44 | borderRadius: BorderRadius.circular(10), 45 | ), 46 | alignment: Alignment.center, 47 | child: Image.network( 48 | widget.product.thumbnail ?? '', 49 | ), 50 | ), 51 | ), 52 | const SizedBox( 53 | height: 10, 54 | ), 55 | Text( 56 | widget.product.title ?? '', 57 | style: const TextStyle( 58 | fontWeight: FontWeight.w500, 59 | fontSize: 18, 60 | ), 61 | ), 62 | Row( 63 | children: [ 64 | Text( 65 | "\$ ${widget.product.price}", 66 | style: const TextStyle( 67 | fontWeight: FontWeight.w500, 68 | fontSize: 20, 69 | ), 70 | ), 71 | const SizedBox( 72 | width: 10, 73 | ), 74 | const Icon( 75 | Icons.star, 76 | color: Colors.amberAccent, 77 | ), 78 | Text( 79 | "${widget.product.rating}", 80 | style: const TextStyle( 81 | fontWeight: FontWeight.w500, 82 | fontSize: 15, 83 | ), 84 | ), 85 | const Spacer(), 86 | Hero( 87 | tag: ValueKey(widget.product), 88 | child: ElevatedButton( 89 | style: const ButtonStyle( 90 | backgroundColor: 91 | WidgetStatePropertyAll(Colors.amberAccent), 92 | ), 93 | onPressed: () {}, 94 | child: const Text("Add To Cart"), 95 | ), 96 | ) 97 | ], 98 | ), 99 | const Divider(), 100 | const SizedBox( 101 | height: 10, 102 | ), 103 | Text( 104 | widget.product.description ?? '', 105 | style: const TextStyle( 106 | fontSize: 14, 107 | ), 108 | ), 109 | const Divider(), 110 | ...?widget.product.reviews?.map( 111 | (e) => Container( 112 | margin: const EdgeInsets.symmetric( 113 | vertical: 8, 114 | ), 115 | child: Column( 116 | mainAxisAlignment: MainAxisAlignment.start, 117 | crossAxisAlignment: CrossAxisAlignment.start, 118 | children: [ 119 | Text( 120 | e.reviewerName ?? '', 121 | style: const TextStyle( 122 | fontWeight: FontWeight.w500, 123 | ), 124 | ), 125 | Row( 126 | children: [ 127 | const Icon( 128 | Icons.star, 129 | color: Colors.amberAccent, 130 | ), 131 | const SizedBox( 132 | width: 6, 133 | ), 134 | Text( 135 | "${e.rating}", 136 | style: const TextStyle( 137 | fontSize: 15, 138 | ), 139 | ), 140 | ], 141 | ), 142 | Text( 143 | e.comment ?? "", 144 | ) 145 | ], 146 | ), 147 | ), 148 | ) 149 | ], 150 | ), 151 | ), 152 | ), 153 | ); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /search-delegates/product_details.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/model/product.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class ProductDetails extends StatefulWidget { 5 | final Product product; 6 | const ProductDetails({super.key, required this.product}); 7 | 8 | @override 9 | State createState() => _ProductDetailsState(); 10 | } 11 | 12 | class _ProductDetailsState extends State { 13 | @override 14 | Widget build(BuildContext context) { 15 | return Scaffold( 16 | appBar: AppBar( 17 | backgroundColor: Colors.amberAccent, 18 | title: Hero( 19 | tag: widget.product.title ?? '', 20 | child: Material( 21 | color: Colors.transparent, 22 | child: Text( 23 | widget.product.title ?? '', 24 | style: const TextStyle( 25 | fontSize: 15, 26 | ), 27 | ), 28 | ), 29 | ), 30 | ), 31 | body: Container( 32 | margin: const EdgeInsets.all(20), 33 | child: SingleChildScrollView( 34 | child: Column( 35 | mainAxisAlignment: MainAxisAlignment.start, 36 | crossAxisAlignment: CrossAxisAlignment.start, 37 | children: [ 38 | Hero( 39 | tag: widget.product.thumbnail ?? '', 40 | child: Container( 41 | height: 170, 42 | decoration: BoxDecoration( 43 | color: const Color(0xFFD5DCDE), 44 | borderRadius: BorderRadius.circular(10), 45 | ), 46 | alignment: Alignment.center, 47 | child: Image.network( 48 | widget.product.thumbnail ?? '', 49 | ), 50 | ), 51 | ), 52 | const SizedBox( 53 | height: 10, 54 | ), 55 | Text( 56 | widget.product.title ?? '', 57 | style: const TextStyle( 58 | fontWeight: FontWeight.w500, 59 | fontSize: 18, 60 | ), 61 | ), 62 | Row( 63 | children: [ 64 | Text( 65 | "\$ ${widget.product.price}", 66 | style: const TextStyle( 67 | fontWeight: FontWeight.w500, 68 | fontSize: 20, 69 | ), 70 | ), 71 | const SizedBox( 72 | width: 10, 73 | ), 74 | const Icon( 75 | Icons.star, 76 | color: Colors.amberAccent, 77 | ), 78 | Text( 79 | "${widget.product.rating}", 80 | style: const TextStyle( 81 | fontWeight: FontWeight.w500, 82 | fontSize: 15, 83 | ), 84 | ), 85 | const Spacer(), 86 | Hero( 87 | tag: ValueKey(widget.product), 88 | child: ElevatedButton( 89 | style: const ButtonStyle( 90 | backgroundColor: 91 | WidgetStatePropertyAll(Colors.amberAccent), 92 | ), 93 | onPressed: () {}, 94 | child: const Text("Add To Cart"), 95 | ), 96 | ) 97 | ], 98 | ), 99 | const Divider(), 100 | const SizedBox( 101 | height: 10, 102 | ), 103 | Text( 104 | widget.product.description ?? '', 105 | style: const TextStyle( 106 | fontSize: 14, 107 | ), 108 | ), 109 | const Divider(), 110 | ...?widget.product.reviews?.map( 111 | (e) => Container( 112 | margin: const EdgeInsets.symmetric( 113 | vertical: 8, 114 | ), 115 | child: Column( 116 | mainAxisAlignment: MainAxisAlignment.start, 117 | crossAxisAlignment: CrossAxisAlignment.start, 118 | children: [ 119 | Text( 120 | e.reviewerName ?? '', 121 | style: const TextStyle( 122 | fontWeight: FontWeight.w500, 123 | ), 124 | ), 125 | Row( 126 | children: [ 127 | const Icon( 128 | Icons.star, 129 | color: Colors.amberAccent, 130 | ), 131 | const SizedBox( 132 | width: 6, 133 | ), 134 | Text( 135 | "${e.rating}", 136 | style: const TextStyle( 137 | fontSize: 15, 138 | ), 139 | ), 140 | ], 141 | ), 142 | Text( 143 | e.comment ?? "", 144 | ) 145 | ], 146 | ), 147 | ), 148 | ) 149 | ], 150 | ), 151 | ), 152 | ), 153 | ); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /multiplatform/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:another_transformer_page_view/another_transformer_page_view.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutternews/check_device.dart'; 6 | import 'package:flutternews/device_enum.dart'; 7 | import 'package:flutternews/news_layout.dart'; 8 | import 'package:flutternews/news_model.dart'; 9 | import 'package:flutternews/page_transformers.dart'; 10 | import 'package:http/http.dart' as http; 11 | 12 | void main() { 13 | runApp(const MyApp()); 14 | } 15 | 16 | class MyApp extends StatelessWidget { 17 | const MyApp({super.key}); 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return const MaterialApp( 22 | debugShowCheckedModeBanner: false, 23 | home: FlutterNews(), 24 | ); 25 | } 26 | } 27 | 28 | class FlutterNews extends StatefulWidget { 29 | const FlutterNews({super.key}); 30 | 31 | @override 32 | State createState() => _FlutterNewsState(); 33 | } 34 | 35 | class _FlutterNewsState extends State { 36 | List newsArticles = []; 37 | bool _loading = false; 38 | @override 39 | void initState() { 40 | getNews(); 41 | super.initState(); 42 | } 43 | 44 | /* 45 | 46 | Hey everyone, 47 | you have heard that in flutter with single code base you can run your app on web/ desktop, and mobile 48 | so today i am going to show you this 49 | yes 50 | before we start i am using my last video which was on news so if you have to watch that yet , please do 51 | i am going to convert that to web and desktop 52 | 53 | basically you don't need anything else to make your mobile app into website or desktop 54 | app 55 | you just have to handle some responsiveness and feature which do not support on other 56 | so to make you app work on all three device/platform 57 | first you need to check on whic device you app is running 58 | 59 | now that you know on which device you are running let's see the changes 60 | required to run on all device 61 | 62 | 63 | Thanks for watching 64 | please subcribe ,like 65 | 66 | */ 67 | 68 | @override 69 | Widget build(BuildContext context) { 70 | return Scaffold( 71 | appBar: getDevice() != Devices.mobile // i am not showing app bar in mobile ,so here i am checking if not mobile show app 72 | ? AppBar( 73 | title: const Text( 74 | "Flutter News", 75 | )) 76 | : null, 77 | body: SafeArea( 78 | child: _loading 79 | ? const Center( 80 | child: CircularProgressIndicator(), 81 | ) 82 | : Align( 83 | alignment: Alignment.topCenter, 84 | child: Container( 85 | constraints: const BoxConstraints( 86 | maxWidth: 600, // next i have constraint my with to 600 so that it don't take full width on web and desktop 87 | ), 88 | child: getDevice() == Devices.mobile // here animation used in mobile is not possible/ will not look good on web and desktop 89 | ? TransformerPageView( // show i have separated 90 | // and showing it with 2 different widget for mobile and web/desktop 91 | scrollDirection: Axis.vertical, 92 | transformer: getDevice() == Devices.mobile 93 | ? DepthPageTransformer() 94 | : null, 95 | 96 | itemBuilder: (context, index) => 97 | NewsLayout(news: newsArticles[index]), // UI /news layout 98 | itemCount: newsArticles.length, 99 | ) // for mobile 100 | : ListView.builder( 101 | itemBuilder: (context, index) => Container( 102 | margin: const EdgeInsets.only( 103 | bottom: 20, 104 | ), 105 | child: NewsLayout(news: newsArticles[index]), 106 | ), 107 | itemCount: newsArticles.length, 108 | padding: const EdgeInsets.symmetric( 109 | vertical: 20, 110 | ), 111 | ), // listview for web /desktop 112 | // that it 113 | // by handling situation like this you can develop mobile / web / desktop app with single code base 114 | // lets again see it 115 | ), 116 | ), 117 | ), 118 | ); 119 | } 120 | 121 | getNews() async { 122 | setState(() { 123 | _loading = true; 124 | }); 125 | try { 126 | // where i am call newsorg api with http plugin's help 127 | // https://newsapi.org/v2/top-headlines?country=us&apiKey=562838d733f0476d8e981f6038bf6cdc 128 | var res = await http.get( 129 | Uri.https("newsapi.org", 'v2/top-headlines', 130 | {'country': 'in', 'apiKey': '562838d733f0476d8e981f6038bf6cdc'}), 131 | ); 132 | if (res.statusCode == 200) { 133 | NewsResponse response = NewsResponse.fromJson(jsonDecode(res.body)); 134 | if (response.articles != null && response.articles!.isNotEmpty) { 135 | 136 | setState(() { 137 | newsArticles = response.articles ?? []; // newsarticles 138 | 139 | }); 140 | } 141 | } 142 | } catch (_) { 143 | } finally { 144 | setState(() { 145 | _loading = false; 146 | }); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /add-to-cart-animation-demo/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | add_to_cart_animation: ^2.0.3 4 | 5 | 6 | */ 7 | 8 | import 'package:add_to_cart_animation/add_to_cart_animation.dart'; 9 | import 'package:addtocartanimationdemo/data.dart'; 10 | import 'package:flutter/material.dart'; 11 | 12 | void main() { 13 | runApp(const MyApp()); 14 | } 15 | 16 | class MyApp extends StatelessWidget { 17 | const MyApp({super.key}); 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return const MaterialApp( 22 | debugShowCheckedModeBanner: false, 23 | home: Home(), 24 | ); 25 | } 26 | } 27 | 28 | class Home extends StatefulWidget { 29 | const Home({super.key}); 30 | 31 | @override 32 | State createState() => _HomeState(); 33 | } 34 | 35 | class _HomeState extends State { 36 | 37 | 38 | GlobalKey cartKey = GlobalKey(); 39 | Function(GlobalKey)? runAddToCartAnimation; 40 | var _cartQuantityItems = 0; 41 | 42 | @override 43 | Widget build(BuildContext context) { 44 | return AddToCartAnimation( 45 | cartKey: cartKey, 46 | height: 30, 47 | width: 30, 48 | opacity: 0.9, 49 | dragAnimation: const DragToCartAnimationOptions( 50 | rotation: false, 51 | ), 52 | createAddToCartAnimation: (addToCart) { 53 | runAddToCartAnimation = addToCart; 54 | }, 55 | jumpAnimation: const JumpAnimationOptions(), 56 | child: Scaffold( 57 | appBar: AppBar( 58 | title: const Text("Add To Cart"), 59 | actions: [ 60 | if (_cartQuantityItems > 0) 61 | IconButton( 62 | icon: const Icon(Icons.remove_shopping_cart), 63 | onPressed: () { 64 | _cartQuantityItems = 0; 65 | cartKey.currentState!.runClearCartAnimation(); 66 | setState(() {}); 67 | }, 68 | ), 69 | const SizedBox(width: 16), 70 | AddToCartIcon( 71 | key: cartKey, 72 | icon: const Icon(Icons.shopping_cart), 73 | badgeOptions: BadgeOptions( 74 | active: (_cartQuantityItems > 0), 75 | backgroundColor: Colors.redAccent, 76 | foregroundColor: Colors.white, 77 | ), 78 | ), 79 | const SizedBox( 80 | width: 16, 81 | ) 82 | ], 83 | ), 84 | body: ListView.builder( 85 | itemCount: products.length, 86 | itemBuilder: (context, index) { 87 | return ProductCard( 88 | key: UniqueKey(), 89 | product: products[index], 90 | addToCartClick: addToCartClick, 91 | ); 92 | }, 93 | ), 94 | ), 95 | ); 96 | } 97 | 98 | void addToCartClick(GlobalKey widgetKey) async { 99 | if (runAddToCartAnimation != null) { 100 | await runAddToCartAnimation!(widgetKey); 101 | await cartKey.currentState! 102 | .runCartAnimation((++_cartQuantityItems).toString()); 103 | setState(() {}); 104 | } 105 | } 106 | } 107 | 108 | class ProductCard extends StatelessWidget { 109 | final dynamic product; 110 | final Function(GlobalKey) addToCartClick; 111 | final GlobalKey widgetKey = GlobalKey(); 112 | 113 | ProductCard({super.key, this.product, required this.addToCartClick}); 114 | 115 | @override 116 | Widget build(BuildContext context) { 117 | return Container( 118 | margin: const EdgeInsets.symmetric( 119 | horizontal: 15, 120 | vertical: 8, 121 | ), 122 | decoration: BoxDecoration( 123 | border: Border.all( 124 | color: Colors.grey.shade300, 125 | ), 126 | ), 127 | padding: const EdgeInsets.all(10), 128 | child: Column( 129 | mainAxisAlignment: MainAxisAlignment.start, 130 | crossAxisAlignment: CrossAxisAlignment.start, 131 | children: [ 132 | Row( 133 | mainAxisAlignment: MainAxisAlignment.start, 134 | children: [ 135 | Container( 136 | key: widgetKey, 137 | child: Image.network( 138 | product["image"], 139 | height: 50, 140 | width: 50, 141 | ), 142 | ), 143 | const SizedBox( 144 | width: 20, 145 | ), 146 | Flexible( 147 | child: Text( 148 | product['title'], 149 | ), 150 | ) 151 | ], 152 | ), 153 | const SizedBox( 154 | height: 10, 155 | ), 156 | Row( 157 | mainAxisAlignment: MainAxisAlignment.start, 158 | crossAxisAlignment: CrossAxisAlignment.start, 159 | children: [ 160 | Text( 161 | "Price: \$${product['price']}", 162 | ), 163 | const SizedBox( 164 | width: 10, 165 | ), 166 | const Icon( 167 | Icons.star_rate, 168 | color: Colors.yellow, 169 | ), 170 | Text( 171 | "${product['rating']['rate']} (${product['rating']['count']})", 172 | ), 173 | ], 174 | ), 175 | TextButton( 176 | onPressed: () { 177 | addToCartClick(widgetKey); 178 | }, 179 | child: const Text( 180 | "Add To Cart", 181 | style: TextStyle( 182 | color: Colors.purple, 183 | ), 184 | ), 185 | ), 186 | ], 187 | ), 188 | ); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /url launcher/main.dart: -------------------------------------------------------------------------------- 1 | /* add plugin 2 | url_launcher: ^6.1.6 3 | 4 | AndroidManifest.xml 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | */ 26 | 27 | 28 | import 'package:flutter/material.dart'; 29 | import 'package:url_launcher/url_launcher.dart'; 30 | 31 | void main() async { 32 | runApp(const MyApp()); 33 | } 34 | 35 | class MyApp extends StatelessWidget { 36 | const MyApp({Key? key}) : super(key: key); 37 | 38 | @override 39 | Widget build(BuildContext context) { 40 | return MaterialApp( 41 | title: 'URL launcher', 42 | theme: ThemeData( 43 | primarySwatch: Colors.blue, 44 | ), 45 | home: const MyHomePage(title: 'URL launcher'), 46 | ); 47 | } 48 | } 49 | 50 | class MyHomePage extends StatefulWidget { 51 | const MyHomePage({Key? key, required this.title}) : super(key: key); 52 | final String title; 53 | @override 54 | State createState() => _MyHomePageState(); 55 | } 56 | 57 | class _MyHomePageState extends State { 58 | /* 59 | Hey everyone today we are going to see a useful plugin , which you can use to launch a webpage or mail or caller or whatsapp etc. 60 | from your flutter app 61 | let see the plugin 62 | let see its setup 63 | that's it 64 | 65 | let's see our code 66 | let's run and then check 67 | okay we got 4 button here 68 | for web site, gmail, messenger,and caller/dialer 69 | 70 | all working 71 | thanks for watching 72 | and please subcribe thank you 73 | 74 | */ 75 | @override 76 | Widget build(BuildContext context) { 77 | return Scaffold( 78 | appBar: AppBar( 79 | title: Text(widget.title), 80 | ), 81 | body: Column( 82 | mainAxisAlignment: MainAxisAlignment.center, 83 | crossAxisAlignment: CrossAxisAlignment.stretch, 84 | mainAxisSize: MainAxisSize.max, 85 | children: [ 86 | // button to launch website 87 | ElevatedButton( 88 | onPressed: () { 89 | // for web simply pass you url and pass that uri to method we created 90 | Uri uri = Uri.https('flutter.dev'); //https://flutter.dev/ 91 | _launchUrl(uri); 92 | // let's see in action 93 | // yup 94 | 95 | }, 96 | child: const Text("Open web site"), 97 | ), 98 | ElevatedButton( 99 | onPressed: () { 100 | // next is mail 101 | Uri uri = Uri( 102 | scheme: 'mailto', // this is scheme for mail 103 | path: 'flutter@example.com', // you receipient email 104 | query: encodeQueryParameters({ 105 | 'subject': 'Testing mail launch from fluter app', // subject 106 | 'body': "this mail body is from flutter code" // body 107 | }), 108 | ); 109 | _launchUrl(uri); // pass this uri 110 | // let's see 111 | }, 112 | child: const Text("Open gmail"), 113 | ), 114 | ElevatedButton( 115 | onPressed: () { 116 | // next is sms 117 | 118 | final Uri uri = Uri( 119 | scheme: 'sms', // scheme 120 | path: '+919876543210', // mobile no 121 | queryParameters: { 122 | 'body': Uri.encodeComponent('Hello'), // your message 123 | }, 124 | ); 125 | _launchUrl(uri); // pass uri 126 | // let's check 127 | 128 | }, 129 | child: const Text("Open messenger"), 130 | ), 131 | ElevatedButton( 132 | onPressed: () { 133 | // next is dialler 134 | final Uri uri = Uri( 135 | scheme: 'tel', // this is scheme for call 136 | path: '+91987654321', // mobile no 137 | ); 138 | _launchUrl(uri); // pass uri 139 | // let's check 140 | }, 141 | child: const Text("Open dialer/caller"), 142 | ), 143 | ], 144 | ), 145 | ); 146 | } 147 | 148 | // i have created a func to launch url 149 | // as name say this plugin uses url to launch different app 150 | // 151 | // so we got func to launch a uri so let create uri for these 152 | Future _launchUrl(Uri url) async { 153 | try { 154 | if (await canLaunchUrl(url)) { 155 | //we canLaunchUrl method you can check your url is good to launch or not , and if you want to check any url if it correct and not you can also use this 156 | await launchUrl( 157 | // launchUrl is to launch 158 | url, // passing our url 159 | ); 160 | } else { 161 | throw 'Could not launch $url'; 162 | } 163 | } catch (_) {} 164 | } 165 | 166 | String? encodeQueryParameters(Map params) { 167 | // this method is to create encodequery i.e from { 'a':'1'} to https:google.com?a=1 somthing like this 168 | return params.entries 169 | .map((MapEntry e) => 170 | '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') 171 | .join('&'); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /razorpay/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | 4 | import 'package:flutter/material.dart'; 5 | import 'package:razorpay_flutter/razorpay_flutter.dart'; 6 | import 'package:http/http.dart' as http; 7 | import 'razor_credentials.dart' as razorCredentials; 8 | 9 | void main() { 10 | HttpOverrides.global = MyHttpOverrides(); 11 | 12 | runApp(const MyApp()); 13 | } 14 | 15 | class MyApp extends StatelessWidget { 16 | const MyApp({Key? key}) : super(key: key); 17 | 18 | @override 19 | Widget build(BuildContext context) { 20 | return MaterialApp( 21 | title: 'Razorpay Demo', 22 | theme: ThemeData( 23 | primarySwatch: Colors.blue, 24 | ), 25 | home: const MyHomePage(), 26 | ); 27 | } 28 | } 29 | 30 | class MyHomePage extends StatefulWidget { 31 | const MyHomePage({Key? key}) : super(key: key); 32 | 33 | @override 34 | State createState() => _MyHomePageState(); 35 | } 36 | 37 | class _MyHomePageState extends State { 38 | final _razorpay = Razorpay(); 39 | 40 | @override 41 | void initState() { 42 | WidgetsBinding.instance.addPostFrameCallback((timeStamp) { 43 | _razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess); 44 | _razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError); 45 | _razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet); 46 | }); 47 | super.initState(); 48 | } 49 | 50 | void _handlePaymentSuccess(PaymentSuccessResponse response) { 51 | // Do something when payment succeeds 52 | print(response); 53 | verifySignature( 54 | signature: response.signature, 55 | paymentId: response.paymentId, 56 | orderId: response.orderId, 57 | ); 58 | } 59 | 60 | void _handlePaymentError(PaymentFailureResponse response) { 61 | print(response); 62 | // Do something when payment fails 63 | ScaffoldMessenger.of(context).showSnackBar( 64 | SnackBar( 65 | content: Text(response.message ?? ''), 66 | ), 67 | ); 68 | } 69 | 70 | void _handleExternalWallet(ExternalWalletResponse response) { 71 | print(response); 72 | // Do something when an external wallet is selected 73 | ScaffoldMessenger.of(context).showSnackBar( 74 | SnackBar( 75 | content: Text(response.walletName ?? ''), 76 | ), 77 | ); 78 | } 79 | 80 | // create order 81 | void createOrder() async { 82 | String username = razorCredentials.keyId; 83 | String password = razorCredentials.keySecret; 84 | String basicAuth = 85 | 'Basic ${base64Encode(utf8.encode('$username:$password'))}'; 86 | 87 | Map body = { 88 | "amount": 100, 89 | "currency": "INR", 90 | "receipt": "rcptid_11" 91 | }; 92 | var res = await http.post( 93 | Uri.https( 94 | "api.razorpay.com", "v1/orders"), //https://api.razorpay.com/v1/orders 95 | headers: { 96 | "Content-Type": "application/json", 97 | 'authorization': basicAuth, 98 | }, 99 | body: jsonEncode(body), 100 | ); 101 | 102 | if (res.statusCode == 200) { 103 | openGateway(jsonDecode(res.body)['id']); 104 | } 105 | print(res.body); 106 | } 107 | 108 | openGateway(String orderId) { 109 | var options = { 110 | 'key': razorCredentials.keyId, 111 | 'amount': 100, //in the smallest currency sub-unit. 112 | 'name': 'Acme Corp.', 113 | 'order_id': orderId, // Generate order_id using Orders API 114 | 'description': 'Fine T-Shirt', 115 | 'timeout': 60 * 5, // in seconds // 5 minutes 116 | 'prefill': { 117 | 'contact': '9123456789', 118 | 'email': 'ary@example.com', 119 | } 120 | }; 121 | _razorpay.open(options); 122 | } 123 | 124 | verifySignature({ 125 | String? signature, 126 | String? paymentId, 127 | String? orderId, 128 | }) async { 129 | Map body = { 130 | 'razorpay_signature': signature, 131 | 'razorpay_payment_id': paymentId, 132 | 'razorpay_order_id': orderId, 133 | }; 134 | 135 | var parts = []; 136 | body.forEach((key, value) { 137 | parts.add('${Uri.encodeQueryComponent(key)}=' 138 | '${Uri.encodeQueryComponent(value)}'); 139 | }); 140 | var formData = parts.join('&'); 141 | var res = await http.post( 142 | Uri.https( 143 | "10.0.2.2", // my ip address , localhost 144 | "razorpay_signature_verify.php", 145 | ), 146 | headers: { 147 | "Content-Type": "application/x-www-form-urlencoded", // urlencoded 148 | }, 149 | body: formData, 150 | ); 151 | 152 | print(res.body); 153 | if (res.statusCode == 200) { 154 | ScaffoldMessenger.of(context).showSnackBar( 155 | SnackBar( 156 | content: Text(res.body), 157 | ), 158 | ); 159 | } 160 | } 161 | 162 | @override 163 | void dispose() { 164 | _razorpay.clear(); // Removes all listeners 165 | 166 | super.dispose(); 167 | } 168 | 169 | @override 170 | Widget build(BuildContext context) { 171 | return Scaffold( 172 | appBar: AppBar( 173 | title: const Text("Razorpay Demo"), 174 | ), 175 | body: Center( 176 | child: Column( 177 | mainAxisAlignment: MainAxisAlignment.center, 178 | children: [ 179 | ElevatedButton( 180 | onPressed: () { 181 | createOrder(); 182 | }, 183 | child: const Text("Pay Rs.100"), 184 | ) 185 | ], 186 | ), 187 | ), 188 | ); 189 | } 190 | } 191 | 192 | class MyHttpOverrides extends HttpOverrides { 193 | @override 194 | HttpClient createHttpClient(SecurityContext? context) { 195 | return super.createHttpClient(context) 196 | ..badCertificateCallback = 197 | (X509Certificate cert, String host, int port) => true; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /user-form/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:dummy/home_screen.dart'; 2 | import 'package:dummy/text_validator.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | void main() => runApp(const MyApp()); 6 | 7 | class MyApp extends StatelessWidget { 8 | const MyApp({super.key}); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return MaterialApp( 13 | debugShowCheckedModeBanner: false, 14 | theme: ThemeData( 15 | inputDecorationTheme: InputDecorationTheme( 16 | filled: true, 17 | fillColor: Colors.blue[50], 18 | enabledBorder: OutlineInputBorder( 19 | borderRadius: BorderRadius.circular(10), 20 | borderSide: const BorderSide(color: Colors.blue), 21 | ), 22 | focusedBorder: OutlineInputBorder( 23 | borderRadius: BorderRadius.circular(10), 24 | borderSide: const BorderSide(color: Colors.blue, width: 2), 25 | ), 26 | errorBorder: OutlineInputBorder( 27 | borderRadius: BorderRadius.circular(10), 28 | borderSide: const BorderSide(color: Colors.red, width: 2), 29 | ), 30 | focusedErrorBorder: OutlineInputBorder( 31 | borderRadius: BorderRadius.circular(10), 32 | borderSide: const BorderSide(color: Colors.red, width: 2), 33 | ), 34 | ), 35 | elevatedButtonTheme: ElevatedButtonThemeData( 36 | style: ElevatedButton.styleFrom( 37 | padding: 38 | const EdgeInsets.symmetric(vertical: 16.0, horizontal: 32.0), 39 | backgroundColor: Colors.blueAccent, 40 | shape: RoundedRectangleBorder( 41 | borderRadius: BorderRadius.circular(12), 42 | ), 43 | elevation: 8, 44 | ), 45 | )), 46 | home: Scaffold( 47 | body: GestureDetector( 48 | onTap: () { 49 | // Hide keyboard when tapping outside 50 | FocusScope.of(context).unfocus(); 51 | }, 52 | child: Container( 53 | // Gradient background 54 | decoration: const BoxDecoration( 55 | gradient: LinearGradient( 56 | colors: [ 57 | Colors.blueAccent, 58 | Colors.lightBlueAccent, 59 | ], 60 | begin: Alignment.topCenter, 61 | end: Alignment.bottomCenter, 62 | ), 63 | ), 64 | child: const Center( 65 | child: Padding( 66 | padding: EdgeInsets.all(16.0), 67 | child: SingleChildScrollView(child: MyFormCard()), 68 | ), 69 | ), 70 | ), 71 | ), 72 | ), 73 | ); 74 | } 75 | } 76 | 77 | class MyFormCard extends StatelessWidget { 78 | const MyFormCard({super.key}); 79 | 80 | @override 81 | Widget build(BuildContext context) { 82 | return Card( 83 | elevation: 12, 84 | shape: RoundedRectangleBorder( 85 | borderRadius: BorderRadius.circular(15), 86 | ), 87 | color: Colors.white, 88 | child: const Padding( 89 | padding: EdgeInsets.all(20.0), 90 | child: Column( 91 | mainAxisSize: MainAxisSize.min, 92 | children: [ 93 | Text( 94 | 'User Form', 95 | style: TextStyle( 96 | fontSize: 22, 97 | fontWeight: FontWeight.bold, 98 | color: Colors.blueAccent, 99 | ), 100 | ), 101 | SizedBox(height: 20), 102 | MyForm(), 103 | ], 104 | ), 105 | ), 106 | ); 107 | } 108 | } 109 | 110 | class MyForm extends StatefulWidget { 111 | const MyForm({super.key}); 112 | 113 | @override 114 | _MyFormState createState() => _MyFormState(); 115 | } 116 | 117 | class _MyFormState extends State { 118 | final _formKey = GlobalKey(); 119 | // Instances of callable objects for validation 120 | final TextValidator emailValidator = TextValidator('email'); 121 | final TextValidator usernameValidator = TextValidator('username'); 122 | final TextValidator passwordValidator = TextValidator('password'); 123 | 124 | String email = ''; 125 | String username = ''; 126 | String password = ''; 127 | 128 | @override 129 | Widget build(BuildContext context) { 130 | return Form( 131 | key: _formKey, 132 | child: Column( 133 | crossAxisAlignment: CrossAxisAlignment.stretch, 134 | children: [ 135 | // Email Field 136 | TextFormField( 137 | decoration: const InputDecoration( 138 | labelText: 'Email', 139 | hintText: 'Enter your email', 140 | prefixIcon: Icon(Icons.email), 141 | ), 142 | validator: (value) => emailValidator(value!), 143 | onChanged: (value) => email = value, 144 | ), 145 | const SizedBox(height: 20), 146 | 147 | // Username Field 148 | TextFormField( 149 | decoration: const InputDecoration( 150 | labelText: 'Username', 151 | hintText: 'Choose a username', 152 | prefixIcon: Icon(Icons.person), 153 | ), 154 | validator: (value) => usernameValidator(value!), 155 | onChanged: (value) => username = value, 156 | ), 157 | const SizedBox(height: 20), 158 | 159 | // Password Field 160 | TextFormField( 161 | decoration: const InputDecoration( 162 | labelText: 'Password', 163 | hintText: 'Enter your password', 164 | prefixIcon: Icon(Icons.lock), 165 | ), 166 | obscureText: true, 167 | validator: (value) => passwordValidator(value!), 168 | onChanged: (value) => password = value, 169 | ), 170 | const SizedBox(height: 30), 171 | 172 | // Submit Button 173 | ElevatedButton( 174 | onPressed: () { 175 | if (_formKey.currentState!.validate()) { 176 | Navigator.pushReplacement( 177 | context, 178 | MaterialPageRoute(builder: (context) => const HomeScreen()), 179 | ); 180 | } 181 | }, 182 | child: const Text( 183 | 'Submit', 184 | style: TextStyle( 185 | fontSize: 18, 186 | color: Colors.white, 187 | ), 188 | ), 189 | ), 190 | ], 191 | ), 192 | ); 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /statemanagement-getx/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | plugins 3 | http: ^1.1.0 4 | shimmer: ^3.0.0 5 | get: ^4.6.6 6 | */ 7 | 8 | 9 | import 'package:flutter/material.dart'; 10 | import 'package:get/get_state_manager/get_state_manager.dart'; 11 | import 'package:get/instance_manager.dart'; 12 | import 'package:shimmer/shimmer.dart'; 13 | import 'package:skeletondemo/data_controller.dart'; 14 | 15 | void main() { 16 | runApp(const MyApp()); 17 | } 18 | 19 | class MyApp extends StatelessWidget { 20 | const MyApp({super.key}); 21 | 22 | @override 23 | Widget build(BuildContext context) { 24 | return MaterialApp( 25 | title: 'Flutter Demo', 26 | theme: ThemeData( 27 | colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), 28 | useMaterial3: true, 29 | ), 30 | home: const ProductsList(), 31 | ); 32 | } 33 | } 34 | 35 | class ProductsList extends StatefulWidget { 36 | const ProductsList({super.key}); 37 | 38 | @override 39 | State createState() => _ProductsListState(); 40 | } 41 | 42 | class _ProductsListState extends State { 43 | @override 44 | void initState() { 45 | super.initState(); 46 | 47 | Get.put( 48 | DataController()); // you need to put your controller before you can use 49 | 50 | // i am going to call our getproduct method in init - it's first method which get execute 51 | 52 | WidgetsBinding.instance.addPostFrameCallback((timeStamp) { 53 | final dataController = Get.find(); 54 | dataController.getProducts(); 55 | }); 56 | } 57 | 58 | // that's it now let check it 59 | 60 | /* 61 | 62 | 63 | Hey everyone , Today we are going to see how to use GetX state management 64 | 65 | you may have seen this app in shimmer or skeleton demo video , i am going to change this for with GetX state management 66 | 67 | 68 | let's install plugin first 69 | 70 | we need a controller class , lets create it 71 | 72 | 73 | unlike previous way of loading now our data will be loaded once when page loaded 74 | 75 | let's summarize this 76 | 77 | 1- controller 78 | 2. wrap widget with Obx 79 | Thanks for watching 80 | 81 | 82 | */ 83 | 84 | @override 85 | Widget build(BuildContext context) { 86 | final dataController = 87 | Get.find(); // controller in <> brackets 88 | // wrap the widget where you want to make your variable to rebuild when value changes with 89 | return Obx( 90 | () => Scaffold( 91 | appBar: AppBar( 92 | title: const Text("Products"), 93 | ), 94 | body: dataController.loading.value 95 | ? Shimmer.fromColors( 96 | baseColor: Colors.white, 97 | highlightColor: Colors.grey.shade300, 98 | child: ListView.builder( 99 | itemCount: 5, 100 | itemBuilder: (context, index) { 101 | return Padding( 102 | padding: const EdgeInsets.all(8.0), 103 | child: Column( 104 | mainAxisAlignment: MainAxisAlignment.start, 105 | crossAxisAlignment: CrossAxisAlignment.start, 106 | children: [ 107 | Container( 108 | height: 8, 109 | color: Colors.white, 110 | width: 150, 111 | ), 112 | const SizedBox( 113 | height: 5, 114 | ), 115 | Container( 116 | height: 80, 117 | color: Colors.white, 118 | width: double.infinity, 119 | ), 120 | const SizedBox( 121 | height: 5, 122 | ), 123 | Row( 124 | children: [ 125 | Container( 126 | height: 8, 127 | color: Colors.white, 128 | width: 40, 129 | ), 130 | const SizedBox( 131 | width: 15, 132 | ), 133 | Container( 134 | height: 8, 135 | color: Colors.white, 136 | width: 150, 137 | ), 138 | ], 139 | ) 140 | ], 141 | ), 142 | ); 143 | })) 144 | : ListView.builder( 145 | itemCount: dataController.products.length, 146 | itemBuilder: (context, index) { 147 | return Card( 148 | color: Colors.white, 149 | margin: const EdgeInsets.symmetric( 150 | horizontal: 15, 151 | vertical: 8, 152 | ), 153 | elevation: 1, 154 | child: Padding( 155 | padding: const EdgeInsets.all(8.0), 156 | child: Column( 157 | mainAxisAlignment: MainAxisAlignment.start, 158 | crossAxisAlignment: CrossAxisAlignment.start, 159 | children: [ 160 | Text( 161 | dataController.products[index].brand ?? '', 162 | ), 163 | const SizedBox( 164 | height: 5, 165 | ), 166 | Image.network( 167 | dataController.products[index].thumbnail ?? ''), 168 | const SizedBox( 169 | height: 5, 170 | ), 171 | Row( 172 | children: [ 173 | Text( 174 | "\$${dataController.products[index].price ?? ''}"), 175 | const SizedBox( 176 | width: 15, 177 | ), 178 | ElevatedButton( 179 | onPressed: () {}, 180 | child: const Text("Buy Now"), 181 | ) 182 | ], 183 | ) 184 | ], 185 | ), 186 | ), 187 | ); 188 | }), 189 | ), 190 | ); 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /searchbar/home.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:dummy/model/product.dart'; 4 | import 'package:dummy/model/product_response.dart'; 5 | import 'package:dummy/product_details.dart'; 6 | import 'package:dummy/product_item.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:http/http.dart' as http; 9 | 10 | class Home extends StatefulWidget { 11 | const Home({super.key}); 12 | 13 | @override 14 | State createState() => _HomeState(); 15 | } 16 | 17 | class _HomeState extends State { 18 | @override 19 | void initState() { 20 | super.initState(); 21 | getProducts(); 22 | } 23 | 24 | List products = List.empty(); 25 | @override 26 | Widget build(BuildContext context) { 27 | return Scaffold( 28 | appBar: AppBar( 29 | backgroundColor: Colors.amberAccent, 30 | title: const Text("Products"), 31 | elevation: 6, 32 | ), 33 | body: Column( 34 | children: [ 35 | Padding( 36 | padding: const EdgeInsets.all(8.0), 37 | child: SearchAnchor( 38 | viewLeading: IconButton( 39 | onPressed: () { 40 | FocusScope.of(context).requestFocus(FocusNode()); 41 | Navigator.of(context).pop(); 42 | }, 43 | icon: const Icon( 44 | Icons.arrow_back, 45 | ), 46 | ), 47 | builder: (BuildContext context, SearchController controller) { 48 | return SearchBar( 49 | controller: controller, 50 | padding: const WidgetStatePropertyAll( 51 | EdgeInsets.symmetric(horizontal: 16.0), 52 | ), 53 | leading: IconButton( 54 | onPressed: () { 55 | controller.openView(); 56 | }, 57 | icon: const Icon(Icons.search), 58 | ), 59 | onTap: () { 60 | controller.openView(); 61 | }, 62 | onChanged: (_) { 63 | controller.openView(); 64 | }, 65 | onTapOutside: (v) { 66 | FocusScope.of(context).requestFocus(FocusNode()); 67 | }, 68 | hintText: "Enter keywords", 69 | ); 70 | }, 71 | isFullScreen: true, 72 | suggestionsBuilder: 73 | (BuildContext context, SearchController controller) { 74 | List results = [...products] 75 | .where((e) => 76 | e.title?.contains(controller.text.trim()) == true) 77 | .toList(); 78 | return results.map((g) => ProductItem(product: g)); 79 | }, 80 | ), 81 | ), 82 | Expanded( 83 | child: GridView.builder( 84 | itemCount: products.length, 85 | gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( 86 | crossAxisCount: 2, 87 | childAspectRatio: 0.9, 88 | ), 89 | itemBuilder: (context, index) { 90 | return Container( 91 | margin: const EdgeInsets.symmetric( 92 | horizontal: 15, 93 | vertical: 8, 94 | ), 95 | decoration: BoxDecoration( 96 | borderRadius: BorderRadius.circular(10), 97 | border: Border.all(color: Colors.grey), 98 | ), 99 | padding: const EdgeInsets.all(15), 100 | alignment: Alignment.center, 101 | child: Column( 102 | mainAxisAlignment: MainAxisAlignment.start, 103 | crossAxisAlignment: CrossAxisAlignment.start, 104 | children: [ 105 | InkWell( 106 | onTap: () { 107 | Navigator.of(context).push( 108 | MaterialPageRoute( 109 | builder: (context) => ProductDetails( 110 | product: products[index], 111 | ), 112 | ), 113 | ); 114 | }, 115 | child: Hero( 116 | tag: products[index].thumbnail ?? '', 117 | child: Container( 118 | height: 90, 119 | decoration: BoxDecoration( 120 | color: const Color(0xFFD5DCDE), 121 | borderRadius: BorderRadius.circular(10), 122 | ), 123 | alignment: Alignment.center, 124 | child: Image.network( 125 | products[index].thumbnail ?? '', 126 | ), 127 | ), 128 | ), 129 | ), 130 | const SizedBox( 131 | height: 10, 132 | ), 133 | Material( 134 | color: Colors.transparent, 135 | child: Hero( 136 | tag: products[index].title ?? '', 137 | child: Material( 138 | color: Colors.transparent, 139 | child: Text( 140 | products[index].title ?? '', 141 | style: const TextStyle( 142 | fontWeight: FontWeight.w500, 143 | fontSize: 14, 144 | overflow: TextOverflow.ellipsis, 145 | ), 146 | ), 147 | ), 148 | ), 149 | ), 150 | Row( 151 | children: [ 152 | Text( 153 | "\$ ${products[index].price}", 154 | style: const TextStyle( 155 | fontWeight: FontWeight.w500, 156 | fontSize: 12, 157 | ), 158 | ), 159 | const SizedBox( 160 | width: 10, 161 | ), 162 | const Icon( 163 | Icons.star, 164 | color: Colors.amberAccent, 165 | ), 166 | Text( 167 | "${products[index].rating}", 168 | style: const TextStyle( 169 | fontWeight: FontWeight.w500, 170 | fontSize: 12, 171 | ), 172 | ), 173 | ], 174 | ) 175 | ], 176 | ), 177 | ); 178 | }, 179 | ), 180 | ), 181 | ], 182 | ), 183 | ); 184 | } 185 | 186 | getProducts() async { 187 | var res = await http.get(Uri.https("dummyjson.com", "products")); 188 | ProductResponse response = ProductResponse.fromJson(jsonDecode(res.body)); 189 | setState(() { 190 | products = response.products ?? []; 191 | }); 192 | } 193 | } 194 | --------------------------------------------------------------------------------