-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from AChep/dev
Move to an immutable state architecture
- Loading branch information
Showing
14 changed files
with
373 additions
and
111 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -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}); | ||
} |
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,2 @@ | ||
const URL_REPOSITORY = "https://github.com/AChep/15puzzle"; | ||
const URL_AUTHOR = "https://artemchep.com"; |
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,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'; | ||
} | ||
} |
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,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(); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
} |
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,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), | ||
), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |
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
Oops, something went wrong.