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:google_fonts/google_fonts.dart';
- import 'package:module_category/presentation/bloc/category_filter_location_bloc/category_filter_location_bloc.dart';
- import 'package:module_core/common/state_enum.dart';
- import 'package:module_core/utils/app_colors.dart';
- class CategoryFilterLocationPage extends StatefulWidget {
- CategoryFilterLocationPage({Key? key}) : super(key: key);
- @override
- State<CategoryFilterLocationPage> createState() =>
- _CategoryFilterLocationPageState();
- }
- class _CategoryFilterLocationPageState
- extends State<CategoryFilterLocationPage> {
- var _fieldController = TextEditingController();
- @override
- void initState() {
- Future.microtask(
- () => BlocProvider.of<CategoryFilterLocationBloc>(context, listen: false)
- .add(
- OnClickFilterLocationDefault(),
- ),
- );
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- height: 475,
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Stack(
- alignment: Alignment.center,
- children: [
- Container(
- height: 4,
- width: 150,
- decoration: BoxDecoration(
- color: Colors.grey[400],
- borderRadius: BorderRadius.circular(4),
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(right: 8.0, top: 8),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- GestureDetector(
- onTap: () {
- Navigator.pop(context);
- },
- child: Icon(
- Icons.close,
- color: Color(0xffAEAFB2),
- size: 24,
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- SizedBox(height: 16),
- Text(
- 'Lokasi',
- textAlign: TextAlign.center,
- style: GoogleFonts.poppins(
- fontSize: 16,
- fontWeight: FontWeight.w600,
- ),
- ),
- Container(
- margin: EdgeInsets.symmetric(vertical: 16),
- height: 1,
- width: MediaQuery.of(context).size.width,
- color: Color(0xffC4C4C4),
- ),
- Padding(
- padding:
- const EdgeInsets.symmetric(horizontal: 20.0, vertical: 8.0),
- child: TextField(
- onChanged: (query) {
- if (query.isEmpty || query == '') {
- context
- .read<CategoryFilterLocationBloc>()
- .add(OnClickFilterLocationDefault());
- } else {
- context
- .read<CategoryFilterLocationBloc>()
- .add(OnChangeFilterLocationSearch(query));
- }
- },
- controller: _fieldController,
- decoration: InputDecoration(
- filled: true,
- fillColor: Color(0xffC6E4EC).withOpacity(0.5),
- hintText: 'Cari Lokasi...',
- labelStyle: TextStyle(
- fontFamily: GoogleFonts.poppins().fontFamily,
- color: Colors.grey[400],
- ),
- prefixIcon:
- Icon(Icons.search_sharp, color: AppColors.grueMedium),
- border: OutlineInputBorder(
- borderSide: BorderSide(
- color: Color(0xffC6E4EC).withOpacity(0.5)),
- borderRadius: BorderRadius.circular(24)),
- enabledBorder: OutlineInputBorder(
- borderSide: BorderSide(
- color: Color(0xffC6E4EC).withOpacity(0.5)),
- borderRadius: BorderRadius.circular(24)),
- focusedBorder: OutlineInputBorder(
- borderSide: BorderSide(
- color: Color(0xffC6E4EC).withOpacity(0.5)),
- borderRadius: BorderRadius.circular(24)),
- contentPadding: EdgeInsets.all(12)),
- textInputAction: TextInputAction.search,
- ),
- ),
- BlocBuilder<CategoryFilterLocationBloc,
- CategoryFilterLocationState>(builder: (context, state) {
- if (state.state == RequestState.Loading) {
- return Center(
- child: CircularProgressIndicator(),
- );
- } else if (state.state == RequestState.Loaded) {
- return Container(
- margin: EdgeInsets.symmetric(horizontal: 20, vertical: 14),
- height: 325,
- child: ListView.builder(
- itemCount: state.dataSearch != null
- ? state.dataSearch?.response.data.length
- : state.dataDefault?.response.data.province
- ?.asMap()
- .length,
- itemBuilder: (context, index) {
- return Container(
- margin: EdgeInsets.symmetric(vertical: 8),
- child: Column(
- children: [
- Row(
- children: [
- Text(
- state.dataSearch != null
- ? state.dataSearch?.response.data[index]
- .id ??
- ''
- : state.dataDefault?.response.data
- .province
- ?.asMap()[index]
- .toString() ??
- '',
- style: GoogleFonts.roboto(
- fontSize: 12,
- fontWeight: FontWeight.w400),
- ),
- ],
- ),
- SizedBox(height: 12),
- Container(
- height: 1,
- color: Color(0xffC4C4C4),
- ),
- ],
- ));
- },
- ),
- );
- } else if (state.state == RequestState.Empty) {
- return Center(
- child: Text('Data Kosong'),
- );
- } else if (state.state == RequestState.Error) {
- return Center(
- child: Text('Error'),
- );
- } else {
- return Container();
- }
- })
- ],
- ),
- ),
- );
- }
- @override
- void dispose() {
- _fieldController.dispose();
- super.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement