-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
249 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'character.g.dart'; | ||
|
||
@JsonSerializable() | ||
|
||
/// [Character] is a character entity fetched from rick and morty api | ||
class Character { | ||
/// Default constructor | ||
const Character({ | ||
required this.id, | ||
required this.name, | ||
required this.image, | ||
required this.species, | ||
required this.status, | ||
}); | ||
|
||
/// Json deserialize | ||
factory Character.fromJson(Map<String, dynamic> json) => | ||
_$CharacterFromJson(json); | ||
|
||
/// Id of the character | ||
final int id; | ||
|
||
/// Name of the character | ||
final String name; | ||
|
||
/// Image of the character | ||
final String image; | ||
|
||
/// Species of the character | ||
final String species; | ||
|
||
/// Status of the character | ||
final Status status; | ||
} | ||
|
||
/// Status of the character | ||
enum Status { | ||
@JsonValue('Alive') | ||
|
||
/// alive | ||
alive, | ||
@JsonValue('Dead') | ||
|
||
/// dead | ||
dead, | ||
@JsonValue('unknown') | ||
|
||
/// unknown | ||
unknown, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'character.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'bloc/sample_bloc.dart'; | ||
export 'models/models.dart'; | ||
export 'view/view.dart'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_basics/sample_app/sample_app.dart'; | ||
|
||
class CharacterList extends StatelessWidget { | ||
const CharacterList({required this.characters, super.key}); | ||
|
||
final List<Character> characters; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GridView.builder( | ||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | ||
crossAxisCount: 2, | ||
), | ||
itemBuilder: (context, index) => CharacterItemView( | ||
character: characters[index], | ||
), | ||
itemCount: characters.length, | ||
); | ||
} | ||
} | ||
|
||
class CharacterItemView extends StatelessWidget { | ||
@visibleForTesting | ||
const CharacterItemView({ | ||
required this.character, | ||
super.key, | ||
}); | ||
|
||
final Character character; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return InkWell( | ||
child: Stack( | ||
fit: StackFit.expand, | ||
children: [ | ||
Positioned.fill( | ||
child: Hero( | ||
tag: 'image_hero_${character.name}', | ||
child: FittedBox( | ||
fit: BoxFit.fill, | ||
child: Image.network(character.image), | ||
), | ||
), | ||
), | ||
Positioned( | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
child: Container( | ||
color: Colors.white70, | ||
padding: const EdgeInsets.all(5), | ||
child: Center( | ||
child: Text( | ||
character.name, | ||
textAlign: TextAlign.center, | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
style: const TextStyle( | ||
fontSize: 25, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_basics/sample_app/bloc/sample_bloc.dart'; | ||
import 'package:flutter_basics/sample_app/view/character_list.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class SampleAppScreen extends StatelessWidget { | ||
const SampleAppScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocProvider( | ||
create: (context) => SampleBloc()..add(const FetchData()), | ||
child: const SampleAppScreenView(), | ||
); | ||
} | ||
} | ||
|
||
class SampleAppScreenView extends StatelessWidget { | ||
const SampleAppScreenView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('My first app'), | ||
), | ||
body: BlocBuilder<SampleBloc, SampleState>( | ||
builder: (context, state) { | ||
if (state is SampleSucces) { | ||
return CharacterList(characters: state.items); | ||
} | ||
return const Center(child: CircularProgressIndicator()); | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'sample_app_screen.dart'; |