2020-05-29 07:45:27 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:fcs/model/announcement_model.dart';
|
|
|
|
|
import 'package:fcs/model/main_model.dart';
|
|
|
|
|
import 'package:fcs/vo/announcement.dart' as Announce;
|
|
|
|
|
import 'package:fcs/widget/local_text.dart';
|
|
|
|
|
import 'package:fcs/widget/localization/app_translations.dart';
|
|
|
|
|
import 'package:fcs/widget/progress.dart';
|
|
|
|
|
|
2020-08-30 21:26:37 +06:30
|
|
|
import '../fcs/common/theme.dart';
|
2020-05-29 07:45:27 +06:30
|
|
|
import 'announcement.dart';
|
|
|
|
|
import 'announcement_editor.dart';
|
|
|
|
|
|
|
|
|
|
class AnnouncementList extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
_AnnouncementListState createState() => _AnnouncementListState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AnnouncementListState extends State<AnnouncementList> {
|
|
|
|
|
var timeFormatter = new DateFormat('KK:mm a');
|
|
|
|
|
var dateFormatter = new DateFormat('dd MMM');
|
|
|
|
|
|
|
|
|
|
final double dotSize = 15.0;
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
AnnouncementModel announcementModel =
|
|
|
|
|
Provider.of<AnnouncementModel>(context);
|
|
|
|
|
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context);
|
|
|
|
|
bool isOwnerAndAbove =
|
|
|
|
|
mainModel.user != null && mainModel.user.isOwnerAndAbove();
|
|
|
|
|
bool hasAdmin = mainModel.user != null && mainModel.user.hasAdmin();
|
|
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2020-08-30 21:26:37 +06:30
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"announcement.title",
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
)),
|
2020-05-29 07:45:27 +06:30
|
|
|
floatingActionButton: isOwnerAndAbove || hasAdmin
|
|
|
|
|
? FloatingActionButton(
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
child: Icon(Icons.add),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => AnnouncementEditor()),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: Container(),
|
|
|
|
|
body: new ListView.separated(
|
|
|
|
|
separatorBuilder: (context, index) => Divider(
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
),
|
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
|
padding: EdgeInsets.only(left: 15, right: 15, top: 15),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: announcementModel.announcements.length,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
Announce.Announcement announce =
|
|
|
|
|
announcementModel.announcements[index];
|
|
|
|
|
return InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
AnnouncementPage(announcement: announce)),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: new Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 10.0),
|
|
|
|
|
child: new Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
new Padding(
|
|
|
|
|
padding: new EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 32.0 - dotSize / 2),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.announcement,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
size: 30,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
new Expanded(
|
|
|
|
|
child: new Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
announce.name == null
|
|
|
|
|
? Container()
|
|
|
|
|
: new Text(
|
|
|
|
|
announce.name,
|
|
|
|
|
style: new TextStyle(
|
|
|
|
|
fontSize: 15.0,
|
|
|
|
|
color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2020-08-30 21:26:37 +06:30
|
|
|
Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: Text(announce.time == null
|
|
|
|
|
? ""
|
|
|
|
|
: timeFormatter.format(announce.time)),
|
|
|
|
|
),
|
|
|
|
|
announce.fromToday()
|
|
|
|
|
? Container()
|
|
|
|
|
: Text(announce.time == null
|
|
|
|
|
? ""
|
|
|
|
|
: dateFormatter.format(announce.time)),
|
|
|
|
|
],
|
|
|
|
|
)
|
2020-05-29 07:45:27 +06:30
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|