Browse Source

时间选择器更改

wr_2023_business
wurong 2 years ago
parent
commit
568004e8cb
  1. 74
      lib/business_system/date_select/custom_page.dart
  2. 39
      lib/business_system/date_select/day_report_page.dart
  3. 52
      lib/business_system/date_select/monthly_report_page.dart
  4. 74
      lib/business_system/date_select/week_report_page.dart
  5. 69
      lib/business_system/home/overview/trade_summary.dart
  6. 3
      lib/main.dart
  7. 2
      lib/retrofit/retrofit_api.g.dart
  8. 2
      pubspec.yaml

74
lib/business_system/date_select/custom_page.dart

@ -0,0 +1,74 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
import '../../view_widget/my_appbar.dart';
class CustomPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _CustomPage();
}
}
class _CustomPage extends State<CustomPage>{
String customDate = '';
String endCustomDate = '';
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
setState(() {
if (args.value is PickerDateRange) {
customDate =
DateFormat('yyyy年MM月dd日').format(args.value.startDate).toString() +
'' +
DateFormat('yyyy年MM月dd日')
.format(args.value.endDate ?? args.value.startDate)
.toString();
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(
title: "时间选择",
titleColor: Colors.black,
leadingColor: Colors.black,
background: Colors.white,
actions: [
TextButton(
onPressed: () {
Navigator.pop(context, customDate,);
},
child: Text(
"确定",
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
),
],
),
body: Stack(
children: <Widget>[
Positioned(
left: 0,
top: 0,
right: 0,
bottom: 0,
child: SfDateRangePicker(
onSelectionChanged: _onSelectionChanged,
selectionMode: DateRangePickerSelectionMode.range,
initialSelectedRange: PickerDateRange(
DateTime.now().subtract(const Duration(days: 4)),
DateTime.now().add(const Duration(days: 3))),
),
)
],
));
}
}

39
lib/business_system/date_select/day_report_page.dart

@ -15,9 +15,7 @@ class DayReportPage extends StatefulWidget {
class _DayReportPage extends State<DayReportPage>{ class _DayReportPage extends State<DayReportPage>{
String _selectedDate = ''; String _selectedDate = '';
String _dateCount = '';
String _range = ''; String _range = '';
String _rangeCount = '';
@override @override
void initState() { void initState() {
@ -34,11 +32,7 @@ class _DayReportPage extends State<DayReportPage>{
.format(args.value.endDate ?? args.value.startDate) .format(args.value.endDate ?? args.value.startDate)
.toString(); .toString();
} else if (args.value is DateTime) { } else if (args.value is DateTime) {
_selectedDate = args.value.toString(); _selectedDate = args.value.toString().substring(0,10);
} else if (args.value is List<DateTime>) {
_dateCount = args.value.length.toString();
} else {
_rangeCount = args.value.length.toString();
} }
}); });
} }
@ -51,29 +45,26 @@ class _DayReportPage extends State<DayReportPage>{
titleColor: Colors.black, titleColor: Colors.black,
leadingColor: Colors.black, leadingColor: Colors.black,
background: Colors.white, background: Colors.white,
actions: [
TextButton(
onPressed: () {
Navigator.pop(context, _selectedDate);
},
child: Text(
"确定",
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
),
],
), ),
body: Stack( body: Stack(
children: <Widget>[ children: <Widget>[
Positioned( Positioned(
left: 0, left: 0,
right: 0,
top: 0, top: 0,
height: 80,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Selected date: ' + _selectedDate),
Text('Selected date count: ' + _dateCount),
Text('Selected range: ' + _range),
Text('Selected ranges count: ' + _rangeCount)
],
),
),
Positioned(
left: 0,
top: 80,
right: 0, right: 0,
bottom: 0, bottom: 0,
child: SfDateRangePicker( child: SfDateRangePicker(

52
lib/business_system/date_select/monthly_report_page.dart

@ -14,26 +14,13 @@ class MonthlyReportPage extends StatefulWidget {
} }
class _MonthlyReportPage extends State<MonthlyReportPage>{ class _MonthlyReportPage extends State<MonthlyReportPage>{
String _selectedDate = ''; String _monthlyDate = '';
String _dateCount = ''; final DateRangePickerController _controller = DateRangePickerController();
String _range = '';
String _rangeCount = '';
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
setState(() { setState(() {
if (args.value is PickerDateRange) { if (args.value is DateTime) {
_range = _monthlyDate = args.value.toString().substring(0,10);
DateFormat('dd/MM/yyyy').format(args.value.startDate).toString() +
' - ' +
DateFormat('dd/MM/yyyy')
.format(args.value.endDate ?? args.value.startDate)
.toString();
} else if (args.value is DateTime) {
_selectedDate = args.value.toString();
} else if (args.value is List<DateTime>) {
_dateCount = args.value.length.toString();
} else {
_rangeCount = args.value.length.toString();
} }
}); });
} }
@ -46,6 +33,20 @@ class _MonthlyReportPage extends State<MonthlyReportPage>{
titleColor: Colors.black, titleColor: Colors.black,
leadingColor: Colors.black, leadingColor: Colors.black,
background: Colors.white, background: Colors.white,
actions: [
TextButton(
onPressed: () {
Navigator.pop(context, _monthlyDate);
},
child: Text(
"确定",
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
),
],
), ),
body: Stack( body: Stack(
children: <Widget>[ children: <Widget>[
@ -59,10 +60,7 @@ class _MonthlyReportPage extends State<MonthlyReportPage>{
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text('Selected date: ' + _selectedDate), Text('Selected date: ' + _monthlyDate),
Text('Selected date count: ' + _dateCount),
Text('Selected range: ' + _range),
Text('Selected ranges count: ' + _rangeCount)
], ],
), ),
), ),
@ -73,11 +71,13 @@ class _MonthlyReportPage extends State<MonthlyReportPage>{
bottom: 0, bottom: 0,
child: SfDateRangePicker( child: SfDateRangePicker(
onSelectionChanged: _onSelectionChanged, onSelectionChanged: _onSelectionChanged,
selectionMode: DateRangePickerSelectionMode.range, selectionMode: DateRangePickerSelectionMode.single,
selectionShape: DateRangePickerSelectionShape.rectangle, // selectionShape: DateRangePickerSelectionShape.rectangle,
initialSelectedRange: PickerDateRange( // initialSelectedRange: PickerDateRange(
DateTime.now().subtract(const Duration(days: 4)), // DateTime.now().subtract(const Duration(days: 4)),
DateTime.now().add(const Duration(days: 3))), // DateTime.now().add(const Duration(days: 3))),
view: DateRangePickerView.year,
controller: _controller,
), ),
) )
], ],

74
lib/business_system/date_select/week_report_page.dart

@ -14,26 +14,32 @@ class WeekReportPage extends StatefulWidget {
} }
class _WeekReportPage extends State<WeekReportPage>{ class _WeekReportPage extends State<WeekReportPage>{
String _selectedDate = '';
String _dateCount = '';
String _range = ''; String _range = '';
String _rangeCount = ''; String _endRange = '';
final DateRangePickerController _controller = DateRangePickerController();
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
setState(() { setState(() {
if (args.value is PickerDateRange) { if (args.value is PickerDateRange) {
_range = final startDate = args.value.startDate;
DateFormat('dd/MM/yyyy').format(args.value.startDate).toString() + final endDate = args.value.endDate;
' - ' + if (endDate.difference(startDate).inDays > 6) {
DateFormat('dd/MM/yyyy') _controller.selectedRange = PickerDateRange(
startDate.add(Duration(days: 6)),
endDate,
);
} else {
_range = DateFormat('yyyy年MM月dd日').format(args.value.startDate).toString() +
'' +
DateFormat('yyyy年MM月dd日')
.format(args.value.endDate ?? args.value.startDate)
.toString();
_endRange = DateFormat('yyyy年MM月dd日').format(args.value.startDate).toString() +
'' +
DateFormat('yyyy年MM月dd日')
.format(args.value.endDate ?? args.value.startDate) .format(args.value.endDate ?? args.value.startDate)
.toString(); .toString();
} else if (args.value is DateTime) { }
_selectedDate = args.value.toString();
} else if (args.value is List<DateTime>) {
_dateCount = args.value.length.toString();
} else {
_rangeCount = args.value.length.toString();
} }
}); });
} }
@ -46,39 +52,37 @@ class _WeekReportPage extends State<WeekReportPage>{
titleColor: Colors.black, titleColor: Colors.black,
leadingColor: Colors.black, leadingColor: Colors.black,
background: Colors.white, background: Colors.white,
actions: [
TextButton(
onPressed: () {
Navigator.pop(context, _range,);
},
child: Text(
"确定",
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
),
],
), ),
body: Stack( body: Stack(
children: <Widget>[ children: <Widget>[
Positioned( Positioned(
left: 0, left: 0,
right: 0,
top: 0, top: 0,
height: 80,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Selected date: ' + _selectedDate),
Text('Selected date count: ' + _dateCount),
Text('Selected range: ' + _range),
Text('Selected ranges count: ' + _rangeCount)
],
),
),
Positioned(
left: 0,
top: 80,
right: 0, right: 0,
bottom: 0, bottom: 0,
child: SfDateRangePicker( child: SfDateRangePicker(
onSelectionChanged: _onSelectionChanged, onSelectionChanged: _onSelectionChanged,
minDate: DateTime.now().subtract(const Duration(days: 361)),
controller: _controller, //
maxDate: DateTime.now().add(Duration(days: 365)),
selectionMode: DateRangePickerSelectionMode.range, selectionMode: DateRangePickerSelectionMode.range,
startRangeSelectionColor:Color(0xFF30415B), startRangeSelectionColor: Color(0xFF30415B),
endRangeSelectionColor:Color(0xFF30415B), endRangeSelectionColor: Color(0xFF30415B),
initialSelectedRange: PickerDateRange( todayHighlightColor: Color(0xFF30415B),
DateTime.now().subtract(const Duration(days: 4)),
DateTime.now().add(const Duration(days: 3))),
), ),
) )
], ],

