Animate ListItems into another List within the Same Page - flutter

I’m trying to recreate an animation from dribbble (link: https://dribbble.com/shots/16587569-Planner-App) on the app I’m working on.
What I currently have is just a listview builder and a DayView calendar from (calendar pubspec link) switching on whether the calendar is month view or weekly view (I am using Table Calendar for this).
Here is a snippet of the code:
calendarFormat == CalendarFormat.week ?
Container(
alignment: Alignment.topCenter,
child: DayView(
key: calendarKey,
controller: eventController,
dayTitleBuilder: (thisDay){
return Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 10,bottom: 10),
child: Text(
"Upcoming Events",
style: TextStyle(
color: kGrey,
fontSize: 14,
fontWeight: FontWeight.w600
),
),
);
},
eventTileBuilder: (date, events, boundry, start, end) {
// CalendarEventData eventData = events[0];
return Padding(
padding: const EdgeInsets.only(left: 10),
child: Container(
width: width,
padding: const EdgeInsets.all(10),
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: kOrange,
borderRadius: const BorderRadius.horizontal(left: Radius.circular(20)),
),
child: const Text(
"Data",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600
),
),
),
);
},
width: width,
timeLineWidth: 60,
backgroundColor: Colors.white,
showVerticalLine: false,
showLiveTimeLineInAllDays: true,
minDay: DateTime(2022,01,01),
maxDay: DateTime(2022,12,30),
initialDay: _focusedDay,
heightPerMinute: 1.0,
eventArranger: const SideEventArranger(),
onEventTap: (events, date) => print(events),
onDateLongPress: (date) => print(date),
onPageChange: (date,_)=> {
_onDaySelected(date, _focusedDay)
},
)
) :
ValueListenableBuilder<List<BolaEventData>>(
valueListenable: _selectedBolaEvents,
builder: (context, value, _) {
return Listview.builder(
itemCount: dayEvent.length,
return Container(
width: width*.1, child: Text("Data")
);
)
}
)
What I have : https://i.stack.imgur.com/jC8hX.gif
What I want : https://i.stack.imgur.com/CHEcy.gif
How can I achieve this ?

Related

Column: Trailing widget consumes entire tile width. Please use a sized widget, or consider replacing ListTile with a custom widget

Hello trying to learn flutter and found this great open source project, trying to get it to run locally and running into the above issue. I think the offending code is the Column within the ListTile, but can't figure out the exact issue or how to resolve, I tried adding a width/height and converting column to a container, but I don't think I got the syntax correct. Any insight is appreciated!
return StreamBuilder(
stream: usersRef.doc('$userId').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
DocumentSnapshot documentSnapshot = snapshot.data;
UserModel user = UserModel.fromJson(documentSnapshot.data());
return ListTile(
contentPadding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 5.0),
leading: Stack(
children: <Widget>[
CircleAvatar(
backgroundImage: CachedNetworkImageProvider(
'${user?.photoUrl}',
),
radius: 25.0,
),
Positioned(
bottom: 0.0,
right: 0.0,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(6.0),
),
height: 15,
width: 15,
child: Center(
child: Container(
decoration: BoxDecoration(
color: user?.isOnline ?? false
? Color(0xff00d72f)
: Colors.grey,
borderRadius: BorderRadius.circular(6),
),
height: 11,
width: 11,
),
),
),
),
],
),
title: Text(
'${user.username}',
maxLines: 1,
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
type == MessageType.IMAGE ? "IMAGE" : "$msg",
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
trailing: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
SizedBox(height: 10),
TextTime(
child: Text(
"${timeago.format(time.toDate())}",
style: TextStyle(
fontWeight: FontWeight.w300,
fontSize: 11,
),
),
),
SizedBox(height: 5),
buildCounter(context),
],
),
onTap: () {
Navigator.of(context, rootNavigator: true).push(
CupertinoPageRoute(
builder: (BuildContext context) {
return Conversation(
userId: userId,
chatId: chatId,
);
},
),
);
},
);
} else {
return SizedBox();
}
},
);

How to refresh a list widget data on a button click FLUTTER

My flutter app displays bookings for a space, and the data comes from a rest api.
The screen has a vertical and horizontal list view.
The horizontal list view contains 14 buttons, with witch the user can decide what days bookings does he want to display on the vertical list view. The problem that I have is I cant refresh the vertical list views state with the button clicks to display the correct day.
Here is where I am currently:
The vertical List View:
Widget bookingListView(List data, BuildContext context) {
if (data.isNotEmpty) {
return Container(
key: UniqueKey(),
child: Scrollbar(
showTrackOnHover: true,
isAlwaysShown: true,
controller: _horizontalScrollController,
radius: Radius.circular(32),
thickness: 5.0,
child: SingleChildScrollView(
child: ListView.builder(
scrollDirection: Axis.vertical,
controller: _horizontalScrollController,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.only(left: 8.0, right: 6.0),
itemCount: data.length,
itemBuilder: (context, int index) {
Bookings booking = data[index];
String fromDate = booking.from;
String toDate = booking.to;
DateFormat inputFormat = DateFormat('yyyy/MM/dd HH:mm:ss Z');
DateTime fromD = inputFormat.parse(fromDate)
.toUtc()
.add(new Duration(hours: 2));
DateTime toD = inputFormat.parse(toDate).toUtc().add(
new Duration(hours: 2));
final frmDt = fromD.toLocal();
final toDt = toD.toLocal();
String from = DateFormat('HH:mm').format(frmDt);
String to = DateFormat('HH:mm').format(toDt);
return Column(
children: [
Padding(
padding: const EdgeInsets.only(left: 22),
child: ListTile(
title: Row(children: [
Text(
"$from",
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 48.0,
color: Color(0xfff2f2f2)),
),
Padding(
padding: const EdgeInsets.only(
left: 6.0, right: 6.0),
child: Text(
"-",
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 48.0,
color: Color(0xfff2f2f2)),
),
),
Text(
"$to",
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 48.0,
color: Color(0xfff2f2f2)),
),
]),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment
.start,
children: [
Padding(
padding: const EdgeInsets.only(
top: 6.0),
child: Text(
booking.membership.name == null
? ""
: booking.membership.name,
style: TextStyle(
fontSize: booking.membership.name == null
? 0
: 40.0,
fontWeight: FontWeight.w300,
color: Color(0xfff2f2f2)),
),
),
Padding(
padding: const EdgeInsets.only(
top: 6.0),
child: Text(
booking.title == null
? ""
: booking.title ,
style: TextStyle(
fontSize:
booking.title == null
? 0
: 40.0,
fontWeight: FontWeight.w300,
color: Color(0xfff2f2f2)),
),
),
],
),
),
),
Divider(
color: Colors.white,
indent: 10.0,
endIndent: 10.0,
thickness: 0.2,
)
],
);
}),
),
),
);
} else if (data.isEmpty) {
return Container(
child: Center(
heightFactor: 7,
child: Text(
"noBooking".tr().toString(),
style: TextStyle(
fontSize: 46.0,
fontWeight: FontWeight.w300,
color: Colors.white),
),
),
);
}
return Center(child: CircularProgressIndicator());
}
And the horizontal List View:
Padding(
padding: const EdgeInsets.all(8.0),
child: FittedBox(
fit: BoxFit.fitHeight,
child: OutlinedButton(
onPressed: () async {
var from =
"${formatFrom.format(DateTime.now())}";
var to =
"${formatTo.format(DateTime.now())} 23:59";
String fromDate = from.toString();
String toDate = to.toString();
final SharedPreferences
sharedPreferences =
await SharedPreferences.getInstance();
sharedPreferences.setString(
"from", fromDate);
sharedPreferences.setString("to", toDate);
setState(() {
selectedIndex = 0;
var format = new DateFormat('MM/dd');
formattedDate =
format.format(DateTime.now());
print(selectedIndex);
Network.getBookings();
});
},
style: OutlinedButton.styleFrom(
padding: EdgeInsets.fromLTRB(
26.0, 20.0, 26.0, 20.0),
backgroundColor: selectedIndex == 0
? Color(0xfff78848)
: Color(0x66404142),
side: BorderSide(color: Colors.white)),
child: FittedBox(
fit: BoxFit.fitHeight,
child: Text(dayOne.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 22.0)),
),
),
),
),
The remaining 13 button does the same as this one, just with different from and to datetime values.
when you are adding new item to your list you have to locally add the item to you list like list.add(newItem) and then you have to call setState() which will rebuild your list and render the new item on your screen
Another solution : if you want to refreh the whole page then you can clear the previous list and toggle your loading variable and then call to your getDate() to get newly added data.
with inserting data to list will be refresed.
setState(() {
list.add(newItem); // or list.insert() can be used.
});
Otherwise, you can use button's onTap:/onPressed: with setState(() {}).
As like:
InkWell(
onTap: () => setState(() {}),
child: // widget what you want
),

