How to use Provider to persist the state of Pages while navigating (Flutter) - flutter

I'm very new to flutter and super noob with state management.
I am trying to make an app with 5 tabs in BottomBar, and each of them have multiple pages navigated inside them. Currently If I try to navigate from one of the main pages to their child pages, the AppBar and Bottombar disappears. Below is my current code for my home page. The code represents the things I want to display in every page of the app.
class Home extends StatefulWidget {
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int currentTab = 0; // to keep track of active tab index
final List<Widget> screens = [
Feed(key: PageStorageKey('Feed'),),
Insights(key: PageStorageKey('Insights'),),
Data(key: PageStorageKey('Data'),),
Profile(key: PageStorageKey('Profile'),),
ZPart(key: PageStorageKey('Zpart'),),
];
final PageStorageBucket bucket = PageStorageBucket();
Widget currentScreen = Feed();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
iconTheme: IconThemeData(color: Colors.black),
backgroundColor: Colors.white,
title: Text(
'Zecide',
style: TextStyle(
fontFamily: "Raleway-Black.ttf",
fontSize: 23.0,
color: Color(0xFF3F5EFB),
letterSpacing: 2.0,
fontWeight: FontWeight.w800,
),
),
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(2.0),
child: IconButton(
icon: Icon(Icons.search),
onPressed: (){
},),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: IconButton(icon: Icon(Icons.notifications, color: Colors.blueAccent),
onPressed: (){
},),
)
],
),
////// Drawer ///////
drawer: Drawer(
elevation: 5,
child: ListView(
children: <Widget>[
DrawerHeader(
child: Text('Siddharth Singh', style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700, color: Colors.white),),
decoration: BoxDecoration(color: Colors.blueAccent,),
),
ListTile(title: Text('Settings'),),
ListTile(title: Text('Account Details'),),
ListTile(title: Text('Logout'),),
ListTile(title: Text('Version'), subtitle: Text('Version 1.0 Beta'),),
],
),
),
body: PageStorage(
child: currentScreen,
bucket: bucket,
),
///// Below is bottombar ( Kinda lengthy, you can skip if you want from here) //
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.white,
child: Container(
height: 50.0,
width: 50.0,
child: Image.asset("assets/logo.png"),
),
onPressed: () {
setState(() {
currentScreen = ZPart();
currentTab = 69;
});
},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 10,
child: Container(
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen =
Feed(); // if user taps on this dashboard tab will be active
currentTab = 0;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
FontAwesomeIcons.newspaper,
color: currentTab == 0 ? Colors.blueAccent : Colors.grey,
),
Text(
'Feed',
style: TextStyle(
color: currentTab == 0 ? Colors.black87 : Colors.grey,
fontFamily: "Quicksand-Light",
fontWeight: FontWeight.w400,
),
),
],
),
),
SizedBox(width: 10.0,),
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen =
Insights(); // if user taps on this dashboard tab will be active
currentTab = 1;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
FontAwesomeIcons.chartBar,
color: currentTab == 1 ? Colors.blueAccent : Colors.grey,
),
Text(
'Insights',
style: TextStyle(
color: currentTab == 1 ? Colors.black87 : Colors.grey,
fontFamily: "Quicksand-Light",
fontWeight: FontWeight.w400,
),
),
],
),
)
],
),
// Right Tab bar icons
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen =
Data(); // if user taps on this dashboard tab will be active
currentTab = 2;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.pie_chart_outlined,
color: currentTab == 2 ? Colors.blueAccent : Colors.grey,
),
Text(
'Data',
style: TextStyle(
color: currentTab == 2 ? Colors.black87 : Colors.grey,
fontFamily: "Quicksand-Light",
fontWeight: FontWeight.w400,
),
),
],
),
),
SizedBox(width: 10.0,),
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen =
Profile(); // if user taps on this dashboard tab will be active
currentTab = 3;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
FontAwesomeIcons.user,
color: currentTab == 3 ? Colors.blueAccent : Colors.grey,
),
Text(
'Profile',
style: TextStyle(
color: currentTab == 3 ? Colors.black87 : Colors.grey,
fontFamily: "Quicksand-Light",
fontWeight: FontWeight.w400,
),
),
],
),
)
],
)
],
),
),
),
);
}
}
Although I had used PageStorage in the code, but I'm not very happy with it. As navigating to the child pages while persisting the state seemed confusing. With my current understanding I think all these issues can be solved by provider. I have seen tutorials for provider, but still lacked the clarity to solve this particular issue.
Do comment on how I can improve this question and solve it, Thanks for your time!
I'm attaching images of the app Home screen

Related

How to make custom month picker for reusable in flutter

I want to create a reusable WidgetMonthPicker with my own design..
Like other widget switch, user gets value true or false, here I want to get value of selected month and year from this custom widget..
user don't need to code for taponPlus and tapOnMinus buttons...
design is shown in image
here is my code
class _HomeScreenState extends State<HomeScreen> {
int current_month = DateTime.now().month;
int current_year = DateTime.now().year;
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(children: [
Container(
height: 100,
child: Material(
color: Colors.grey,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
setState(() {
if (current_month == 1) {
current_year--;
current_month = 12;
} else
current_month--;
});
},
icon: Icon(Icons.arrow_back)),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
current_year.toString(),
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
Text(
DateFormat('MMMM')
.format(DateTime(0, current_month))
.toString(),
style: TextStyle(
fontSize: 30,
color: Colors.black,
fontWeight: FontWeight.bold),
),
],
),
IconButton(
onPressed: () {
setState(() {
if (current_month == 12) {
current_year++;
current_month = 1;
} else
current_month++;
});
},
icon: Icon(Icons.arrow_forward)),
],
),
),
),
Expanded(
child: Container(
color: Colors.blue,
child: Center(child: Text('Output')),
),
),
]),
),
);
}
}

How can I save my Radio button value in SharedPreferences?

This my output
when the first time open app should display like this but select one radio button and close open then should display that selected one
EX:- when the user opens the app at the first then should unselect all values, and then the user select grow and click the next button and close the app after reopening again then should display grow as the selected value.
like this
my code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class RadioButtonScreen extends StatefulWidget {
const RadioButtonScreen({Key? key}) : super(key: key);
#override
State<RadioButtonScreen> createState() => _RadioButtonScreenState();
}
class _RadioButtonScreenState extends State<RadioButtonScreen> {
#override
void initState() {
super.initState();
dropdownValueDisease = level;
checkValueDisease();
}
// data which child
// data which child
String? dropdownValueDisease;
// // List of items in our dropdown menu
String level = 'y';
//IF "dropdownValueMembers" is empty pass "which" word as a initial value if al ready selected then pass the shared preference value
checkValueDisease() {
_getDataDisease();
}
_saveDataDisease(String dropdownDiseaseShared) async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
sharedPreferences.setString("Disease", dropdownDiseaseShared);
}
_getDataDisease() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
dropdownValueDisease = sharedPreferences.getString("Disease") ?? level;
setState(() {});
}
//
//
#override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
child: Column(
children: [
SizedBox(
height: height * 0.72,
width: (MediaQuery.of(context).size.width),
child: Column(
children: <Widget>[
const SizedBox(
height: 10,
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"taking",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "talking",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"grow",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "grow",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"listing ",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "listing",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"eye",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "eye",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
title: const Text(
"autism",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "autism",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
],
),
),
Padding(
padding: const EdgeInsets.only(
bottom: 0.0,
),
child: SizedBox(
width: 160.0,
height: 35.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: const BorderSide(
color: Colors.blueAccent,
),
),
),
),
onPressed: () {
_saveDataDisease(level);
},
child: const Text('next')),
),
),
],
),
),
);
}
}
You are trying to save dropdownValueDisease but you should save level value:
onPressed: () {
_saveDataDisease(level);
},
also in your _getDataDisease you need pass SharedPreferences value to level not dropdownValueDisease:
_getDataDisease() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
dropdownValueDisease = sharedPreferences.getString("Disease") ?? level;
level = dropdownValueDisease;
setState(() {});
}

