Skip to content

Commit

Permalink
feat: complete code for training
Browse files Browse the repository at this point in the history
  • Loading branch information
omartinma committed Feb 8, 2024
1 parent 9170ee1 commit 69d0051
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 21 deletions.
9 changes: 8 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
include: package:flutter_lints/flutter.yaml
include: package:very_good_analysis/analysis_options.5.1.0.yaml
analyzer:
exclude:
- lib/l10n/*
- lib/generated/*
linter:
rules:
public_member_api_docs: false
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
84 changes: 84 additions & 0 deletions lib/basics/basics_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ignore_for_file: avoid_print

import 'package:flutter/material.dart';

class BasicsScreen extends StatelessWidget {
const BasicsScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('IE Workshop'),
backgroundColor: Colors.red,
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.settings),
),
],
),
backgroundColor: Colors.green,
body: SingleChildScrollView(
child: Column(
children: [
const Text('Hello world!'),
const Text(
'Hello world with style',
style: TextStyle(
fontSize: 34,
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
const Text(
'Tooooooooooooooo looooooooooooooooong text',
style: TextStyle(
fontSize: 34,
color: Colors.pink,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
Container(
height: 300,
width: 300,
color: Colors.amber,
child: const Text('Hello in a colored box'),
),
const SizedBox(
height: 15,
),
Container(
height: 300,
width: 300,
color: Colors.amber,
padding: const EdgeInsets.all(30),
child: const Text('Hello in a colored box'),
),
Row(
children: [
TextButton(
onPressed: () {
print('Button 1 pressed');
},
child: const Text('Button 1'),
),
ElevatedButton(
onPressed: () {
print('Button 2 pressed');
},
child: const Text('Button 2'),
),
],
),
const SizedBox(
height: 100,
),
],
),
),
);
}
}
12 changes: 7 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ie_workshop/sample_app/bloc/sample_bloc.dart';
import 'package:ie_workshop/sample_app/sample_app_screen.dart';

void main() {
runApp(const MainApp());
Expand All @@ -9,11 +12,10 @@ class MainApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello World!'),
),
return MaterialApp(
home: BlocProvider(
create: (context) => SampleBloc()..add(const FetchData()),
child: const SampleAppScreen(),
),
);
}
Expand Down
30 changes: 30 additions & 0 deletions lib/sample_app/bloc/sample_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:ie_workshop/sample_app/sample_app_screen.dart';
import 'package:meta/meta.dart';

part 'sample_event.dart';
part 'sample_state.dart';

class SampleBloc extends Bloc<SampleEvent, SampleState> {
SampleBloc() : super(SampleInitial()) {
on<FetchData>(_fetchData);
}

FutureOr<void> _fetchData(FetchData event, Emitter<SampleState> emit) async {
await Future<void>.delayed(const Duration(seconds: 1));
final list = <MyItem>[];
for (var i = 0; i < 5; i++) {
list.add(
MyItem(
name: 'Name $i',
description: 'Description $i',
url: 'https://picsum.photos/id/$i/200',
),
);
}
emit(SampleSucces(items: list));
}
}
11 changes: 11 additions & 0 deletions lib/sample_app/bloc/sample_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
part of 'sample_bloc.dart';

class SampleEvent extends Equatable {
const SampleEvent();
@override
List<Object> get props => [];
}

class FetchData extends SampleEvent {
const FetchData();
}
14 changes: 14 additions & 0 deletions lib/sample_app/bloc/sample_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
part of 'sample_bloc.dart';

@immutable
sealed class SampleState {}

final class SampleInitial extends SampleState {}

final class SampleLoading extends SampleState {}

final class SampleSucces extends SampleState {
SampleSucces({required this.items});

final List<MyItem> items;
}
75 changes: 75 additions & 0 deletions lib/sample_app/sample_app_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ie_workshop/sample_app/bloc/sample_bloc.dart';

class MyItem {
MyItem({
required this.name,
required this.description,
required this.url,
});

final String name;
final String description;
final String url;
}

class SampleAppScreen extends StatelessWidget {
const SampleAppScreen({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 ListView.builder(
itemBuilder: (context, index) {
final item = state.items[index];
return ListTile(
title: Text(item.name, style: const TextStyle(fontSize: 30)),
subtitle: Text(
item.description,
style: const TextStyle(fontSize: 24),
),
leading: Image.network(item.url),
trailing: const Icon(Icons.account_tree_sharp),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) {
return DetailsScreen(item: item);
},
),
);
},
);
},
itemCount: state.items.length,
);
}
return const Center(child: CircularProgressIndicator());
},
),
);
}
}

class DetailsScreen extends StatelessWidget {
const DetailsScreen({required this.item, super.key});

final MyItem item;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(item.name),
),
body: Text(item.description, style: const TextStyle(fontSize: 30)),
);
}
}
61 changes: 47 additions & 14 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
bloc:
dependency: "direct main"
description:
name: bloc
sha256: "3820f15f502372d979121de1f6b97bfcf1630ebff8fe1d52fb2b0bfa49be5b49"
url: "https://pub.dev"
source: hosted
version: "8.1.2"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -41,6 +49,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
equatable:
dependency: "direct main"
description:
name: equatable
sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2
url: "https://pub.dev"
source: hosted
version: "2.0.5"
fake_async:
dependency: transitive
description:
Expand All @@ -54,27 +70,19 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
flutter_bloc:
dependency: "direct main"
description:
name: flutter_lints
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
name: flutter_bloc
sha256: e74efb89ee6945bcbce74a5b3a5a3376b088e5f21f55c263fc38cbdc6237faae
url: "https://pub.dev"
source: hosted
version: "2.0.3"
version: "8.1.3"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
lints:
dependency: transitive
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
matcher:
dependency: transitive
description:
Expand All @@ -92,13 +100,21 @@ packages:
source: hosted
version: "0.5.0"
meta:
dependency: transitive
dependency: "direct main"
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.10.0"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
Expand All @@ -107,6 +123,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.3"
provider:
dependency: transitive
description:
name: provider
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096"
url: "https://pub.dev"
source: hosted
version: "6.1.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -168,6 +192,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
very_good_analysis:
dependency: "direct dev"
description:
name: very_good_analysis
sha256: "9ae7f3a3bd5764fb021b335ca28a34f040cd0ab6eec00a1b213b445dae58a4b8"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
web:
dependency: transitive
description:
Expand All @@ -178,3 +210,4 @@ packages:
version: "0.3.0"
sdks:
dart: ">=3.2.4 <4.0.0"
flutter: ">=1.16.0"
6 changes: 5 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ environment:
sdk: '>=3.2.4 <4.0.0'

dependencies:
bloc: ^8.1.2
equatable:
flutter:
sdk: flutter
flutter_bloc: ^8.1.3
meta: ^1.10.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
very_good_analysis: ^5.1.0

flutter:
uses-material-design: true

0 comments on commit 69d0051

Please sign in to comment.