Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePickerWidget can't refresh data ? #13

Open
Qusdrok opened this issue Oct 19, 2020 · 1 comment
Open

DatePickerWidget can't refresh data ? #13

Qusdrok opened this issue Oct 19, 2020 · 1 comment

Comments

@Qusdrok
Copy link

Qusdrok commented Oct 19, 2020

i'm using StreamBuilder to build a DatePickerWidget if initial data changed, but it don't working, why?
import 'dart:async';

import 'package:LunarCalendar/models/app_utils.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_holo_date_picker/flutter_holo_date_picker.dart';
import 'package:flutter_screenutil/screenutil.dart';

class DoiNgayPage extends StatefulWidget {
static const String routeName = '/DNPage';

@OverRide
State createState() {
return DoiNgayPageState();
}
}

class DoiNgayPageState extends State {
DateTime solarDay = DateTime.now();
DateTime lunarDay = DateTime.now();

final dateTimeStream = StreamController();

@OverRide
void dispose() {
super.dispose();
dateTimeStream.close();
}

@OverRide
void initState() {
super.initState();

DateTime dateTime = AppUtils().GetLunarDateFromSolarDate(solarDay.day, solarDay.month, solarDay.year);
lunarDay = new DateTime(dateTime.year, dateTime.month, dateTime.day);
dateTimeStream.sink.add(lunarDay);

}

@OverRide
Widget build(BuildContext context) {
ScreenUtil.init(context, width: 1280, height: 720, allowFontScaling: false);

return Scaffold(
  backgroundColor: Colors.white,
  appBar: AppBar(
    automaticallyImplyLeading: false,
    centerTitle: true,
    title: Text('ĐỔI NGÀY', style: TextStyle(fontSize: 22)),
    backgroundColor: Color(0xff4965e0),
  ),
  body: Column(
    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
    children: <Widget>[
      new Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Image.asset(
              "assets/images/duonglich.png",
              height: 50,
              width: 50,
              fit: BoxFit.fill,
            ),
            Text(
              ' Dương lịch: ${AppUtils().formatViewDay(solarDay)}',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(70),
                color: Colors.orangeAccent,
                fontWeight: FontWeight.w500,
              ),
            ),
          ],
        ),
      ),
      new Container(
        padding: EdgeInsets.only(left: ScreenUtil().setWidth(120), right: ScreenUtil().setWidth(120)),
        child: DottedBorder(
          color: Colors.lightBlueAccent,
          borderType: BorderType.RRect,
          radius: Radius.circular(5),
          child: DatePickerWidget(
            looping: false,
            initialDate: solarDay,
            onChange: (DateTime date, _) {
              setState(() {
                solarDay = date;
                DateTime dateTime = AppUtils().GetLunarDateFromSolarDate(solarDay.day, solarDay.month, solarDay.year);
                lunarDay = new DateTime(dateTime.year, dateTime.month, dateTime.day);
              });

              dateTimeStream.sink.add(lunarDay);
            },
            dateFormat: "dd-MMMM-yyyy",
            locale: DateTimePickerLocale.vi,
            pickerTheme: DateTimePickerTheme(
              itemTextStyle: TextStyle(color: Colors.black, fontSize: 19, fontWeight: FontWeight.bold),
              dividerColor: Colors.orange[200],
            ),
          ),
        ),
      ),
      new Container(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Image.asset(
              "assets/images/amlich.png",
              height: 50,
              width: 55,
              fit: BoxFit.fill,
            ),
            Text(
              ' Âm lịch: ${AppUtils().formatViewDay(lunarDay)}',
              style: TextStyle(
                fontSize: ScreenUtil().setSp(70),
                color: Colors.orangeAccent,
                fontWeight: FontWeight.w500,
              ),
            ),
          ],
        ),
      ),
      amlichbuilder(),
    ],
  ),
);

}

amlichbuilder() {
return StreamBuilder(
stream: dateTimeStream.stream,
builder: (context, snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();

    return new Container(
      padding: EdgeInsets.only(left: ScreenUtil().setWidth(120), right: ScreenUtil().setWidth(120)),
      child: DottedBorder(
        color: Colors.lightBlueAccent,
        borderType: BorderType.RRect,
        radius: Radius.circular(5),
        child: DatePickerWidget(
          looping: false,
          initialDate: snapshot.data,
          onChange: (DateTime date, _) {
            setState(() {
              lunarDay = date;
              DateTime dateTime = AppUtils().GetSolarDateFromLunarDate(lunarDay.day, lunarDay.month, lunarDay.year);
              solarDay = new DateTime(dateTime.year, dateTime.month, dateTime.day);
            });
          },
          dateFormat: "dd-MMMM-yyyy",
          locale: DateTimePickerLocale.vi,
          pickerTheme: DateTimePickerTheme(
            itemTextStyle: TextStyle(color: Colors.black, fontSize: 19, fontWeight: FontWeight.bold),
            dividerColor: Colors.orange[200],
          ),
        ),
      ),
    );
  },
);

}
}

@kfiross
Copy link
Owner

kfiross commented Oct 27, 2020

Hi,
Can you send a link to the repository? It's hard to understand what the problem you face with or what you expected to happen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants