Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import 'package:font_awesome_flutter/font_awesome_flutter.dart';
- import 'package:lottie/lottie.dart';
- import 'package:sisca/config/theme/dialog_helper.dart';
- import 'package:sisca/presentation/home/ui/widget/textfield_search.dart';
- import 'package:sisca/presentation/peserta/ui/peserta_page.dart';
- import 'package:sisca/config/preferences/sisca_preferences.dart';
- import 'package:sisca/presentation/home/ui/widget/card_event.dart';
- import '../../../config/preferences/constant.dart';
- import '../../../config/preferences/global_value.dart';
- import '../../../config/theme/light_colors.dart';
- import '../../error/error_screen.dart';
- import '../../peserta/data/model/argument_peserta.dart';
- import '../bloc/home_bloc.dart';
- import '../data/model/event_model.dart';
- class HomePage extends StatefulWidget {
- const HomePage({super.key});
- @override
- State<HomePage> createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> {
- late List<EventModel> _eventList = [];
- late List<EventModel> _searchResult = [];
- late TextEditingController textController = TextEditingController();
- @override
- void initState() {
- BlocProvider.of<HomeBloc>(context).add(HomeSendData());
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- Size size = MediaQuery.of(context).size;
- String username = GlobalValue.getUsername(TAG_USERNAME)!;
- return Scaffold(
- body: SafeArea(
- child: ListView(
- children: [
- /// header
- Padding(
- padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- "Hallo, $username",
- style: const TextStyle(
- fontWeight: FontWeight.w600,
- fontSize: 22.0,
- color: LightColors.kRed),
- ),
- Text(
- "Petugas Presensi",
- style: const TextStyle(
- fontSize: 14.0,
- color: Colors.black54),
- ),
- ],
- ),
- InkWell(
- child: Container(
- width: 60,
- height: 60,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- image: DecorationImage(
- image: NetworkImage(
- 'https://images.pixexid.com/a-persons-face-expressing-a-sense-of-wonder-and-curiosity-as-they-explore-a-new-3rjuuksg.webp?h=700&q=70'),
- fit: BoxFit.cover),
- border: Border.all(width: 4, color: Colors.black38)
- ),
- ),
- onTap: () {
- DialogHelper.showLogoutDialog(context, "Keluar Aplikasi",
- "Apakah anda yakin akan keluar aplikasi?");
- },
- )
- ],
- ),
- ),
- /// Event list
- BlocConsumer<HomeBloc, HomeState>(
- builder: (context, state) {
- if (state is HomeLoad) {
- if (state.data.isNotEmpty) {
- _eventList = state.data;
- } else {
- return Center(
- child: Container(
- margin: const EdgeInsets.symmetric(vertical: 50),
- child: const Text(
- "Event kosong",
- style: TextStyle(
- color: Colors.black45,
- fontWeight: FontWeight.w400,
- ),
- ),
- ),
- );
- }
- } else if (state is HomeLoading) {
- return Center(
- child: Container(
- margin: const EdgeInsets.symmetric(vertical: 50),
- child: Container(
- width: 175,
- height: 175,
- child: Lottie.asset('assets/lottie/animated_loading.json'),
- ),
- ));
- } else if (state is ErrorEvent) {
- return ErrorScreenBuilder(errorMessage: state.errorMessage);
- }
- return _buildLayout(size);
- },
- listener: (context, state) {},
- ),
- ],
- ),
- ),
- );
- }
- Widget _buildLayout(Size size) {
- return Column(
- children: [
- /// filed pencarian
- TextFieldSearch(
- size: size,
- textController: textController,
- hintText: 'Cari event disini',
- icoton: textController.text.isEmpty ? IconButton(
- onPressed: () {},
- icon: const Icon(
- FontAwesomeIcons.search,
- color: Colors.black54,
- )): IconButton(
- onPressed: () {
- textController.clear();
- setState(() {
- _searchResult = _eventList;
- });
- },
- icon: const Icon(
- FontAwesomeIcons.close,
- color: Colors.black54,
- )),
- onChangedText: onSearchTextChanged,
- ),
- const SizedBox(
- height: 20,
- ),
- Container(
- width: size.width * 0.95,
- alignment: Alignment.topLeft,
- margin: const EdgeInsets.symmetric(horizontal: 10),
- // margin: const EdgeInsets.fromLTRB(20.0, 5.0, 100.0, 5.0),
- decoration: const BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(12)),
- color: LightColors.kRed,
- ),
- child: const Padding(
- padding: EdgeInsets.all(10),
- child: Text(
- "Daftar Event",
- style: TextStyle(
- fontSize: 18.0,
- color: Colors.white,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- ),
- _eventListView(size)
- ],
- );
- }
- Widget _eventListView(Size size) {
- return _searchResult.isNotEmpty
- ? ListView.builder(
- shrinkWrap: true,
- physics: const NeverScrollableScrollPhysics(),
- itemCount: _searchResult.length,
- itemBuilder: (context, index) {
- return _eventListItems(_searchResult[index], size);
- },
- )
- : ListView.builder(
- shrinkWrap: true,
- physics: const NeverScrollableScrollPhysics(),
- itemCount: _eventList.length,
- itemBuilder: (context, index) {
- return _eventListItems(_eventList[index], size);
- },
- );
- }
- Widget _eventListItems(EventModel eventList, Size size) {
- return Container(
- padding: const EdgeInsets.symmetric(horizontal:10, vertical: 5),
- child: CardEvent(
- size: size,
- title: eventList.title!,
- peserta: eventList.peserta!,
- lokasi: eventList.lokasi!,
- start: eventList.time_start!,
- finish: eventList.time_finish!,
- onTapEvent: () {
- print(eventList.idEvent);
- String? jenis = "";
- String? status = eventList.status_acara;
- String? id = eventList.idEvent;
- Navigator.pushNamed(context, '/peserta',
- arguments: PesertaArgument(
- id,
- status,
- jenis,
- ));
- },
- ),
- );
- }
- //fungsi pencarian
- onSearchTextChanged(String text) {
- List<EventModel> _results = <EventModel>[];
- if (text.isEmpty) {
- _results = _eventList;
- } else {
- _results = _eventList
- .where((event) =>
- event.title!.toLowerCase().contains(text.toLowerCase()))
- .toList();
- }
- setState(() {
- _searchResult = _results;
- });
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement