205 lines
7.8 KiB
Dart
205 lines
7.8 KiB
Dart
import 'package:card_loading/card_loading.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:skripsi_getit/data/model/movie.dart';
|
|
import 'package:skripsi_getit/services/cubit/test_cubit.dart';
|
|
import 'package:skripsi_getit/themes/colors.dart';
|
|
import 'package:skripsi_getit/themes/fonts.dart';
|
|
import 'package:skripsi_getit/utils/api_config.dart';
|
|
|
|
class TestView extends StatefulWidget {
|
|
const TestView({super.key});
|
|
|
|
@override
|
|
State<TestView> createState() => _TestViewState();
|
|
}
|
|
|
|
class _TestViewState extends State<TestView> {
|
|
void _handleSearch() {
|
|
final result = context.read<TestCubit>().binarySearchByTitle("Laila");
|
|
if (result != null) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Film ditemukan: ${result.title}'),
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Film tidak ditemukan'),
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
title: Text(
|
|
"Loop Test Movie",
|
|
style: AppFonts.montserrat(
|
|
fontSize: 16,
|
|
color: whiteColor,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
leading: IconButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
icon: Icon(Icons.keyboard_arrow_left_rounded, color: whiteColor),
|
|
),
|
|
),
|
|
backgroundColor: primaryColor,
|
|
body: BlocConsumer<TestCubit, List<Results>>(
|
|
builder: (context, state) {
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Wrap(
|
|
spacing: 8,
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
context.read<TestCubit>().reset();
|
|
context.read<TestCubit>().fetchDataForLoop(count: 250);
|
|
},
|
|
child: Text("For Loop"),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
context.read<TestCubit>().reset();
|
|
context.read<TestCubit>().fetchDataWhileLoop(count: 50);
|
|
},
|
|
child: Text("While Loop"),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
context.read<TestCubit>().reset();
|
|
context.read<TestCubit>().fetchDataDoWhileLoop(count: 50);
|
|
},
|
|
child: Text("Do While Loop"),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
context.read<TestCubit>().compareAllMoviesByRating();
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.deepPurple,
|
|
),
|
|
child: const Text("Compare O(n²)"),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
_handleSearch();
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.deepPurple,
|
|
),
|
|
child: const Text("Binary Search O(n²)"),
|
|
),
|
|
],
|
|
),
|
|
Gap(10),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
scrollDirection: Axis.vertical,
|
|
itemCount: state.length,
|
|
itemBuilder: (context, index) {
|
|
final movie = state[index];
|
|
return Container(
|
|
width: 120,
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
movie.posterPath != null
|
|
? Container(
|
|
padding: const EdgeInsets.all(5),
|
|
width: 120,
|
|
height: 170,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
image: DecorationImage(
|
|
image: NetworkImage(
|
|
'${ApiConfig.imageUrl}${movie.posterPath}',
|
|
),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: CircleAvatar(
|
|
radius: 20,
|
|
backgroundColor: primaryColor.withOpacity(
|
|
0.8,
|
|
),
|
|
child: Text(
|
|
'${index + 1}',
|
|
style: AppFonts.montserrat(
|
|
fontSize: 12,
|
|
color: whiteColor,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
: CardLoading(
|
|
height: 170,
|
|
width: 120,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
movie.title ?? '',
|
|
style: AppFonts.montserrat(
|
|
fontSize: 16,
|
|
color: whiteColor,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
'Rating: ${(movie.voteAverage! * 10).toStringAsFixed(0)}%',
|
|
style: AppFonts.montserrat(
|
|
fontSize: 14,
|
|
color: whiteColor,
|
|
),
|
|
),
|
|
const Gap(10),
|
|
Text(
|
|
movie.overview ?? "",
|
|
style: AppFonts.montserrat(
|
|
fontSize: 12,
|
|
color: whiteColor,
|
|
),
|
|
maxLines: 4,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
listener: (context, state) {},
|
|
),
|
|
);
|
|
}
|
|
}
|