Why is selected value not reflecting in showModalBottomSheet with flutter?

First of all, I created a designed bottom sheet, In which, there are two lists to show numbers(left side) and options(hour, day, week, month) with the help of CupertinoPicker widget,
Numbers will depend on what option I select, If I select the hour, numbers of the left side should be 1-24, and if I select week, numbers should be 1-4, I select the day, numbers should be 1-30 and last I select month number should be 1-12.
Code :
All Lists variable:
List<String> reminderDay = ['hour','day','week','month'];
List<String> reminderHoursVal =['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24'];
List<String> reminderDaysVal =['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'];
List<String> reminderMonthsVal =['1','2','3','4','5','6','7','8','9','10','11','12'];
List<String> reminderWeeksVal =['1','2','3','4'];
String selectedReminderVal='1';
String selectedReminderDay ='hour';
Code of bottom sheet:
addReminder(){
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return AnimatedPadding(
padding: MediaQuery.of(context).viewInsets,
duration: const Duration(milliseconds: 100),
curve: Curves.decelerate,
child: Container(
padding: const EdgeInsets.only(top:8,right: 8, left:8,bottom: 8),
height: MediaQuery.of(context).size.height/2,
// color: Colors.transparent,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30)
)
),
child: Container(
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height:10),
Text("Set a reminder",
style: TextStyle(
fontSize:18,
fontWeight:FontWeight.bold,
color: Colors.grey
),
),
SizedBox(height:20),
Container(
margin: const EdgeInsets.only(left: 10, right: 10),
height: MediaQuery.of(context).size.height/4,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(10)
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: CupertinoPicker(
scrollController: new FixedExtentScrollController(
initialItem: 0,
),
itemExtent: 30,
backgroundColor: Colors.grey[100],
onSelectedItemChanged: (int val) {
setState(() {
if(selectedReminderDay=='day'){
selectedReminderVal = reminderDaysVal[val];
}else if(selectedReminderDay=='week'){
selectedReminderVal = reminderWeeksVal[val];
}else if(selectedReminderDay=='month'){
selectedReminderVal = reminderMonthsVal[val];
}else{
selectedReminderVal = reminderHoursVal[val];
}
print("selectedReminderVal:$selectedReminderVal");
});
},
children:selectedReminderDay=='day'?reminderDaysVal
:selectedReminderDay=='week'?reminderWeeksVal
:selectedReminderDay=='month'?reminderMonthsVal:reminderHoursVal// ['hour','day','week','month']; reminderHoursVal
.map(
(item) => Center(
child: Text(
item,
style: TextStyle(
fontSize: 16,
// fontWeight:FontWeight.bold,
),
),
),
)
.toList()),
),
Expanded(
child: CupertinoPicker(
scrollController: new FixedExtentScrollController(
initialItem: 0,
),
itemExtent: 30,
backgroundColor: Colors.grey[100],
onSelectedItemChanged: (int val) {
setState(() {
selectedReminderDay = reminderDay[val];
print("selectedReminderDay:$selectedReminderDay");
});
},
children: reminderDay
.map(
(item) => Center(
child: Text(
item,
style: TextStyle(
fontSize: 16,
// fontWeight:FontWeight.bold,
),
),
),
)
.toList()),
),
])
),
SizedBox(height:15),
// selectedVal!=null?Text(selectedVal.toString()):Container()
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("You'll get the reminder"),
Text('$selectedReminderVal $selectedReminderDay before the event')
],
),
SizedBox(height:25),
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: (){
Navigator.pop(context);
},
child: Text("Cancel",
style: TextStyle(
fontSize: 18,
color: Colors.blue,
fontWeight: FontWeight.bold
),
),
),
InkWell(
onTap: (){
Navigator.pop(context);
},
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(8)
),
width: MediaQuery.of(context).size.width/5,
height: MediaQuery.of(context).size.height/25 ,
child: Text("Save", style:TextStyle(
color: Colors.white,
fontSize: 19
)),
),
)
],
),
)
],
),
)
),
);
},
);
}
Screenshot:
This is because the state you are setting is different from the state in the modal bottom sheet.
Right now, when you are calling setState, you are actually rebuilding the stateful widget under the modal bottom sheet.
To fix this, just wrap your bottom sheet in a Stateful Builder.
StatefulBuilder(
builder: (context, setState) {
return AnimatedPadding(
padding: MediaQuery.of(context).viewInsets,
duration: const Duration(milliseconds: 100),
curve: Curves.decelerate,
child: Container(
padding: const EdgeInsets.only(top:8,right: 8, left:8,bottom: 8),
height: MediaQuery.of(context).size.height/2,
// color: Colors.transparent,
decoration: BoxDecoration(
color: Colors.white,
....
when we create new context widgets in existing state there states become different, bottomSheets are similar to dialogBox with new context and builder build a completely new widget out of the parent state, to create its own stateful state Wrap it with the stateful builder and user its own setState to change anything in this context not the parent one
eg:
StatefulBuilder(
builder: (context, setStateChild) {
return AnimatedPadding(...
Expanded(
child: CupertinoPicker(
scrollController: new FixedExtentScrollController(
initialItem: 0,
),
itemExtent: 30,
backgroundColor: Colors.grey[100],
onSelectedItemChanged: (int val) {
setStateChild(() {
selectedReminderDay = reminderDay[val];
print("selectedReminderDay:$selectedReminderDay");
});
},);
child: ... ),
}

Flutter, calculated Double do not work for circularprogress bar

I want to calculate the Percentage for the different Circularprogressbars with data from my Firestore Database. But when i use the calculated Doubles instead of hardcoded doubles i get this error and i can not explain my self why iam getting this error in the Terminal:
|
The getter 'weekActivity' was called on null.
Receiver: null
Tried calling: weekActivity
|
Can someone help me to fix this error?
Error Message
import 'dart:core';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_circular_chart/flutter_circular_chart.dart';
import 'package:testapp/models/Goals.dart';
import 'package:testapp/services/Services.dart';
class ReadingPage extends StatefulWidget {
final Goal goal;
const ReadingPage({Key key, this.goal}) : super(key: key);
#override
_ReadingPageState createState() => _ReadingPageState();
}
class _ReadingPageState extends State<ReadingPage> {
int _currentValue = 1;
//weeklyGoals
bool weekActivityFinished = false;
bool weekReadTimeFinished = false;
#override
Widget build(BuildContext context) {
final _chartSize = const Size(145, 145);
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: PreferredSize(
preferredSize: Size.fromHeight(35),
child: AppBar(
title: Align(
alignment: Alignment.center,
child: Text('Reading', style: TextStyle(
fontWeight: FontWeight.w500,
color: Colors.grey[900],
fontSize: 25,
decoration: TextDecoration.underline,
decorationColor: Color(0XFF006699),
decorationThickness: 1.5,
),),
),
backgroundColor: Colors.white,
),
),
body: Container(
margin: EdgeInsets.symmetric(vertical: 0),
height: 260.0,
child: StreamBuilder(
stream: FirestoreService().getGoals(),
builder: (BuildContext context,
AsyncSnapshot<List<Goal>> snapshot) {
if (snapshot.hasError || !snapshot.hasData)
return Center(child: CircularProgressIndicator(
backgroundColor: Color(0XFF1954A1),
));
return SizedBox(
height: 250,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
Goal goal = snapshot.data[index];
return Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(
top: 5, bottom: 10, left: 30, right: 30),
child: Container(
width: 330.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20.0)),boxShadow: [
BoxShadow(
color: Colors.grey[500],
offset: const Offset(0.5, 1),
blurRadius: 5.0,
spreadRadius: 0.1,
),
]),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 20),
width: 240,
child: Align(
alignment: Alignment.topLeft,
child: Container(
child: Text(
'WeeklyGoals', style: TextStyle(
fontSize: 25,
),),
),
),
),
Align(
alignment: Alignment.topRight,
child: Container(
padding: EdgeInsets.only(top: 5,right: 0, left: 0,
bottom: 0),
child: FlatButton(
child: Text('edit', style: TextStyle(
fontSize: 16,
color: Colors.yellow[700]
),),
onPressed: () {}
)
),
)
],
),
Row(
children: <Widget>[
Container(
width: 160,
margin: EdgeInsets.only(right: 10),
child: Column(
children: <Widget>[
Text('Activity', style: TextStyle(
fontSize: 18
),),
Center(
child: new AnimatedCircularChart(
size: _chartSize,
initialChartData: <
CircularStackEntry>[
new CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(
_weekActivityProgress(),
weekActivityFinished
? Colors
.yellow[700]
: Color(
0XFF006699),
rankKey: 'completed',
),
new CircularSegmentEntry(
100,
Colors.grey[300],
rankKey: 'remaining',
),
],
rankKey: 'progress',
),
],
chartType: CircularChartType
.Radial,
percentageValues: true,
holeLabel: '${goal
.weekActivity != null
? goal.weekActivity
: '-'}/${goal
.weekActivityGoal != null
? goal.weekActivityGoal
: '-'}',
labelStyle: new TextStyle(
color: Colors.blueGrey[600],
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
),
),
],
),
),
Container(
width: 160,
child: Column(
children: <Widget>[
Text('Time', style: TextStyle(
fontSize: 18
),),
Center(
child: new AnimatedCircularChart(
size: _chartSize,
initialChartData: <
CircularStackEntry>[
new CircularStackEntry(
<CircularSegmentEntry>[
new CircularSegmentEntry(
_weekReadingProgress(),
weekReadTimeFinished
? Colors
.yellow[700]
: Color(
0XFF006699),
rankKey: 'completed',
),
new CircularSegmentEntry(
100,
Colors.grey[300],
rankKey: 'remaining',
),
],
rankKey: 'progress',
),
],
chartType: CircularChartType
.Radial,
percentageValues: true,
holeLabel: '${goal
.weekReadTime != null
? goal.weekReadTime
.toStringAsFixed(2)
: '-'} / ${goal
.weekReadTimeGoal != null
? goal.weekReadTimeGoal
: '-'}',
labelStyle: new TextStyle(
color: Colors.blueGrey[600],
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
),
),
],
),
),
],
),
],
),
),
),
]);
}),
);
})));
}
//week
double _weekReadingProgress(){
var _weekReadingProgress = widget.goal.weekReadTime != null? widget.goal.weekReadTimeGoal : 0 *100 ~/
widget.goal.weekReadTimeGoal;
if(widget.goal.weekReadTime.toInt() >= widget.goal.weekReadTimeGoal){
setState(() {
weekReadTimeFinished = true;
});}
return _weekReadingProgress.toDouble();
}
double _weekActivityProgress(){
var _weekActivityProgress = widget.goal.weekActivity != null? widget.goal.weekActivity : 0 *100 ~/
widget.goal.weekActivityGoal;
if(widget.goal.weekActivity >= widget.goal.weekActivityGoal){
setState(() {
weekReadTimeFinished = true;
});}
return _weekActivityProgress.toDouble();
}}
The variable goal is null at one of places where you use goal.weekActivity.
At all places where you use goal.weekActivity, first ensure goal != null. Since it comes from Firestore, it's possible that there are no goals in the database when this error occurs. If you try this and find that it is always null, you should make sure it exists in the database.

