Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
markusrubey authored Feb 5, 2021
1 parent ebaaf79 commit 46512ca
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 152 deletions.
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
File renamed without changes.
6 changes: 3 additions & 3 deletions lib/domain/common/use_case.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
abstract class BaseUseCase<Output> {
abstract class UseCase<Output> {
Future<Output> run();
}

abstract class BaseStreamUseCase<Output> {
abstract class StreamUseCase<Output> {
Stream<Output> run();
}
}
11 changes: 11 additions & 0 deletions lib/domain/error/error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// Defines user facing errors.
enum Error {
/// A generic error.
unknown,

/// No internet connection error.
connection,

/// Unauthorized 401 error.
unauthorized,
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import 'package:dio/dio.dart';

/// Defines user facing errors.
enum Error {
/// A generic error.
unknown,

/// No internet connection error.
connection,

/// Unauthorized 401 error.
unauthorized,
}
import 'package:flutter_template/domain/error/error.dart';

class ErrorHandler {
static List<Error> obtainAll(dynamic error) {
Expand Down
115 changes: 2 additions & 113 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,117 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_template/presentation/app.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
runApp(App());
}
12 changes: 12 additions & 0 deletions lib/presentation/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_template/presentation/app_router.dart';

class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Project Name',
onGenerateRoute: AppRouter.onGenerateRoute,
);
}
}
28 changes: 28 additions & 0 deletions lib/presentation/app_router.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_template/presentation/feature/home/home_page_route.dart';

/// Contains classes and helpers for navigation.
/// To navigate to a page use the [BuildContext.navigateTo] extension function.
/// - Example: context.navigateTo(HomeRoute(fieldExample = "hello"));
/// To pop the Navigation stack to a specific page use the [BuildContext.popUntil] extension function.
/// - Example: context.popUntil(HomeRoute.name);
class AppRouter {
static Route<dynamic> onGenerateRoute(RouteSettings settings) {
final args = settings.arguments;
return args is AppRoute ? args.route : HomePageRoute().route;
}
}

abstract class AppRoute {
String get name;

Widget get page;

MaterialPageRoute get route {
return MaterialPageRoute(
builder: (context) => page,
settings: RouteSettings(name: name),
);
}
}
5 changes: 0 additions & 5 deletions lib/presentation/common/base_bloc.dart

This file was deleted.

5 changes: 5 additions & 0 deletions lib/presentation/common/bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abstract class Bloc {
Future<void> initState() async {}

void dispose();
}
2 changes: 1 addition & 1 deletion lib/presentation/common/error_messages.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_template/domain/model/error.dart';
import 'package:flutter_template/domain/error/error.dart';

extension ErrorMessages on Error {
String getMessage(BuildContext context) {
Expand Down
49 changes: 49 additions & 0 deletions lib/presentation/feature/home/home_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';
import 'package:flutter_template/presentation/feature/home/home_page_tab.dart';

class HomePage extends StatefulWidget {
HomePage({Key key, this.tab}) : super(key: key);

final HomePageTab tab;

@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
_counter++;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.tab.toString()),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
15 changes: 15 additions & 0 deletions lib/presentation/feature/home/home_page_route.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter_template/presentation/feature/home/home_page.dart';
import 'package:flutter_template/presentation/feature/home/home_page_tab.dart';
import 'package:flutter_template/presentation/app_router.dart';

class HomePageRoute extends AppRoute {
final HomePageTab tab;

HomePageRoute({this.tab = HomePageTab.first});

@override
get page => HomePage(tab: tab);

@override
get name => '/';
}
5 changes: 5 additions & 0 deletions lib/presentation/feature/home/home_page_tab.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum HomePageTab {
first,
second,
third,
}
20 changes: 2 additions & 18 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,10 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:flutter_template/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
testWidgets('TODO', (WidgetTester tester) async {
// TODO
});
}

0 comments on commit 46512ca

Please sign in to comment.