69
lib/business_system/home/overview/trade_summary.dart

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/my_footer.dart'; import 'package:huixiang/view_widget/my_footer.dart';
import 'package:intl/intl.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -25,6 +26,15 @@ class _TradeSummary extends State<TradeSummary> {
int operateSelect = 0; int operateSelect = 0;
int expensesSelect = 0; int expensesSelect = 0;
int dateIndex = 0; int dateIndex = 0;
String selectedDate = "";
String dayDate = "${DateTime.now().year}${ DateTime.now().month}${ DateTime.now().day}";
String weekDate ="";
String weekDateNum = "${DateTime.now().year}${ DateTime.now().month}${ DateTime.now().day}日 至 "
"${DateFormat("yyyy年MM月dd日").format(DateTime.parse(DateTime.now().add(Duration(days:6)).toString().substring(0,10)))}";
String monthlyDate ="";
String monthlyDateNum = "${DateTime.now().year}${ DateTime.now().month}";
String customDate ="";
String customDateNum = "${DateTime.now().year}${ DateTime.now().month}${ DateTime.now().day}";
List<LineChartSample2Data> lineChartSample2DataAmount = List<LineChartSample2Data> lineChartSample2DataAmount =
[LineChartSample2Data(0,40,"2023-03-09"), [LineChartSample2Data(0,40,"2023-03-09"),
LineChartSample2Data(1,10,"2023-03-10"), LineChartSample2Data(1,10,"2023-03-10"),
@ -200,20 +210,36 @@ class _TradeSummary extends State<TradeSummary> {
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: (){ onTap: (){
if(dateIndex == 0){ if(dateIndex == 0){
Navigator.of(context).pushNamed('/router/day_report_page'); Navigator.of(context).pushNamed('/router/day_report_page').then((value) {
setState((){
selectedDate = value;
});
});
} }
else if(dateIndex == 1){ else if(dateIndex == 1){
Navigator.of(context).pushNamed('/router/week_report_page'); Navigator.of(context).pushNamed('/router/week_report_page').then((value) {
setState((){
weekDate = value;
});
});
} }
else if(dateIndex == 2){ else if(dateIndex == 2){
Navigator.of(context).pushNamed('/router/monthly_report_page'); Navigator.of(context).pushNamed('/router/monthly_report_page').then((value) {
setState((){
monthlyDate = value;
});
});
} }
else if(dateIndex == 3){ else if(dateIndex == 3){
Navigator.of(context).pushNamed('/router/monthly_report_page'); Navigator.of(context).pushNamed('/router/custom_page').then((value){
setState((){
customDate = value;
});
});
} }
}, },
child: Container( child: Container(
width: 154.w, width: 194.w,
alignment: Alignment.center, alignment: Alignment.center,
padding: EdgeInsets.all(8), padding: EdgeInsets.all(8),
decoration: BoxDecoration( decoration: BoxDecoration(
@ -223,15 +249,17 @@ class _TradeSummary extends State<TradeSummary> {
margin: EdgeInsets.only(bottom:16.h), margin: EdgeInsets.only(bottom:16.h),
child: Row( child: Row(
children: [ children: [
Padding(padding: EdgeInsets.only(right: 20.w), Expanded(child:Container(
alignment: Alignment.center,
child: Text( child: Text(
"2023年06月01日(今日)", timeDate(),
style: TextStyle( style: TextStyle(
fontSize: 10.sp, fontSize: 10.sp,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
color: Colors.black, color: Colors.black,
), ),
),), ),
)),
Image.asset( Image.asset(
"assets/image/bs_calendar_logo.webp", "assets/image/bs_calendar_logo.webp",
width:15, width:15,
@ -265,6 +293,18 @@ class _TradeSummary extends State<TradeSummary> {
); );
} }
String timeDate(){
if(dateIndex == 0){
return (selectedDate == "" || selectedDate == null) ? "${dayDate}(今日)":"${DateFormat("yyyy年MM月dd日").format(DateTime.parse(selectedDate))}(今日)";
}
else if(dateIndex == 1){
return (weekDate == "" || weekDate == null) ? weekDateNum : weekDate;}
else if(dateIndex == 2){
return (monthlyDate == "" || monthlyDate == null) ? "${monthlyDateNum}(当月)":"${(DateFormat("yyyy年MM月dd日").format(DateTime.parse(monthlyDate)).substring(0,8))}(当月)";}
else if(dateIndex == 3){
return (customDate == "" || customDate == null) ? "${customDateNum}(今日)" : customDate;}
}
/// ///
Widget operateAnalysis(){ Widget operateAnalysis(){
return Column( return Column(
@ -495,17 +535,4 @@ class _TradeSummary extends State<TradeSummary> {
); );
} }
showAlertDialog() {
showCupertinoModalPopup(
context: context,
builder: (context) {
return MaterialApp(
title: 'CalendarDatePicker2 Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
localizationsDelegates: GlobalMaterialLocalizations.delegates,
home: MonthlyReportPage(),
);},);
}
} }

3
lib/main.dart

@ -85,6 +85,7 @@ import 'package:huixiang/web/web_turntable_activity.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'business_system/business_page.dart'; import 'business_system/business_page.dart';
import 'business_system/date_select/custom_page.dart';
import 'business_system/date_select/day_report_page.dart'; import 'business_system/date_select/day_report_page.dart';
import 'business_system/date_select/monthly_report_page.dart'; import 'business_system/date_select/monthly_report_page.dart';
import 'business_system/date_select/week_report_page.dart'; import 'business_system/date_select/week_report_page.dart';
@ -501,4 +502,6 @@ Map<String, WidgetBuilder> routers = <String, WidgetBuilder>{
WeekReportPage(), WeekReportPage(),
'/router/monthly_report_page': (context, {arguments}) => '/router/monthly_report_page': (context, {arguments}) =>
MonthlyReportPage(), MonthlyReportPage(),
'/router/custom_page': (context, {arguments}) =>
CustomPage(),
}; };

2
lib/retrofit/retrofit_api.g.dart

@ -1644,7 +1644,7 @@ class _ApiService implements ApiService {
data: _data); data: _data);
final value = BaseData<List<VipBenefitList>>.fromJson( final value = BaseData<List<VipBenefitList>>.fromJson(
_result.data, _result.data,
(json) => (json as List<dynamic>) (json) => ((json??"") == "")?null:(json as List<dynamic>)
.map<VipBenefitList>( .map<VipBenefitList>(
(i) => VipBenefitList.fromJson(i as Map<String, dynamic>)) (i) => VipBenefitList.fromJson(i as Map<String, dynamic>))
.toList()); .toList());

2
pubspec.yaml

@ -113,7 +113,7 @@ dependencies:
# 时间选择器 # 时间选择器
flutter_datetime_picker: ^1.5.1 flutter_datetime_picker: ^1.5.1
syncfusion_flutter_datepicker: ^19.2.44 syncfusion_flutter_datepicker: ^19.4.38
dev_dependencies: dev_dependencies:

Loading…
Cancel
Save