Open Qusdrok opened 4 years ago
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], ), ), ), ); }, );
} }
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
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();
}
@override Widget build(BuildContext context) { ScreenUtil.init(context, width: 1280, height: 720, allowFontScaling: false);
}
amlichbuilder() { return StreamBuilder(
stream: dateTimeStream.stream,
builder: (context, snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
} }