how to solve that buttom navigation bar doesn't appear in flutter

First,, Thanks for answering of questions about flutter in everytime.
As explaining the way this time, I tried to make that seperating button navigation bar as a widget in another file from main file and try to use it in main file like below. but it doesn't appear and not specific error.. so I don't get why is it not apper and how to use this in the way that I tried to? Could you give me some advice about this? Thanks a lot.
--main page I used--
return Scaffold(
bottomNavigationBar: BottomBar(),
--bottomNavigationBar widget page--
class BottomBar extends StatefulWidget {
const BottomBar({Key? key}) : super(key: key);
#override
State<BottomBar> createState() => _BottomBarState();
}
class _BottomBarState extends State<BottomBar> {
int currentTab = 0;
final List<Widget> screens = [
HomePage(),
ShopPage(),
PeoplePage(),
WalletPage()
];
final PageStorageBucket bucket = PageStorageBucket();
Widget currentScreen = HomePage();
#override
Widget build(BuildContext context) {
return Scaffold(
body: PageStorage(
child: currentScreen,
bucket: bucket,
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: (){},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 10,
child: Container(
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = HomePage();
currentTab = 0;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.home,
color: currentTab == 0? Colors.blue : Colors.grey,
),
Text(
'Home',
style: TextStyle(
color: currentTab == 0? Colors.blue : Colors.grey,
),
)
],
),
),
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = ShopPage();
currentTab = 1;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.shop,
color: currentTab == 1? Colors.blue : Colors.grey,
),
Text(
'Shop',
style: TextStyle(
color: currentTab == 1? Colors.blue : Colors.grey,
),
)
],
),
),
],
),
//Right Tab Bar Icons
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = WalletPage();
currentTab = 2;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.wallet,
color: currentTab == 2? Colors.blue : Colors.grey,
),
Text(
'Home',
style: TextStyle(
color: currentTab == 3? Colors.blue : Colors.grey,
),
)
],
),
),
MaterialButton(
minWidth: 40,
onPressed: (){
setState(() {
currentScreen = PeoplePage();
currentTab = 3;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.people,
color: currentTab == 3? Colors.blue : Colors.grey,
),
Text(
'Shop',
style: TextStyle(
color: currentTab == 3? Colors.blue : Colors.grey,
),
)
],
),
),
],
),
],
),
),
),
);
}
}
It is likely due to the fact that your BottomBar class' build method contains a Scaffold and it should not. It should only return a BottomAppBar widget. You can move all of your FAB widget code to the outer scaffold in your Main Page class.

how to remove a value from a list using remove() and setState() in Stateful widget in flutter using onpressed property of a button?

I'm trying to delete a quote from the list on clicking the button. but on click the list doesn't seem to be updated or the quote isn't being deleted on click.
any solutions would be appreciated !!!
this is a list of quotes which i'm displaying in a card in the activity
List<Quote> quotes =[
Quote(quote: "be yourself; everyone else is already taken",author: "oscar wilde"),
Quote(quote: "this is test quote 2",author: "mikey"),
Quote(quote: "good thing about music, when it hits you, you feel no pain",author: "bob marley"),
];
using a textbutton to delete a particular quote on click
class QuoteCard extends StatelessWidget {
final Quote quote;
final Function delete;
QuoteCard({required this.quote, required this.delete});
#override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.fromLTRB(16, 16, 16, 0),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
quote.quote,
style: TextStyle(
fontSize: 18,
color: Colors.grey[600],
),
),
SizedBox(height: 10,),
Text(
quote.author,
style: TextStyle(
fontSize: 14,
color: Colors.grey[800],
),
),
SizedBox(height: 8.0,),
TextButton(
onPressed: (){ delete; },
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.delete),
Text(
'delete quote',
),
],
)
)
],
),
),
);
}
}
trying to delete the quote using the remove() method in setState()
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: AppBar(
title: Text('Awesome Quotes'),
centerTitle: true,
backgroundColor: Colors.redAccent,
),
body: Column(
children: quotes.map((quote) => QuoteCard(
quote:quote,
delete:(){
setState(() {
quotes.remove(quote);
});
}
)).toList(),
),
);
}
}
Card(
margin: EdgeInsets.fromLTRB(16, 16, 16, 0),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
quote.quote,
style: TextStyle(
fontSize: 18,
color: Colors.grey[600],
),
),
SizedBox(height: 10,),
Text(
quote.author,
style: TextStyle(
fontSize: 14,
color: Colors.grey[800],
),
),
SizedBox(height: 8.0,),
TextButton(
onPressed:(){
delete();
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.delete),
Text(
'delete quote',
),
],
)
)
],
),
),
);
Try this one, it works
onPressed:(){
delete();
},

How To Dynamically add Dropdown buttons or delete dropdown(s) in listview with flutter Web?

i have created a page where a user who will click a title to edit the contents and can add and delete devices that the article is attached to,
but i could not figure it out on how to program the drop down dynamically, to add more drop downs when a user press the add device button,
the additional function they want me to add as well is on the Dropdown list, when they select 'NONE' it should remove that dropdown as well,
i am planning to use mysql,xampp or sqlite for my database if im done with the UI,
import 'package:flutter/material.dart';
import 'package:surveyadminpanel/Contents/tabbar.dart';
import 'package:surveyadminpanel/widgets/button.dart';
import 'package:surveyadminpanel/widgets/simplewidgets.dart';
import 'homepage.dart';
import 'dart:ui';
class Item {
Item(this.name);
String name;
}
class editsurvey extends StatefulWidget {
#override
_editsurveyState createState() => _editsurveyState();
}
class _editsurveyState extends State<editsurvey>{
int surveyquestionnum = 1;
int surveyquestiontotal = 1;
List<Item> selectedUser = [null, null];
List<Item> selecteddata = [null, null];
List<Item> users;
int linkdevices = 1;
String dropdownvalue= "SELECT FROM DROPDOWN";
List data = [
'Sample Data 1',
'Sample Data 2',
'Sample Data 3',
'Sample Data 4',
'Sample Data 5',
'Sample Data 6',
];
#override
void initState() {
super.initState();
users = <Item>[
Item('Sample device 1'),
Item('Sample device 2'),
Item('Sample device 3'),
Item('Sample device 4'),
];
}
#override
Widget _dropdownbutton (List<Item> userlist, int index){
return Container(
padding: EdgeInsets.all(1),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(
Radius.circular(15.0) //
),
),
child: DropdownButton<Item>(
underline: SizedBox(),
isExpanded: true,
icon: Icon(Icons.arrow_drop_down),
hint: Text(" $dropdownvalue"),
value: selectedUser[index],
onChanged: (Item Value) {
setState(() {
selectedUser[index] = Value;
});
},
items: userlist.map((Item user) {
return DropdownMenuItem<Item>(
value: user,
child: Row(
children: <Widget>[
SizedBox(width: 10,),
Text(
user.name,
style: TextStyle(color: Colors.black),
),
],
),
);
}).toList(),
),
);
}
Widget _text(texthere,bold,size,color){
return Text(texthere,style: TextStyle(fontWeight: bold,fontSize: size,color: color),overflow: TextOverflow.ellipsis,maxLines: 1);
}
Widget _logo(){
return InkWell(
onTap: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => admincontent()),
);
},
child: Container(width: 500,height: 200,child: Image.asset("images/v2.jpg")));
}
Widget build(BuildContext context) {
double screenHeight = MediaQuery.of(context).size.height;
double screenWidth = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: Padding(padding: EdgeInsets.only(left: 30),
child: RichText(
text: TextSpan(
text: 'Good Morning Welcome to Sample:',
style: TextStyle(
color: Colors.blueAccent, fontSize: 18),
children: <TextSpan>[
TextSpan(text: usernametitle,
style: TextStyle(
color: Colors.black, fontSize: 18),
)
]
),
)
),
elevation: 1,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
leading: _logo(),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.notifications),
color: Colors.blueAccent,
tooltip: 'Show Notification',
onPressed: () {
},
),
IconButton(
color: Colors.lightGreen,
icon: const Icon(Icons.account_circle),
tooltip: 'Check your Profile',
onPressed: () {
},
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
_text("EDIT SURVEY", FontWeight.bold, 20,Colors.blue),
roundedRectButton("BACK", signInGradients),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
width: screenWidth/1.6,
height: screenHeight/1.6,
decoration: BoxDecoration(
color: Colors.orange[200],
borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_text("SURVEY TITLE", FontWeight.bold, 17,Colors.white),
_text(data[0], FontWeight.bold, 19, Colors.black),
_text("DATE CREATED", FontWeight.bold, 17,Colors.white),
_text(data[1], null, 19, Colors.black),
_text("CURRENT STATUS", FontWeight.bold, 17,Colors.white),
_text(data[2], null, 19, Colors.black),
_text("LANGUAGE VERSION", FontWeight.bold, 17,Colors.white),
_text(data[3], null, 19, Colors.black),
_text("NUMBERS OF ASSESSORS", FontWeight.bold, 17,Colors.white),
_text(data[4], null, 19, Colors.black),
_text("TOTAL RENDERED SURVEYS", FontWeight.bold, 17,Colors.white),
_text(data[5], null, 19, Colors.black),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: (){
},
child: Container(width: 100,height: 50,child: Text("EDIT SURVEY")),
),
_text("LINKED DEVICES : $linkdevices", FontWeight.bold, 17,Colors.white),
],
)
],
),
)
),
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid
)
),
width: screenWidth/1.6,
height: screenHeight/1.6,
child: Column(
children: <Widget>[
_text("DEVICES PINNED", FontWeight.bold, 20,Colors.blue),
ListView.separated(
shrinkWrap: true,
itemCount: linkdevices,
itemBuilder: (context, index){
return Padding(
padding: const EdgeInsets.all(8.0),
child: _dropdownbutton(users, index),
);
},
separatorBuilder: (context, index) => Container(height: 10),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
child: roundedRectButton("ADD DEVICE", signInGradients),
onTap: (){
},
),
InkWell(
child: roundedRectButton("CLEAR ALL DEVICE", signInGradients),
onTap: (){
},
),
],
),
],
),
),
],
)
],
),
),
),
);
}
}
The Plan
The Result
im still trying to figure this out, but if someone can give me a lift,, im gonna be very thankful to who can help me out here ,,
You can copy paste run full code below
You can increase linkdevices and selectedUser
code snippet
List<Item> selectedUser = [null];
...
InkWell(
child: Text("ADD DEVICE"),
onTap: () {
selectedUser.add(null);
linkdevices ++;
setState(() {
});
working demo
full code
import 'package:flutter/material.dart';
class Item {
Item(this.name);
String name;
}
class editsurvey extends StatefulWidget {
#override
_editsurveyState createState() => _editsurveyState();
}
class _editsurveyState extends State<editsurvey> {
int surveyquestionnum = 1;
int surveyquestiontotal = 1;
List<Item> selectedUser = [null];
List<Item> selecteddata = [null, null];
List<Item> users;
int linkdevices = 1;
String dropdownvalue = "SELECT FROM DROPDOWN";
List data = [
'Sample Data 1',
'Sample Data 2',
'Sample Data 3',
'Sample Data 4',
'Sample Data 5',
'Sample Data 6',
];
#override
void initState() {
super.initState();
users = <Item>[
Item('Sample device 1'),
Item('Sample device 2'),
Item('Sample device 3'),
Item('Sample device 4'),
];
}
#override
Widget _dropdownbutton(List<Item> userlist, int index) {
return Container(
padding: EdgeInsets.all(1),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.all(Radius.circular(15.0) //
),
),
child: DropdownButton<Item>(
underline: SizedBox(),
isExpanded: true,
icon: Icon(Icons.arrow_drop_down),
hint: Text(" $dropdownvalue"),
value: selectedUser[index],
onChanged: (Item Value) {
print(Value.toString());
print(index);
setState(() {
selectedUser[index] = Value;
});
},
items: userlist.map((Item user) {
return DropdownMenuItem<Item>(
value: user,
child: Row(
children: <Widget>[
SizedBox(
width: 10,
),
Text(
user.name,
style: TextStyle(color: Colors.black),
),
],
),
);
}).toList(),
),
);
}
Widget _text(texthere, bold, size, color) {
return Text(texthere,
style: TextStyle(fontWeight: bold, fontSize: size, color: color),
overflow: TextOverflow.ellipsis,
maxLines: 1);
}
Widget _logo() {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => admincontent()),
);
},
child: Container(
width: 500, height: 200, child: Image.asset("images/v2.jpg")));
}
Widget build(BuildContext context) {
double screenHeight = MediaQuery.of(context).size.height;
double screenWidth = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: Padding(
padding: EdgeInsets.only(left: 30),
child: RichText(
text: TextSpan(
text: 'Good Morning Welcome to Sample:',
style: TextStyle(color: Colors.blueAccent, fontSize: 18),
children: <TextSpan>[
TextSpan(
text: "usernametitle",
style: TextStyle(color: Colors.black, fontSize: 18),
)
]),
)),
elevation: 1,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
leading: _logo(),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.notifications),
color: Colors.blueAccent,
tooltip: 'Show Notification',
onPressed: () {},
),
IconButton(
color: Colors.lightGreen,
icon: const Icon(Icons.account_circle),
tooltip: 'Check your Profile',
onPressed: () {},
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
_text("EDIT SURVEY", FontWeight.bold, 20.0, Colors.blue),
//roundedRectButton("BACK", signInGradients),
Text("BACK"),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
width: screenWidth / 1.6,
height: screenHeight / 1.6,
decoration: BoxDecoration(
color: Colors.orange[200],
borderRadius:
new BorderRadius.all(new Radius.circular(20.0)),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_text("SURVEY TITLE", FontWeight.bold, 17.0,
Colors.white),
_text(data[0], FontWeight.bold, 19.0, Colors.black),
_text("DATE CREATED", FontWeight.bold, 17.0,
Colors.white),
_text(data[1], null, 19.0, Colors.black),
_text("CURRENT STATUS", FontWeight.bold, 17.0,
Colors.white),
_text(data[2], null, 19.0, Colors.black),
_text("LANGUAGE VERSION", FontWeight.bold, 17.0,
Colors.white),
_text(data[3], null, 19.0, Colors.black),
_text("NUMBERS OF ASSESSORS", FontWeight.bold, 17.0,
Colors.white),
_text(data[4], null, 19.0, Colors.black),
_text("TOTAL RENDERED SURVEYS", FontWeight.bold,
17.0, Colors.white),
_text(data[5], null, 19.0, Colors.black),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
InkWell(
onTap: () {},
child: Container(
width: 100,
height: 50,
child: Text("EDIT SURVEY")),
),
_text("LINKED DEVICES : $linkdevices",
FontWeight.bold, 17.0, Colors.white),
],
)
],
),
)),
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid)),
width: screenWidth / 1.6,
height: screenHeight / 1.6,
child: Column(
children: <Widget>[
_text("DEVICES PINNED", FontWeight.bold, 20.0,
Colors.blue),
ListView.separated(
shrinkWrap: true,
itemCount: linkdevices,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: _dropdownbutton(users, index),
);
},
separatorBuilder: (context, index) => Container(height: 10),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
child: Text("ADD DEVICE"),
onTap: () {
selectedUser.add(null);
linkdevices ++;
setState(() {
});
/*listWidget.add( ListView.separated(
shrinkWrap: true,
itemCount: linkdevices,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: _dropdownbutton(users, index),
);
},
separatorBuilder: (context, index) => Container(height: 10),
));
setState(() {
});*/
},
),
InkWell(
child: Text("CLEAR ALL DEVICE"),
onTap: () {},
),
],
),
],
),
),
],
)
],
),
),
),
);
}
}
class admincontent extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container();
}
}
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: editsurvey(),
);
}
}