Commit 1d07d5c6ea273ffdad3099ecf503f6fdffd24e14

Authored by wdn127929
1 parent 4403468a

日历和早餐、晚餐、午餐

... ... @@ -11,14 +11,14 @@ if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = "303"
def flutterVersionCode = "310"
if (flutterVersionCode == null) {
flutterVersionCode = '303'
flutterVersionCode = '310'
}
def flutterVersionName = "3.0.3"
def flutterVersionName = "3.1.0"
if (flutterVersionName == null) {
flutterVersionName = '3.0.3'
flutterVersionName = '3.1.0'
}
apply plugin: 'com.android.application'
... ...
... ... @@ -177,7 +177,6 @@ class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
debugShowCheckedModeBanner: false,
... ... @@ -191,7 +190,7 @@ class MyAppState extends State<MyApp> {
TextTheme(overline: TextStyle(decoration: TextDecoration.none)),
tooltipTheme: TooltipThemeData(verticalOffset: -100000)),
home: isLogin
? HomePage(initialIndex: 2)
? HomePage(initialIndex: 1)
: ChangeNotifierProvider<OtherLoginProvider>(
create: (_) => OtherLoginProvider(), child: LoginPage()),
onGenerateRoute: App.router.generator,
... ...
... ... @@ -6,21 +6,18 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_update/azhon_app_update.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/app.dart';
import 'package:one_key/pages/home_enter_order/home_enter_order.dart';
import 'package:one_key/pages/message/message_page.dart';
import 'package:one_key/pages/my/my_page.dart';
import 'package:one_key/pages/notebook/notebook_page.dart';
import 'package:one_key/pages/table/table_manager_page.dart';
import 'package:one_key/provider/contact_model.dart';
import 'package:one_key/provider/enter_model.dart';
import 'package:one_key/provider/home_enter_model.dart';
import 'package:one_key/provider/message_dialog_model.dart';
import 'package:one_key/provider/message_model.dart';
import 'package:one_key/provider/my_model.dart';
import 'package:one_key/provider/notebook_model.dart';
import 'package:one_key/provider/remark_manager_model.dart';
import 'package:one_key/provider/table_manager_model.dart';
import 'package:one_key/provider/tools.dart';
import 'package:one_key/provider/update_model.dart';
... ... @@ -38,7 +35,7 @@ import 'package:one_key/models/message.dart';
class HomePage extends StatefulWidget {
final int initialIndex; //初始tab
HomePage({this.initialIndex = 2});
HomePage({this.initialIndex = 1});
@override
State<StatefulWidget> createState() {
... ... @@ -49,7 +46,7 @@ class HomePage extends StatefulWidget {
class HomePageState extends State<HomePage> with WidgetsBindingObserver {
List<Widget> pages = List<Widget>();
int _currIndex = 2;
int _currIndex = 1;
Color _activeColor = MyColours.color_199095;
Color _defaultColor = MyColours.color_999999;
int numPush = 0; //推送消息个数
... ... @@ -75,12 +72,12 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
_currIndex = widget.initialIndex;
_pageController = PageController(initialPage: _currIndex);
pages
..add(ChangeNotifierProvider<HomeEnterModel>(
create: (_) => HomeEnterModel(),
child: ChangeNotifierProvider<RemarkManagerModel>(
create: (_) => RemarkManagerModel(),
child: SafeArea(child: HomeEnterPage()),
)))
// ..add(ChangeNotifierProvider<HomeEnterModel>(
// create: (_) => HomeEnterModel(),
// child: ChangeNotifierProvider<RemarkManagerModel>(
// create: (_) => RemarkManagerModel(),
// child: SafeArea(child: HomeEnterPage()),
// )))
..add(SafeArea(
child: MessagePage(),
))
... ... @@ -496,24 +493,24 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
selectedFontSize: ScreenUtil().setSp(22),
backgroundColor: MyColours.color_ffffff,
items: [
BottomNavigationBarItem(
icon: Image(
image: AssetImage("assets/enter_order_n.png"),
width: ScreenUtil().setWidth(48),
height: ScreenUtil().setWidth(48),
),
activeIcon: Image(
image: AssetImage("assets/enter_order_s.png"),
width: ScreenUtil().setWidth(48),
height: ScreenUtil().setWidth(48),
),
title: Text(
"录入预订",
style: TextStyle(
color: _currIndex == 0 ? _activeColor : _defaultColor,
fontSize: ScreenUtil().setSp(22)),
),
),
// BottomNavigationBarItem(
// icon: Image(
// image: AssetImage("assets/enter_order_n.png"),
// width: ScreenUtil().setWidth(48),
// height: ScreenUtil().setWidth(48),
// ),
// activeIcon: Image(
// image: AssetImage("assets/enter_order_s.png"),
// width: ScreenUtil().setWidth(48),
// height: ScreenUtil().setWidth(48),
// ),
// title: Text(
// "录入预订",
// style: TextStyle(
// color: _currIndex == 0 ? _activeColor : _defaultColor,
// fontSize: ScreenUtil().setSp(22)),
// ),
// ),
BottomNavigationBarItem(
icon: Stack(
children: [
... ... @@ -564,7 +561,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
title: Text(
"消息中心",
style: TextStyle(
color: _currIndex == 1 ? _activeColor : _defaultColor,
color: _currIndex == 0 ? _activeColor : _defaultColor,
fontSize: ScreenUtil().setSp(22)),
),
),
... ... @@ -600,7 +597,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
title: Text(
"已预订",
style: TextStyle(
color: _currIndex == 2 ? _activeColor : _defaultColor,
color: _currIndex == 1 ? _activeColor : _defaultColor,
fontSize: ScreenUtil().setSp(22)),
),
),
... ... @@ -618,7 +615,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
title: Text(
"桌位",
style: TextStyle(
color: _currIndex == 3 ? _activeColor : _defaultColor,
color: _currIndex == 2 ? _activeColor : _defaultColor,
fontSize: ScreenUtil().setSp(22)),
),
),
... ... @@ -636,7 +633,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
title: Text(
"我的",
style: TextStyle(
color: _currIndex == 4 ? _activeColor : _defaultColor,
color: _currIndex == 3 ? _activeColor : _defaultColor,
fontSize: ScreenUtil().setSp(22)),
),
),
... ... @@ -649,7 +646,7 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
_currIndex = index;
_pageController.jumpToPage(index);
});
if (_currIndex == 5) {
if (_currIndex == 3) {
Utils.changeStatusColor(color: MyColours.color_199095);
} else {
Utils.changeStatusColor(color: Colors.white);
... ...
... ... @@ -20,6 +20,8 @@ import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/app_bar.dart';
import 'package:one_key/widgets/area_item.dart';
import 'package:one_key/widgets/common_button.dart';
import 'package:one_key/widgets/common_button_flat.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/page_exception.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/table_item.dart';
... ... @@ -339,124 +341,167 @@ class TableManagerPageState extends State<TableManagerPage> {
Widget build(BuildContext context) {
return Consumer<TableManagerModel>(
builder: (context, model, child) {
int sum = 3;
int hide = 0;
int btnNum = 0;
if (tableManagerModel.morning == "00:00-00:00") {
hide++;
}
if (tableManagerModel.noon == "00:00-00:00") {
hide++;
}
if (tableManagerModel.night == "00:00-00:00") {
hide++;
}
btnNum = sum - hide;
return Column(
children: <Widget>[
SystemAppBar("桌位", showLeading: false),
Container(
color: MyColours.color_ffffff,
width: double.infinity,
padding:
EdgeInsets.symmetric(vertical: ScreenUtil().setHeight(16)),
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(15)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Center(
child: GestureDetector(
onTap: () {
DialogUtil.showCalendarDialog(
context, tableManagerModel.dateTime)
.then((day) {
if (day != null) {
tableManagerModel.createDateText(context, day);
}
});
},
child: Container(
child: Text(
tableManagerModel.dateText,
style: TextStyle(
color: MyColours.color_199095,
fontSize: ScreenUtil().setSp(34)),
),
),
),
),
),
MyDivider(
ScreenUtil().setWidth(2),
ScreenUtil().setHeight(68),
color: MyColours.color_E0E0E0,
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(30)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Offstage(
offstage:
tableManagerModel.morning == "00:00-00:00"
? true
: false,
child: Padding(
padding: EdgeInsets.only(
right: ScreenUtil().setWidth(18)),
child: CommonButton(
content: "早市",
state: tableManagerModel.currTimeIndex == 1
? 1
: 0,
width: 92,
height: 48,
fontSize: 32,
onPress: () {
if (tableManagerModel.currTimeIndex == 1)
return;
tableManagerModel.currTimeIndex = 1;
tableManagerModel.getReserveList(context);
},
))),
Offstage(
offstage: tableManagerModel.noon == "00:00-00:00"
onTap: () {
DialogUtil.showCalendarDialog(
context, tableManagerModel.dateTime)
.then((day) {
if (day != null) {
tableManagerModel.createDateText(context, day);
}
});
},
child: Container(
// height: ScreenUtil().setWidth(80),
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(15),
vertical: ScreenUtil().setWidth(20)),
decoration: BoxDecoration(
color: MyColours.color_199095,
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(20))),
child: Row(
children: [
Expanded(
child: Text(
tableManagerModel.dateText,
style: TextStyle(
color: MyColours.color_ffffff,
fontSize: ScreenUtil().setSp(28)),
)),
HEmptyView(10),
Image.asset(
Utils.getImgPath('f_arrow_right'),
width: ScreenUtil().setWidth(25),
// height: ScreenUtil().setWidth(10),
)
],
)),
)),
// MyDivider(
// ScreenUtil().setWidth(2),
// ScreenUtil().setHeight(68),
// color: MyColours.color_E0E0E0,
// ),
HEmptyView(20),
Container(
width: ScreenUtil().setWidth(206),
height: ScreenUtil().setWidth(74),
decoration: BoxDecoration(
color: Color.fromRGBO(232, 232, 232, 1),
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(20),
)),
child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Offstage(
offstage: tableManagerModel.morning == "00:00-00:00"
? true
: false,
child: CommonButtonFlat(
content: "早市",
state:
tableManagerModel.currTimeIndex == 1 ? 1 : 0,
fontSize: 28,
right: tableManagerModel.noon == "00:00-00:00" &&
tableManagerModel.night == "00:00-00:00"
? true
: false,
child: Padding(
padding: EdgeInsets.only(
right: ScreenUtil().setWidth(18)),
child: CommonButton(
content: "午市",
state: tableManagerModel.currTimeIndex == 2
? 1
: 0,
width: 92,
height: 48,
fontSize: 32,
onPress: () {
if (tableManagerModel.currTimeIndex == 2)
return;
tableManagerModel.currTimeIndex = 2;
tableManagerModel.getReserveList(context);
},
))),
Offstage(
offstage: tableManagerModel.night == "00:00-00:00"
width: ScreenUtil().setWidth(200) / btnNum,
onPress: () {
if (tableManagerModel.currTimeIndex == 1)
return;
tableManagerModel.currTimeIndex = 1;
tableManagerModel.getReserveList(context);
},
)),
btnNum == 3 && tableManagerModel.currTimeIndex == 3
? MyDivider(
ScreenUtil().setWidth(4),
ScreenUtil().setWidth(46),
color: MyColours.color_dfdfdf,
)
: SizedBox(),
Offstage(
offstage: tableManagerModel.noon == "00:00-00:00"
? true
: false,
child: Container(
// padding: EdgeInsets.symmetric(
// horizontal: ScreenUtil().setWidth(10)),
child: CommonButton(
content: "晚市",
child: CommonButtonFlat(
content: "午市",
state:
tableManagerModel.currTimeIndex == 3 ? 1 : 0,
width: 92,
height: 48,
fontSize: 32,
tableManagerModel.currTimeIndex == 2 ? 1 : 0,
fontSize: 28,
width: ScreenUtil().setWidth(200) / btnNum,
left: tableManagerModel.morning == "00:00-00:00"
? true
: false,
right: tableManagerModel.night == "00:00-00:00"
? true
: false,
onPress: () {
if (tableManagerModel.currTimeIndex == 3)
if (tableManagerModel.currTimeIndex == 2)
return;
tableManagerModel.currTimeIndex = 3;
tableManagerModel.currTimeIndex = 2;
tableManagerModel.getReserveList(context);
},
)),
),
],
),
btnNum == 3 && tableManagerModel.currTimeIndex == 1
? MyDivider(
ScreenUtil().setWidth(4),
ScreenUtil().setWidth(46),
color: MyColours.color_dfdfdf,
)
: SizedBox(),
Offstage(
offstage: tableManagerModel.night == "00:00-00:00"
? true
: false,
child: Container(
child: CommonButtonFlat(
content: "晚市",
left: tableManagerModel.morning == "00:00-00:00" &&
tableManagerModel.noon == "00:00-00:00"
? true
: false,
state: tableManagerModel.currTimeIndex == 3 ? 1 : 0,
fontSize: 28,
width: ScreenUtil().setWidth(200) / btnNum,
onPress: () {
if (tableManagerModel.currTimeIndex == 3) return;
tableManagerModel.currTimeIndex = 3;
tableManagerModel.getReserveList(context);
},
)),
),
],
),
)
),
],
),
),
... ...
... ... @@ -13,6 +13,7 @@ import 'package:one_key/net/http_url.dart';
import 'package:one_key/models/table.dart' as t;
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/lunar_calendar.dart';
import 'package:one_key/utils/utils.dart';
import 'package:provider/provider.dart';
... ... @@ -50,12 +51,7 @@ class TableManagerModel with ChangeNotifier {
initTime(BuildContext context) async {
userModel = Provider.of<UserModel>(context, listen: false);
dateTime = DateTime.now();
dateText = "${dateTime.year}年 " +
Utils.addZeroNumber(dateTime.month) +
"月" +
Utils.addZeroNumber(dateTime.day) +
"日" +
" 今天";
dateText = _returnDate(dateTime);
morning =
userModel.user.morning.isEmpty ? "00:00-00:00" : userModel.user.morning;
noon = userModel.user.noon.isEmpty ? "00:00-00:00" : userModel.user.noon;
... ... @@ -326,7 +322,7 @@ class TableManagerModel with ChangeNotifier {
"keywords": "",
"sort": "1"
};
if ( needLoading) {
if (needLoading) {
pageState = PageState.Loading;
notifyListeners();
}
... ... @@ -459,23 +455,34 @@ class TableManagerModel with ChangeNotifier {
//生成日期文本
createDateText(BuildContext context, DateTime day) {
if (Utils.isOneDay(day, dateTime)) return; //日期没变
dateText = _returnDate(day);
dateTime = day;
getReserveList(context);
}
_returnDate(DateTime day) {
String date = '';
DateTime dateNow = DateTime.now();
dateText = "${day.year}年 " +
String ymd = "${day.year}-" +
Utils.addZeroNumber(day.month) +
"月" +
Utils.addZeroNumber(day.day) +
"日";
"-" +
Utils.addZeroNumber(day.day);
if (Utils.isOneDay(day, dateNow)) {
dateText += " 今天";
date += "今天 ";
} else if (Utils.isOneDay(day, dateNow.add(Duration(days: 1)))) {
dateText += " 明天";
date += "明天 ";
} else if (Utils.isOneDay(day, dateNow.add(Duration(days: 2)))) {
dateText += " 后天";
} else {
dateText += " 周${Utils.formatWeekDayNum(day.weekday)}";
date += "后天 ";
}
dateTime = day;
getReserveList(context);
date += ymd;
date += " 星期${Utils.formatWeekDayNum(day.weekday)}";
LunarCalendar lunarCalendar = LunarCalendar(day);
String time =
'${lunarCalendar.getChinaMonthString()}月${LunarCalendar.getChinaDayString(lunarCalendar.day)}';
date += ' ${time}';
return date;
}
//获取桌位数据
... ...
... ... @@ -10,7 +10,6 @@ import 'package:flutter_picker/flutter_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/models/remark.dart';
import 'package:one_key/pages/home_enter_order/home_enter_order.dart';
import 'package:one_key/pages/message/message_dialog_item.dart';
import 'package:one_key/provider/message_dialog_model.dart';
import 'package:one_key/provider/table_manager_model.dart';
... ... @@ -33,6 +32,8 @@ import 'package:url_launcher/url_launcher.dart';
typedef CustomCallBack = void Function(Object object);
typedef CustomCallBackMap = void Function(Map<String, String> object);
typedef ClickCallback = void Function(String value);
class DialogUtil {
///添加图片UI弹出
static openImageModalBottomSheet(context,
... ...
import 'package:intl/intl.dart';
class LunarCalendar {
//农历年
int year;
int month;
int day;
bool leap;
///中文月名称
static List<String> chineseNumber = [
"一",
"二",
"三",
"四",
"五",
"六",
"七",
"八",
"九",
"十",
"十一",
"十二"
];
///中文日期格式
static DateFormat chineseDateFormat = new DateFormat("yyyy年MM月dd日");
///农历数据, 1901 ~ 2100 年之间正确
static List<int> lunarInfo = [
0x04bd8,
0x04ae0,
0x0a570,
0x054d5,
0x0d260,
0x0d950,
0x16554,
0x056a0,
0x09ad0,
0x055d2,
0x04ae0,
0x0a5b6,
0x0a4d0,
0x0d250,
0x1d255,
0x0b540,
0x0d6a0,
0x0ada2,
0x095b0,
0x14977,
0x04970,
0x0a4b0,
0x0b4b5,
0x06a50,
0x06d40,
0x1ab54,
0x02b60,
0x09570,
0x052f2,
0x04970,
0x06566,
0x0d4a0,
0x0ea50,
0x06e95,
0x05ad0,
0x02b60,
0x186e3,
0x092e0,
0x1c8d7,
0x0c950,
0x0d4a0,
0x1d8a6,
0x0b550,
0x056a0,
0x1a5b4,
0x025d0,
0x092d0,
0x0d2b2,
0x0a950,
0x0b557,
0x06ca0,
0x0b550,
0x15355,
0x04da0,
0x0a5d0,
0x14573,
0x052d0,
0x0a9a8,
0x0e950,
0x06aa0,
0x0aea6,
0x0ab50,
0x04b60,
0x0aae4,
0x0a570,
0x05260,
0x0f263,
0x0d950,
0x05b57,
0x056a0,
0x096d0,
0x04dd5,
0x04ad0,
0x0a4d0,
0x0d4d4,
0x0d250,
0x0d558,
0x0b540,
0x0b5a0,
0x195a6,
0x095b0,
0x049b0,
0x0a974,
0x0a4b0,
0x0b27a,
0x06a50,
0x06d40,
0x0af46,
0x0ab60,
0x09570,
0x04af5,
0x04970,
0x064b0,
0x074a3,
0x0ea50,
0x06b58,
0x055c0,
0x0ab60,
0x096d5,
0x092e0,
0x0c960,
0x0d954,
0x0d4a0,
0x0da50,
0x07552,
0x056a0,
0x0abb7,
0x025d0,
0x092d0,
0x0cab5,
0x0a950,
0x0b4a0,
0x0baa4,
0x0ad50,
0x055d9,
0x04ba0,
0x0a5b0,
0x15176,
0x052b0,
0x0a930,
0x07954,
0x06aa0,
0x0ad50,
0x05b52,
0x04b60,
0x0a6e6,
0x0a4e0,
0x0d260,
0x0ea65,
0x0d530,
0x05aa0,
0x076a3,
0x096d0,
0x04bd7,
0x04ad0,
0x0a4d0,
0x1d0b6,
0x0d250,
0x0d520,
0x0dd45,
0x0b5a0,
0x056d0,
0x055b2,
0x049b0,
0x0a577,
0x0a4b0,
0x0aa50,
0x1b255,
0x06d20,
0x0ada0
];
// 传回农历 y年的总天数
static int yearDays(int y) {
int i, sum = 348;
for (i = 0x8000; i > 0x8; i >>= 1) {
if ((lunarInfo[y - 1900] & i) != 0) sum += 1;
}
return (sum + leapDays(y));
}
// 传回农历 y年闰月的天数
static int leapDays(int y) {
if (leapMonthM(y) != 0) {
if ((lunarInfo[y - 1900] & 0x10000) != 0)
return 30;
else
return 29;
} else
return 0;
}
// 传回农历 y年闰哪个月 1-12 , 没闰传回 0
static int leapMonthM(int y) {
print('$y');
return (lunarInfo[y - 1900] & 0xf);
}
// 传回农历 y年m月的总天数
static int monthDays(int y, int m) {
if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
return 29;
else
return 30;
}
// 传回农历 y年的生肖
String animalsYear() {
final List<String> Animals = [
"鼠",
"牛",
"虎",
"兔",
"龙",
"蛇",
"马",
"羊",
"猴",
"鸡",
"狗",
"猪"
];
return Animals[(year - 4) % 12];
}
// 传入 月日的offset 传回干支, 0=甲子
static String cyclicalm(int num) {
final List<String> Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"];
final List<String> Zhi = [
"子",
"丑",
"寅",
"卯",
"辰",
"巳",
"午",
"未",
"申",
"酉",
"戌",
"亥"
];
return (Gan[num % 10] + Zhi[num % 12]);
}
// 传入 offset 传回干支, 0=甲子
String cyclical() {
int num = year - 1900 + 36;
return (cyclicalm(num));
}
static String getChinaDayString(int day) {
List<String> chineseTen = ["初", "十", "廿", "卅"];
int n = day % 10 == 0 ? 9 : day % 10 - 1;
if (day > 30) return "";
if (day == 10)
return "初十";
else
return chineseTen[day ~/ 10] + chineseNumber[n];
}
String getChinaMonthString() {
return chineseNumber[month - 1];
}
String toString() {
return "$year" +
"年" +
(leap ? "闰" : "") +
chineseNumber[month - 1] +
"月" +
getChinaDayString(day);
}
///使用指定日历日期构造一个农历日历
LunarCalendar(DateTime cal) {
int yearCyl, monCyl, dayCyl;
int leapMonth = 0;
DateTime baseDate = null;
try {
baseDate = chineseDateFormat.parse("1900年1月31日");
} catch (e) {}
// 求出和1900年1月31日相差的天数, 注意此处毫秒,除以86400000000
int offset =
((cal.microsecondsSinceEpoch - baseDate.microsecondsSinceEpoch) ~/
86400000000);
dayCyl = offset + 40;
monCyl = 14;
// 用offset减去每农历年的天数
// 计算当天是农历第几天
// i最终结果是农历的年份
// offset是当年的第几天
int iYear, daysOfYear = 0;
for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {
daysOfYear = yearDays(iYear);
offset -= daysOfYear;
monCyl += 12;
}
if (offset < 0) {
offset += daysOfYear;
iYear--;
monCyl -= 12;
}
// 农历年份
year = iYear;
yearCyl = iYear - 1864;
leapMonth = leapMonthM(iYear); // 闰哪个月,1-12
leap = false;
// 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
int iMonth, daysOfMonth = 0;
for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
// 闰月
if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
--iMonth;
leap = true;
daysOfMonth = leapDays(year);
} else
daysOfMonth = monthDays(year, iMonth);
offset -= daysOfMonth;
// 解除闰月
if (leap && iMonth == (leapMonth + 1)) leap = false;
if (!leap) monCyl++;
}
// offset为0时,并且刚才计算的月份是闰月,要校正
if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
if (leap) {
leap = false;
} else {
leap = true;
--iMonth;
--monCyl;
}
}
// offset小于0时,也要校正
if (offset < 0) {
offset += daysOfMonth;
--iMonth;
--monCyl;
}
month = iMonth;
day = offset + 1;
}
}
... ...
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';
class CommonButtonFlat extends StatelessWidget {
final VoidCallback onPress;
final String content;
final double width;
final double height;
final double fontSize;
final int state; //-1 不可用 0 默认 1 选中
final FontWeight fontWeight;
final bool left;
final bool right;
CommonButtonFlat(
{this.onPress,
this.content,
this.state = 0,
this.width = 250,
this.height = 50,
this.fontSize = 18,
this.fontWeight = FontWeight.normal,
this.left = true,
this.right = true});
@override
Widget build(BuildContext context) {
BoxDecoration boxDecoration;
Color fontColor;
switch (state) {
// case -1:
// boxDecoration = BoxDecoration(
// // color: MyColours.color_74BBBE,
// borderRadius: BorderRadius.only(
// topLeft: left
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// bottomLeft: left
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// topRight: right
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// bottomRight: right
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// ),
// );
// fontColor = MyColours.color_ffffff;
// break;
case 0:
boxDecoration = BoxDecoration(
color: Color.fromRGBO(232, 232, 232, 1),
// border: Border.all(
// color: MyColours.color_199095, width: ScreenUtil().setWidth(2)),
borderRadius: BorderRadius.only(
topLeft: left
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
bottomLeft: left
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
topRight: right
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
bottomRight: right
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
));
fontColor = MyColours.color_199095;
break;
case 1:
boxDecoration = BoxDecoration(
color: MyColours.color_199095,
// gradient: LinearGradient(
// colors: [Color(0xff199095), Color(0xff36C3C7)],
// begin: Alignment.topCenter,
// end: Alignment.bottomCenter),
borderRadius: BorderRadius.only(
topLeft: left
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
bottomLeft: left
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
topRight: right
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
bottomRight: right
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
));
fontColor = MyColours.color_fefefe;
break;
// case 2:
// boxDecoration = BoxDecoration(
// color: MyColours.color_199095,
// borderRadius: BorderRadius.only(
// topLeft: left
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// bottomLeft: left
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// topRight: right
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// bottomRight: right
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// ));
// fontColor = MyColours.color_fefefe;
// break;
// case -2:
// boxDecoration = BoxDecoration(
// color: Color.fromRGBO(232, 232, 232, 1),
// borderRadius: BorderRadius.only(
// topLeft: left
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// bottomLeft: left
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// topRight: right
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// bottomRight: right
// ? Radius.circular(ScreenUtil().setWidth(20))
// : Radius.circular(0),
// ));
// fontColor = MyColours.color_fefefe;
// break;
default:
boxDecoration = BoxDecoration(
border: Border.all(color: MyColours.color_199095),
borderRadius: BorderRadius.only(
topLeft: left
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
bottomLeft: left
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
topRight: right
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
bottomRight: right
? Radius.circular(ScreenUtil().setWidth(20))
: Radius.circular(0),
));
fontColor = MyColours.color_fefefe;
break;
break;
}
return Material(
child: Ink(
child: InkWell(
onTap: onPress,
child: Container(
width: width,
// height: ScreenUtil().setWidth(height),
decoration: boxDecoration,
child: Align(
alignment: Alignment.center,
child: Text(
content,
style: TextStyle(
color: fontColor,
fontWeight: fontWeight,
fontSize: ScreenUtil().setSp(fontSize)),
),
),
),
),
),
);
}
}
... ...