How to navigate to another page but show information according to the items on my list that was pressed?

I'm trying to create my first app with flutter, it's a basic app to show items on a list and you tap on them to get the information. I've created the list and the contact page, I can navigate from one page to the other but I'm stuck now on how to make flutter show the information according to the contact I choose on the list, so I dont need to write one class for each contact. Is there a way to do it?
import 'package:flutter/material.dart';
import 'package:whatsapp_casimiro/contacts/contact_page.dart';
import 'package:whatsapp_casimiro/listas/lanchonetes.dart';
class LanchonetesScreen extends StatelessWidget {
final List<Lanchonetes> _allLanchonetes =
Lanchonetes.allLanchonetes();
#override
Widget build(BuildContext context) {
return Scaffold(body: getLanchonetesPageBody(context));
}
getLanchonetesPageBody(BuildContext context) {
return ListView.builder(
itemCount: _allLanchonetes.length,
itemBuilder: _getItemUI,
);
}
Widget _getItemUI(BuildContext context, index) {
return Column(children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 20.0),
child: Divider(
color: Colors.black,
indent: 80.0,
height: 8.0,
),
),
ListTile(
contentPadding: EdgeInsets.fromLTRB(15.0, 10.0, 10.0, 10.0),
leading: Container(
width: 55.0,
height: 60.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
"images/" + _allLanchonetes[index].img)),
),
),
title: Text(
_allLanchonetes[index].name,
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
),
onTap: () {
_onLanchonetesButtonPressed(context);
},
)
]);
}
}
void _onLanchonetesButtonPressed(BuildContext context) {
Navigator.push(
context, MaterialPageRoute(builder: (context) => ContactPage()));
}
class Lanchonetes {
final String name;
final String img;
Lanchonetes({this.name, this.img});
static List<Lanchonetes> allLanchonetes() {
var listOfLanchonetes = List<Lanchonetes>();
listOfLanchonetes.add(
Lanchonetes(name: "Esquina do Açaí",
img: "esquina_do_acai.jpg"));
listOfLanchonetes.add(
Lanchonetes(name: "Lanchonete Água na boca",
img: "esquina_do_acai.jpg"));
listOfLanchonetes.add(
Lanchonetes(name: "Kídelicia", img: "esquina_do_acai.jpg"));
listOfLanchonetes.add(
Lanchonetes(name: "Godinho Lanches", img: "godinho.jpeg" ));
return listOfLanchonetes;
}
}
import 'package:flutter/material.dart';
class ContactPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.blueGrey[100],
body: ListView(children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
child: Stack(children: <Widget>[
Image.asset("images/esquina_do_acai.jpg"),
Container(
height: 420.0,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: FractionalOffset.center,
end: FractionalOffset.bottomCenter,
colors: [
Colors.grey.withOpacity(0.0),
Colors.black,
])
),
),
Positioned(
bottom: 10.0,
left: 15.0,
child: Text(
"Esquina do Açaí",
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.normal,
color: Colors.white),
),
)
]
),
)
],
),
Padding(
padding: EdgeInsets.only(top: 5.0),
child: GestureDetector(
child: Card(
elevation: 1.0,
child: Container(
height: 100.0,
color: Colors.white,
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 30.0, horizontal: 15.0),
child: Text(
"Cardápio",
style: TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.bold),
),
),
),
),
onTap: () {},
),
),
Card(
elevation: 1.0,
child: Container(
height: 100.0,
color: Colors.white,
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 30.0, horizontal: 15.0),
child: Text(
"Pedir",
style: TextStyle(
fontSize: 30.0, fontWeight:
FontWeight.bold),
),
)))
])));
}
}
In your Navigation function you can pass one object
on your onTap you should pass your object like this in navigation function
onTap: () {
_onLanchonetesButtonPressed(context, _allLanchonetes[index]);
}
and receive it at function and pass it to new page
void _onLanchonetesButtonPressed(BuildContext context,Lanchonetes lanchonetes) {
Navigator.push(
context, MaterialPageRoute(builder: (context) => ContactPage(lanchonetes)));
}
on new page create constructor
class ContactPage extends StatelessWidget {
Lanchonetes lanchonetes;
ContactPage({this.lanchonetes});
//
Your code
//
}
with this you can use your lanchonetes object in new page