Skip to main content

Posts

Showing posts from January, 2024

Create Custom AppBar Widget in Flutter

 Custom AppBar Widget in Flutter Create Dart File, import 'package:flutter/material.dart' ; import 'package:../styles/colors.dart' ; import 'package:../styles/text_style.dart' ; import 'package:../widgets/marquee_direction_widget.dart' ; import 'package:sizer/sizer.dart' ; class AppBarWidget{ // create AppBar Widget here static AppBar appBarWidget (BuildContext context , { String? companyName , String? titleName , List<Widget>? actions , Color? backgroundColor , bool isActions= false, VoidCallback? onClickBackIcon , bool isBackIconView= false, IconThemeData? iconThemeData}) { return AppBar ( backgroundColor: backgroundColor , iconTheme: iconThemeData== null ? IconThemeData (size: 3 . h , color: blackColor):iconThemeData , leading:isBackIconView? GestureDetector ( onTap:onClickBackIcon , child: Icon ( Icons. arrow_back_ios , size: 20 , color: blac...

How to arrange wrong order the list data in Dart

List In Dart 1: =>   To replace the smallest number in a Dart list and move it to the first position, you can use the following code:- void main() {   List<int> a = [3, 5, 2, 8, 6, 10, 9];   // Find the index of the smallest number in the list   int minIndex = 0;   for (int i = 1; i < a.length; i++) {     if (a[i] < a[minIndex]) {       minIndex = i;     }   }   // Swap the smallest number with the number at the first position   int temp = a[0];   a[0] = a[minIndex];   a[minIndex] = temp;   // Print the updated list   print(a); } 2: =>You can sort a Dart list in ascending and descending order without using a separate function by using the sort method and providing a custom comparison function.  Here's an example: void main() {   List<int> a = [3, 5, 2, 8, 6, 10, 9];   // Sort in ascending order   a.sort((a, b) => a.compareTo(b));   print('Asc...

Implement API using Bloc Pattern in Flutter

 Implement API using Bloc Pattern  in Flutter Step 1: Add Dependencies: => flutter_bloc: ^8.1.1 => equatable: ^2.0.5 Step 2: Create a Folder and File => Create a Folder API Bloc => In the API Bloc Folder, Create a Dart File, exampleAPIProvider.dart exampleRepository. dart exampleEvent. dart exampleState. dart exampleBloc. dart 1 => exampleAPIProvider.  import 'dart:convert' ; import 'package:http/http.dart' as http ; class ExampleApiProvider { Future<ExampleModel> fetchData ({Id}) async { var url = Apis. getExampleAPIURL ; var data = { "Id" : 0 } ; var jsonData = json.encode(data) ; // Encode map data http.Response res = await http.post(Uri. parse (url) , headers: { 'Content-Type' : 'application/json' , } , body: jsonData) ; try { Map<String , dynamic > parsor = jsonDecode(res. body .toString()) ; return ExampleModel . fromJson (parsor) ; } ...

How to generate the app.jks file in Flutter

  Generate the app. jks file in Flutter In Flutter, the app.jks file is not directly generated by Flutter itself; rather, it is related to the Android platform and the signing of your Android app. The app.jks file (Java KeyStore) is used to store cryptographic keys and certificates needed for signing and verifying the authenticity of your Android app. Here's a general outline of the steps to generate the app.jks file: 1. Navigate to the Android App Directory: cd your_flutter_project/android 2. Generate a Keystore File (app.jks): keytool -genkey -v -keystore app.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key This command will prompt you for various pieces of information, such as the keystore password , distinguished name fields (e.g., name, organization, etc. ), and the password for the key. Make sure to remember the keystore password and key password as you'll need them later. 3. Configure build. gradle: Inside the android/app/build.gradle file, you'll need...

How to implement rest API using BLoC Pattern in Flutter

 Implement Rest API using  BLoC Pattern  in Flutter Implementing a REST API in Flutter using the BLoC (Business Logic Component) pattern typically involves the following steps: Step 1: - Create the BLoC: Define a class for your BLoC , which will contain the business logic for managing the state of your data. Use the flutter_bloc package to create a BLoC . You can add this package to your pubspec.yaml file: dependencies:   flutter_bloc: ^7.0.0 Run flutter pub get to fetch the package. Create a BLoC class . Here's a simple example : import 'package:bloc/bloc.dart'; // Define events enum MyEvent { fetchData } // Define states abstract class MyState {} class InitialState extends MyState {} class LoadedState extends MyState {   final List<String> data;   LoadedState(this.data); } class ErrorState extends MyState {   final String error;   ErrorState(this.error); } // Define the BLoC class MyBloc extends Bloc<MyEvent, MyState> { ...

How to write a custom responsive TextField widget in Flutter

 TextField widget in Flutter Creating a custom responsive TextField widget in Flutter involves using a combination of Flutter widgets and media query information to adjust the TextField size based on the screen size. Here's a basic example of how you can create a custom responsive TextField widget: import 'package:flutter/material.dart'; class ResponsiveTextField extends StatelessWidget {   final String hintText;   final double minWidth;   final double maxWidth;   ResponsiveTextField({     required this.hintText,     required this.minWidth,     required this.maxWidth,   });   @override   Widget build(BuildContext context) {     double screenWidth = MediaQuery.of(context).size.width;     double scaleFactor = screenWidth / 375.0; // Assuming the base screen width is 375.0 (adjust as needed)     double dynamicWidth = max(minWidth, min(maxWidth, 200.0 * scaleFactor)); // Adjust the initial ...

How to write a custom responsive Image widget in Flutter

  Image widget in Flutter Creating a custom responsive image widget in Flutter involves using a combination of Flutter widgets and media query information to adjust the image size based on the screen size. Here's a basic example of how you can create a custom responsive image widget : import 'package:flutter/material.dart'; class ResponsiveImage extends StatelessWidget {   final String imagePath;   final double minWidth;   final double maxWidth;   ResponsiveImage({     required this.imagePath,     required this.minWidth,     required this.maxWidth,   });   @override   Widget build(BuildContext context) {     double screenWidth = MediaQuery.of(context).size.width;     double scaleFactor = screenWidth / 375.0; // Assuming the base screen width is 375.0 (adjust as needed)     double dynamicWidth = max(minWidth, min(maxWidth, 100.0 * scaleFactor)); // Adjust the initial width as needed ...

How to write a custom responsive text widget in Flutter

 Custom responsive Text widget in Flutter Creating a custom responsive text widget in Flutter involves using a combination of Flutter widgets and media query information to adjust the text size based on the screen size. Here's a basic example of how you can create a custom responsive text widget: import 'package:flutter/material.dart'; //ResponsiveText widget class class ResponsiveText extends StatelessWidget {   final String text;   final double minTextSize;   final double maxTextSize;   ResponsiveText({     required this.text,     required this.minTextSize,     required this.maxTextSize,   });   @override   Widget build(BuildContext context) {     double screenWidth = MediaQuery.of(context).size.width;     double scaleFactor = screenWidth / 375.0; // Assuming the base screen width is 375.0 (adjust as needed)     double dynamicTextSize = max(minTextSize, min(maxTextSize, 16.0 * scaleFa...

How to write a code Internet Connectivity in Flutter

Check Internet Connectivity In Flutter In pubspec.yaml file:  add package, connectivity_plus : ^3.0.3 provider : ^6.0.3 In Dart file: Write a Code, 1- Create  AppScaffold.dart file, import 'package:flutter/material.dart' ; import 'package:../widgets/network_widget.dart' ; import 'network_aware_widget.dart' ; class AppScaffold extends StatelessWidget { final Widget child ; const AppScaffold({Key? key , required this . child }) : super (key: key) ; @override Widget build (BuildContext context) { return Scaffold ( body: NetworkAwareWidget ( onlineChild: child , offlineChild: Center ( child: OfflineWidget () //(according to need create offline Network UI) )) , ) ; } } 2- Create an OfflineWidget.dart file, import 'package:flutter/material.dart' ; import 'package:google_fonts/google_fonts.dart' ; import 'package:.../routes/const_string_route_name.dart' ; import 'package:.../...

How to write a code for an auto-update application in Flutter

 Auto-Update Application In Flutter In pubspec.yaml file : add Packages, Packages Name: open_store : ^0.5.0 #new version update new_version_plus : ^0.0.3 In Dart File:  Write a Code, import 'package:flutter/material.dart' ; import 'package:flutter/cupertino.dart' ; import 'package:new_version_plus/new_version_plus.dart' ; import 'package:open_store/open_store.dart' ; // Use this method for update app version or check version (main mathod) //this method use for check app version then updated or Not updated checkAppVersionUpdate (BuildContext context) async { final newVersion= NewVersionPlus ( iOSId: 'com.example.app' , // This is ios app package name androidId: "com.example.app" , // This is android app package name ) ; final status= await newVersion.getVersionStatus() ; print( "store app_version: ${status!. storeVersion } " ) ; print( " local app_version: ${status!. localVersion } " ) ; print( ...

How to create a custom responsive List View widget in Flutter

ListView Widget Creating a custom responsive ListView widget in Flutter involves handling the sizing of the list items based on the screen size. Below is a basic example of how you can create a custom responsive ListView with adjustable item sizes: import 'package:flutter/material.dart'; class ResponsiveListView extends StatelessWidget {   final List<String> items;   ResponsiveListView({required this.items});   @override   Widget build(BuildContext context) {     double screenWidth = MediaQuery.of(context).size.width;     double scaleFactor = screenWidth / 375.0; // Assuming the base screen width is 375.0 (adjust as needed)     double dynamicItemHeight = 50.0 * scaleFactor; // Adjust the initial item height as needed     return ListView.builder(       itemCount: items.length,       itemBuilder: (context, index) {         return Container(         ...

How to create searching in dart language

 Searching in Dart  // BinarySearch using mixin class mixin BinarySearch {   int binarySearch(list, element) {   int start = 0;   int end = list.length - 1;  // int i = 0;   while (start <= end) {     int mid = ((start + end) / 2).floor();     if (list[mid] == element) {       return mid;     }     if (list[mid] < element) {       start = mid + 1;     } else {       end = mid - 1;     }   }   return -1; } } //This is  Binary Search Method binarySearch (List<int> arr, int userValue, int min, int max) {   if (max >= min) {     print('min $min');     print('max $max');     int mid = ((max + min) / 2).floor();     if (userValue == arr[mid]) {       print('your item is at index: ${mid}');     } else if (userValue > arr[mid]) {       binar...

How to create Dynamic Link using firebase in Flutter

  Dynamic Linking First, You set Firebase in the Flutter Project, then use this code. According to the need to modify this code. import 'dart:async' ; import 'package:firebase_dynamic_links/firebase_dynamic_links.dart' ; import 'package:flutter/material.dart' ; import 'package:flutter/services.dart' ; class DynamicLinkWidget extends StatefulWidget { const DynamicLinkWidget({Key? key}) : super (key: key) ; @override State<DynamicLinkWidget> createState () => _DynamicLinkWidgetState () ; } class _DynamicLinkWidgetState extends State<DynamicLinkWidget>{ String? _linkMessage ; bool _isCreatingLink = false; final FirebaseDynamicLinks dynamicLinks = FirebaseDynamicLinks. instance ; final String DynamicLink = 'https://www.goggle.com?screen= ${loginRoute.toString()} ' ; final String Link = 'https://astscm.page.link' ; @override void initState () { super .initState() ; initDynamicLinks() ; } Future...