Skip to content

Instantly share code, notes, and snippets.

@techpotatoes
techpotatoes / navigator_bloc_test.dart
Created June 2, 2020 14:43
Flutter development series – Part 5
// ignore_for_file: invalid_override_different_default_values_named, must_be_immutable
class MockNavigatorKey extends Mock implements GlobalKey<NavigatorState> {}
class MockCurrentState extends Mock implements NavigatorState {
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.debug}) =>
super.toString();
}
@techpotatoes
techpotatoes / loyalty_add_page.dart
Created June 2, 2020 14:34
Flutter development series – Part 5
class LoyaltyAddPage extends StatelessWidget {
const LoyaltyAddPage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
BlocProvider.of<NavigatorBloc>(context).add(NavigatorEventPop());
return Future(() => true);
},
@techpotatoes
techpotatoes / navigator_event.dart
Created June 2, 2020 13:19
Flutter development series – Part 5
abstract class NavigatorEvent {}
class NavigatorEventPop extends NavigatorEvent {}
class NavigatorEventAdd extends NavigatorEvent {}
@techpotatoes
techpotatoes / navigator_bloc.dart
Created June 2, 2020 13:14
Flutter development series – Part 5
class NavigatorBloc extends Bloc<NavigatorEvent, dynamic>{
final GlobalKey<NavigatorState> navigatorKey;
NavigatorBloc({this.navigatorKey});
@override
dynamic get initialState => "Initial";
@override
@techpotatoes
techpotatoes / loyalty_bloc_test.dart
Created April 18, 2020 14:47
Flutter development series - part4
class MockLoyaltyCardRepository extends Mock implements LoyaltyCardRepository {}
class UnhandledEvent extends LoyaltyEvent {}
void main() {
final loyaltyCard1 = LoyaltyCard.fromParams('Card1','12345');
group('Given a Loyalty cards BLoC', () {
final mockLoyaltyCardRepository = MockLoyaltyCardRepository();
@techpotatoes
techpotatoes / loyalty_list_page.dart
Created April 18, 2020 14:31
Flutter development series - part4
class LoyaltyListPage extends StatefulWidget {
LoyaltyListPage({Key key}) : super(key: key);
@override
_LoyaltyListPageState createState() => _LoyaltyListPageState();
}
class _LoyaltyListPageState extends State<LoyaltyListPage> {
@override
@techpotatoes
techpotatoes / main.dart
Created April 18, 2020 14:07
Flutter development series - part4
void main()...
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
@techpotatoes
techpotatoes / events_states.dart
Created April 18, 2020 13:16
Flutter development series - part4
//EVENTS
abstract class LoyaltyEvent extends Equatable {
@override
List<Object> get props => [];
}
class Fetch extends LoyaltyEvent {}
@techpotatoes
techpotatoes / loyalty_bloc.dart
Last active April 18, 2020 14:36
Flutter development series - part4
class LoyaltyBloc extends Bloc<LoyaltyEvent, LoyaltyState>{
final LoyaltyCardRepository loyaltyCardRepository;
LoyaltyBloc({@required this.loyaltyCardRepository});
@override
LoyaltyState get initialState => LoyaltyEmpty();
@override
Stream<LoyaltyState> mapEventToState(LoyaltyEvent event) async* {
@techpotatoes
techpotatoes / pubspec.yaml
Last active April 16, 2020 09:52
Flutter development series - part4
...
dependencies:
equatable: ^1.1.1
bloc: ^3.0.0
flutter_bloc: ^3.2.0
...