Posts

Showing posts from February, 2023

Using The Stack Widget

Image
Using The Stack Widget The  Stack  widget is commonly used to overlap, position, and align widgets to create a custom look. A good example is a shopping cart with the number of items to purchase on the upper-right side. The Stack children list of the widget is either positioned or nonpositioned. When you use a Positioned widget, each child widget is placed at the appropriate location. The Stack widget resizes itself to accommodate all of the nonpositioned children. The nonpositioned children are positioned to the alignment property (Top-Left or Top-Right depending on the left-to-right or right-to-left environment).  Each Stack child widget is drawn in order from bottom to top, like stacking pieces of paper on top of each other.  This means the first widget drawn is at the bottom of the Stack, and then the next widget is drawn above the previous widget and so on. Each child widget is positioned on top of each other in the order of the Stack children list. The RenderSt...

Widget Lifecycle Events

Image
  Widget Lifecycle Events  In programming, you have different lifecycle events that usually happen in a linear mode, one after another as each stage is completed. In this section, you’ll learn the widget lifecycle events and their purpose. To build the UI, you use two main types of widgets, StatelessWidget and StatefulWidget. A stateless widget is used when the values (state) do not change, and the stateful widget is used when values (state) change. The StatelessWidget Lifecycle A  StatelessWidget  is built based on its own configuration and does not change dynamically. For example, the screen displays an image with a description and will not change. The stateless widget is declared with one class. The build (the UI portions) method of the stateless widget can be called from three different scenarios. It can be called the first time the widget is created, when the widget’s parent changes, and when an InheritedWidget has changed. The following sample code sh...

Important widget Row & Column with Example

Image
  Important widget Row & Column with Example   In this article, we’re going to learn how to use rows & columns in a flutter with an example. This Topic is very very important in flutter development, without Rows & Columns you cannot build UI. Column  A Column widget displays its children vertically. It takes a children property containing an array of List . The children align vertically without taking up the full height of the screen. Each child widget can be embedded in an Expanded widget to fill available space. You can use CrossAxisAlignment, MainAxisAlignment, and MainAxisSize to align and size how much space is occupied on the main axis. Column(   crossAxisAlignment: CrossAxisAlignment.center,  mainAxisAlignment: MainAxisAlignment.spaceEvenly,  mainAxisSize: MainAxisSize.max,  children: <Widget>[  Text('Column 1'),  Divider(),  Text('Column 2'),  Divider(),  Text('Column 3'),  ], ), Row A Row widget ...

HTTP GET Response in Flutter

  HTTP GET Response in Flutter Model Class // To parse this JSON data, do // // final welcome = welcomeFromJson(jsonString); import 'dart:convert' ; List<Welcome> welcomeFromJson (String str) => List <Welcome>. from (json.decode(str).map((x) => Welcome . fromJson (x))) ; String welcomeToJson (List<Welcome> data) => json.encode( List < dynamic >. from (data.map((x) => x.toJson()))) ; class Welcome { Welcome({ required this . userId , required this . id , required this . title , }) ; int userId ; int id ; String title ; factory Welcome. fromJson (Map<String , dynamic > json) => Welcome ( userId: json[ "userId" ] , id: json[ "id" ] , title: json[ "title" ] , ) ; Map<String , dynamic > toJson () => { "userId" : userId , "id" : id , "title" : title , } ; } Main Class // Importing important packages require to conn...

Search ListView In flutter

Search ListView In flutter   Hello friends, today we will teach you how to search in list and listview. Array List List<Invoices> historyList = [] ; if (response.statusCode == 200 ) { var responseData = json.decode(response.body) ; var orderHistory = responseData[ 'invoices' ] ; for ( var coinJSON in orderHistory) { historyList .add(Invoices.fromJson(coinJSON)) ; items .add(Invoices.fromJson(coinJSON)) ; } print( '----------------> ${ historyList . length } ' ) ; print(responseData) ; setState(() {}) ; } var items = <Invoices>[] ; void filterSearchResults(String query) { List<Invoices> dummySearchList = <Invoices>[] ; dummySearchList.addAll(historyList) ; if (query.isNotEmpty) { List<Invoices> dummyListData = <Invoices>[] ; dummySearchList.forEach((item) { if (item.swiggyOrderId!.contains(query)) { dummyListData.add(item) ; print( "yes" ) ; } }) ; set...