我有一个颤动的调度程序日历,我已经设法用数据库中的数据填充调度程序。我已将调度程序上的卡片设为可点击。每张卡片在数据库中都有一组数据。就像第一行填充第一张卡片一样,第二行填充第二行。我希望能够点击任何卡片并获取 id,然后重定向到 webview 以显示网页
+------+--------+---------------------+------------+
| ID |title | dose | urls |
+------+--------+---------------------+------------+
| 1001 | Texas | 1st | google.com |
| 1002 | Texas | 2nd |facebook.com|
| 1003 | Ohio | 1st | azure.com |
| 1004 | Ohio | 2nd | med.com |
| 1005 | Utah | 1st | tell.com |
| 1006 | Utah | 2nd | burger.com |
| 1007 | Utah | 3rd | whatif.com |
+------+--------+---------------------+------------+
这就是我所拥有的
我的功能是监听日历点击并尝试使用 id 重定向到网页
void onCalendarTapped(CalendarTapDetails calendarTapDetails) async{
if (calendarTapDetails.targetElement != CalendarElement.calendarCell &&
calendarTapDetails.targetElement != CalendarElement.appointment) {
print("the index is ");
calendarTapDetails.targetElement.index;
return;
}
SharedPreferences prefs = await SharedPreferences.getInstance();
var userid = prefs.getString('id');
var email = prefs.getString('email');
var gender = prefs.getString('gender');
// for (Schedule s in participantSchedules){
var scheular = await db.getSchedulesById(participantSchedules[0].id);
print(scheular);
print("the link is " + scheular.botUrl!+'&userId=$userid'+'&email=$email'+'&gender=$gender'+'&sendData=true');
Navigator.push(context,
MaterialPageRoute(builder: (context) => WebViewPage(scheular.botUrl!+'&userId=$userid'+'&email=$email'+'&gender=$gender'+'&sendData=true', scheular.title!)));
//}
}
我在日历上填充项目的功能
Future<void> init() async {
participantSchedules = await db.getScheduleByparticipantId(participantid!);
setState(() {
appointments = getMeetingDetails();
_events = DataSource(appointments);
});
}
我如何获得上表中没有的标题和其他一些字段
List<Meeting> getMeetingDetails() {
final List<Meeting> meetingCollection = <Meeting>[];
eventNameCollection = <String>[];
//display the titles here
for (Schedule s in participantSchedules) {
eventNameCollection.add(s.title!);
meetingCollection.add(Meeting(
from: DateTime.parse(s.windowStart!),
to: DateTime.parse(s.windowEnd!),
background: getCalendarTileColor(
DateTime.parse(s.windowStart!),
DateTime.parse(s.windowEnd!), null),
isAllDay: true,
eventName: s.title!,
startTimeZone: '',
endTimeZone: '',
description: '',
));
}
return meetingCollection;
}
如何获取卡上的 id 并将其传递给下面的查询,因为这仅在我希望它是动态的时才选择索引为 0 的值。使用 for 循环遍历所有项目并一次显示所有 url
var scheular = await db.getSchedulesById(participantSchedules[0].id);
以便我可以仅使用所选卡的详细信息填充我的推送路线?
Navigator.push(context,
MaterialPageRoute(builder: (context) => WebViewPage(scheular.botUrl!+'&userId=$userid'+'&email=$email'+'&gender=$gender'+'&sendData=true', scheular.title!)));
全班
//ignore: must_be_immutable
class WAFollowUps extends StatefulWidget {
const WAFollowUps(this.participantid, {Key? key}) : super(key: key);
final String? participantid;
@override
WAFollowUpsState createState() => WAFollowUpsState(this.participantid);
}
List<Color> _colorCollection = <Color>[];
List<String> _colorNames = <String>[];
int _selectedColorIndex = 0;
int _selectedCardIndex = 0;
int _selectedTimeZoneIndex = 0;
List<String> _timeZoneCollection = <String>[];
DataSource _events = DataSource(<Meeting>[]);
Meeting? _selectedAppointment;
late DateTime _startDate;
late TimeOfDay _startTime;
late DateTime _endDate;
late TimeOfDay _endTime;
bool _isAllDay = false;
String _subject = '';
String _notes = '';
class WAFollowUpsState extends State<WAFollowUps> {
List<WATransactionModel> transactionList = <WATransactionModel>[];
List<Schedule> participantSchedules = <Schedule>[];
//Schedule schedule;
CemDatabase db = CemDatabase.getInstance();
String? participantid;
//List<Schedules> participantsid = <Schedules>[];
WAFollowUpsState(this.participantid);
CalendarView _calendarView = CalendarView.schedule;
late List<String> eventNameCollection;
late List<Meeting> appointments;
@override
void initState() {
init();
_calendarView = CalendarView.schedule;
_selectedAppointment = null;
_selectedCardIndex = 0;
_selectedColorIndex = 0;
_selectedTimeZoneIndex = 0;
_subject = '';
_notes = '';
super.initState();
}
Future<void> init() async {
participantSchedules = await db.getScheduleByparticipantId(participantid!);
setState(() {
appointments = getMeetingDetails();
_events = DataSource(appointments);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: Padding(
padding: const EdgeInsets.fromLTRB(5, 0, 5, 5),
child: getEventCalendar(_calendarView, _events, onCalendarTapped)));
}
SfCalendar getEventCalendar(CalendarView _calendarView,
CalendarDataSource _calendarDataSource,
CalendarTapCallback calendarTapCallback) {
return SfCalendar(
view: _calendarView,
dataSource: _calendarDataSource,
onTap: calendarTapCallback,
initialDisplayDate: DateTime(DateTime
.now()
.year, DateTime
.now()
.month,
DateTime
.now()
.day, 0, 0, 0),
scheduleViewSettings: ScheduleViewSettings(
hideEmptyScheduleWeek: true,
monthHeaderSettings: MonthHeaderSettings(
height: 0,
),
),
// timeSlotViewSettings: TimeSlotViewSettings(
// minimumAppointmentDuration: const Duration(minutes: 60))
);
}
void onCalendarTapped(CalendarTapDetails calendarTapDetails, ) async{
if (calendarTapDetails.targetElement != CalendarElement.calendarCell &&
calendarTapDetails.targetElement != CalendarElement.appointment) {
return;
}
SharedPreferences prefs = await SharedPreferences.getInstance();
var userid = prefs.getString('id');
var email = prefs.getString('email');
var gender = prefs.getString('gender');
// for (Schedule s in participantSchedules){
var scheular = await db.getSchedulesById(participantSchedules[11].id);
print(scheular);
print("the link is " + scheular.botUrl!+'&userId=$userid'+'&email=$email'+'&gender=$gender'+'&sendData=true');
Navigator.push(context,
MaterialPageRoute(builder: (context) => WebViewPage(scheular.botUrl!+'&userId=$userid'+'&email=$email'+'&gender=$gender'+'&sendData=true', scheular.title!)));
// }
}
List<Meeting> getMeetingDetails() {
final List<Meeting> meetingCollection = <Meeting>[];
eventNameCollection = <String>[];
//display the titles here
for (Schedule s in participantSchedules) {
eventNameCollection.add(s.title!);
meetingCollection.add(Meeting(
from: DateTime.parse(s.windowStart!),
to: DateTime.parse(s.windowEnd!),
background: getCalendarTileColor(
DateTime.parse(s.windowStart!),
DateTime.parse(s.windowEnd!), null),
isAllDay: true,
eventid: s.id!,
eventName: s.title!,
startTimeZone: '',
endTimeZone: '',
description: '',
));
}
return meetingCollection;
}
Color getCalendarTileColor(DateTime begin, DateTime end,
DateTime? dateCompleted) {
final DateTime today = DateTime.now();
_colorCollection = <Color>[];
if (today.isBefore(begin)) { // not completed but window has not begun yet
return Color(0xFF636363);
} else if (today.isAfter(end) &&
dateCompleted == null) { // not completed and window expired
return Color(0xFFFF00FF);
} else if (today.isAfter(begin) && today.isBefore(end) &&
dateCompleted == null) { // not completed but still within window
return Color(0xFF3D4FB5);
} else if (today.isAfter(end) &&
dateCompleted!.isAfter(end)) { // completed after window ended
return Color(0xFFE47C73);
} else if (dateCompleted!.isAfter(begin) &&
dateCompleted.isBefore(end)) { // completed on time
return Color(0xFF0F8644);
}
return Colors.white;
}
}
class DataSource extends CalendarDataSource {
DataSource(List<Meeting> source) {
appointments = source;
}
@override
bool isAllDay(int index) => appointments![index].isAllDay;
@override
String getSubject(int index) => appointments![index].eventName;
@override
String getStartTimeZone(int index) => appointments![index].startTimeZone;
@override
String getNotes(int index) => appointments![index].description;
@override
String getEndTimeZone(int index) => appointments![index].endTimeZone;
@override
Color getColor(int index) => appointments![index].background;
@override
DateTime getStartTime(int index) => appointments![index].from;
@override
DateTime getEndTime(int index) => appointments![index].to;
}
class Meeting {
Meeting({required this.from,
required this.to,
this.eventid,
this.background = Colors.green,
this.isAllDay = false,
this.eventName = '',
this.startTimeZone = '',
this.endTimeZone = '',
this.description = ''});
final String eventName;
final DateTime from;
final DateTime to;
final Color background;
final bool isAllDay;
final String startTimeZone;
final String endTimeZone;
final String description;
final int? eventid;
}
class WebViewPage extends StatefulWidget {
final String url;
final String title;
WebViewPage(this.url, this.title);
@override
WebViewPageState createState() =>
WebViewPageState(this.url, this.title);
}
class WebViewPageState extends State<WebViewPage> {
final String url;
final String title;
WebViewPageState(this.url, this.title);
@override
void initState() {
super.initState();
// Enable hybrid composition.
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
title: Text(
this.title,
style: boldTextStyle(color: Colors.black, size: 20),
),
actions: <Widget>[
TextButton(
onPressed: () {},
child: Text('Finish'),
),
],
leading: Container(
margin: EdgeInsets.all(8),
decoration: boxDecorationWithRoundedCorners(
backgroundColor: context.cardColor,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.grey.withOpacity(0.2)),
),
child: Icon(Icons.arrow_back, color: Banking_blackColor),
).onTap(() {
finish(context);
}),
centerTitle: true,
elevation: 0.0,
systemOverlayStyle: SystemUiOverlayStyle.light,
),
body: Column(children: [
Expanded(
child: SafeArea(
child: WebView(
initialUrl: this.url,
javascriptMode: JavascriptMode.unrestricted,
debuggingEnabled: true,
),
)
)
])
),
);
}
}