Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to an immutable state architecture #2

Merged
merged 1 commit into from
Dec 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added artwork/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 0 additions & 24 deletions lib/about/dialogs.dart

This file was deleted.

5 changes: 4 additions & 1 deletion lib/data/result.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:meta/meta.dart';

class Result {
final int steps;
final int time;
final int size;

Result({this.steps, this.time});
Result({@required this.steps, @required this.time, @required this.size});
}
46 changes: 0 additions & 46 deletions lib/game/dialogs.dart

This file was deleted.

2 changes: 2 additions & 0 deletions lib/links.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const URL_REPOSITORY = "https://github.com/AChep/15puzzle";
const URL_AUTHOR = "https://artemchep.com";
9 changes: 9 additions & 0 deletions lib/utils/url.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:url_launcher/url_launcher.dart';

void launchUrl({String url}) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
55 changes: 55 additions & 0 deletions lib/widgets/about/dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:fifteenpuzzle/links.dart';
import 'package:fifteenpuzzle/utils/url.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class AboutDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('About'),
content: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Game of Fifteen is a free and open source app '
'written with Flutter.'),
const SizedBox(height: 32),
Text(
'Developed by',
style: Theme.of(context).textTheme.caption,
),
const SizedBox(height: 8),
ListTile(
leading: ClipOval(
child: Image.network(
'https://achep-84559.firebaseapp.com/static/avatar.jpg',
width: 32,
height: 32,
),
),
title: const Text('Artem Chepurnoy'),
onTap: () {
launchUrl(url: URL_AUTHOR);
},
),
],
),
actions: <Widget>[
new FlatButton(
child: new Text("Repository"),
onPressed: () {
launchUrl(url: URL_REPOSITORY);
},
),
new FlatButton(
child: new Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
}
}
189 changes: 189 additions & 0 deletions lib/widgets/game/material/page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import 'dart:math';

import 'package:fifteenpuzzle/widgets/game/board.dart';
import 'package:fifteenpuzzle/widgets/game/material/control.dart';
import 'package:fifteenpuzzle/widgets/game/material/sheets.dart';
import 'package:fifteenpuzzle/widgets/game/material/steps.dart';
import 'package:fifteenpuzzle/widgets/game/material/stopwatch.dart';
import 'package:fifteenpuzzle/widgets/game/presenter/main.dart';
import 'package:fifteenpuzzle/widgets/icons/app.dart';
import 'package:fifteenpuzzle/widgets/icons/stopwatch.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class GameMaterialPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final presenter = GamePresenterWidget.of(context);

final screenSize = MediaQuery.of(context).size;
final screenWidth =
MediaQuery.of(context).orientation == Orientation.portrait
? screenSize.width
: screenSize.height;
final screenHeight =
MediaQuery.of(context).orientation == Orientation.portrait
? screenSize.height
: screenSize.width;

final isTallScreen = screenHeight / screenWidth > 1.9;
final isLargeScreen = screenWidth > 400;

final fabWidget = _buildFab(context);
final boardWidget = _buildBoard(context);
return OrientationBuilder(builder: (context, orientation) {
final statusWidget = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GameStopwatchWidget(
time: presenter.time,
fontSize: orientation == Orientation.landscape && !isLargeScreen
? 56.0
: 72.0,
),
GameStepsWidget(
steps: presenter.steps,
),
],
);

if (orientation == Orientation.portrait) {
//
// Portrait layout
//
return Scaffold(
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
isTallScreen
? Container(
height: 56,
child: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const AppIcon(size: 24.0),
const SizedBox(width: 16.0),
Text(
'Game of Fifteen',
style: Theme.of(context).textTheme.title,
),
],
),
),
)
: const SizedBox(height: 0),
Expanded(
child: Center(
child: statusWidget,
),
),
boardWidget,
isLargeScreen && isTallScreen
? const SizedBox(height: 116.0)
: const SizedBox(height: 72.0),
],
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: fabWidget,
);
} else {
//
// Landscape layout
//
return Scaffold(
body: SafeArea(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
boardWidget,
statusWidget,
],
),
),
floatingActionButton: fabWidget,
);
}
});
}

Widget _buildBoard(final BuildContext context) {
final presenter = GamePresenterWidget.of(context);
final background = Theme.of(context).brightness == Brightness.dark
? Colors.black54
: Colors.black12;
return Center(
child: Container(
margin: EdgeInsets.all(16.0),
padding: EdgeInsets.all(4.0),
decoration: BoxDecoration(
color: background,
borderRadius: BorderRadius.circular(16.0),
),
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final puzzleSize = min(
constraints.maxWidth,
constraints.maxHeight,
);

return BoardWidget(
board: presenter.board,
size: puzzleSize,
onTap: (point) {
presenter.tap(point: point);
},
);
},
),
),
);
}

Widget _buildFab(final BuildContext context) {
final presenter = GamePresenterWidget.of(context);
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const SizedBox(width: 64.0),
GamePlayStopButton(
isPlaying: presenter.isPlaying(),
onTap: () {
presenter.playStop();
},
),
const SizedBox(width: 16.0),
Container(
width: 48,
height: 48,
child: Material(
elevation: 0.0,
color: Colors.transparent,
shape: CircleBorder(),
child: InkWell(
onTap: () {
// Show the modal bottom sheet on
// tap on "More" icon.
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return createMoreBottomSheet(context,
psize: presenter.board.size,
call: (size) {
presenter.resize(size);
});
},
);
},
customBorder: CircleBorder(),
child: Icon(Icons.more_vert),
),
),
),
],
);
}
}
21 changes: 13 additions & 8 deletions lib/widgets/game/material/sheets.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:fifteenpuzzle/config/ui.dart';
import 'package:fifteenpuzzle/game/dialogs.dart';
import 'package:fifteenpuzzle/links.dart';
import 'package:fifteenpuzzle/utils/url.dart';
import 'package:fifteenpuzzle/widgets/about/dialog.dart';
import 'package:fifteenpuzzle/widgets/game/presenter/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide AboutDialog;
import 'package:flutter/widgets.dart';

Widget createMoreBottomSheet(
Expand Down Expand Up @@ -29,15 +31,18 @@ Widget createMoreBottomSheet(
showDialog(
context: context,
builder: (context) {
return createAboutDialog(context);
return AboutDialog();
});
},
),
// ListTile(
// leading: const Icon(Icons.people_outline),
// title: const Text('Contribute'),
// onTap: () {},
// ),
ListTile(
leading: const Icon(Icons.people_outline),
title: const Text('Contribute'),
onTap: () {
Navigator.of(context).pop();
launchUrl(url: URL_REPOSITORY);
},
),
const Divider(),
];

Expand Down
Loading