Today in this post we will learn to create a custom dynamic listview and you can connect the dynamic list with firebase. And from there you can display the data as per your requirement in the dynamic list. We will use cards to create the dynamic list and it is created using multiple text on the card. You can also take images if you want and you can make any custom design as per your requirement.
First of all create a project in Android Studio Flutter then copy and paste the code given by us in your project. You can name the app screen anything you like.
InvestmentScreen.dart
import 'package:flutter/material.dart'; import 'package:stocks/util/bluecolor.dart'; class InvestmentScreen extends StatefulWidget { @override _InvestmentScreenState createState() => _InvestmentScreenState(); } class _InvestmentScreenState extends State{ int _selectedIndex = 0; bool _isPortfolioSelected = false; // New variable to track portfolio selection void _onItemTapped(int index) { if (_selectedIndex == index) return; // If the same screen is already selected, do nothing setState(() { _selectedIndex = index; _isPortfolioSelected = index == 1; // Set to true if Portfolio is selected }); // Navigate to the correct screen } final List
Code Explanation
- In this code two packages have been imported. Color and material package have been imported. If you want you can remove the color package and you can give the color directly.
- A class has been created with the name Investmentscreen in which all the codes of the list have been kept. You can also change the name of the class as per the need, this will not cause any difference in the list.
- An array named finallist is created inside which the list data is stored which is displayed inside the list.
- An extension cord is built inside the scaffold.
- listview.builder has been used to create this list. Whenever we have to make a big list then it is better to use listview builder.
Output
0 Comments