Skip to content
Snippets Groups Projects
Commit 909d5289 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Add main menu with first "demo" entry, clean/improve/fix code

parent 1a1cc983
No related branches found
No related tags found
1 merge request!25Resolve "Add a main menu"
Pipeline #3843 passed
This commit is part of merge request !25. Comments created here will be created in the context of that merge request.
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=1.0.16
app.versionCode=17
app.versionName=1.0.17
app.versionCode=18
assets/menu/demo.png

11.8 KiB

#! /bin/bash
# Check dependencies
command -v inkscape >/dev/null 2>&1 || { echo >&2 "I require inkscape but it's not installed. Aborting."; exit 1; }
command -v scour >/dev/null 2>&1 || { echo >&2 "I require scour but it's not installed. Aborting."; exit 1; }
command -v optipng >/dev/null 2>&1 || { echo >&2 "I require optipng but it's not installed. Aborting."; exit 1; }
command -v inkscape >/dev/null 2>&1 || {
echo >&2 "I require inkscape but it's not installed. Aborting."
exit 1
}
command -v scour >/dev/null 2>&1 || {
echo >&2 "I require scour but it's not installed. Aborting."
exit 1
}
command -v optipng >/dev/null 2>&1 || {
echo >&2 "I require optipng but it's not installed. Aborting."
exit 1
}
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
BASE_DIR="$(dirname "${CURRENT_DIR}")"
SOURCE_ICON="${CURRENT_DIR}/icon.svg"
SOURCE_FASTLANE="${CURRENT_DIR}/featureGraphic.svg"
SOURCE_LAUNCH_IMAGE="${CURRENT_DIR}/icon.svg"
ASSETS_DIR="${BASE_DIR}/assets"
OPTIPNG_OPTIONS="-preserve -quiet -o7"
ICON_SIZE=192
if [ ! -f "${SOURCE_ICON}" ]; then
echo "Missing file: ${SOURCE_ICON}"
fi
#######################################################
if [ ! -f "${SOURCE_FASTLANE}" ]; then
echo "Missing file: ${SOURCE_FASTLANE}"
fi
# Menu images
AVAILABLE_MENU_IMAGES="
demo
"
if [ ! -f "${SOURCE_LAUNCH_IMAGE}" ]; then
echo "Missing file: ${SOURCE_LAUNCH_IMAGE}"
fi
#######################################################
# optimize svg
function optimize_svg() {
SVG="$1"
SOURCE="$1"
cp ${SVG} ${SVG}.tmp
cp "${SOURCE}" "${SOURCE}.tmp"
scour \
--remove-descriptive-elements \
--enable-id-stripping \
......@@ -37,82 +42,47 @@ function optimize_svg() {
--enable-comment-stripping \
--nindent=4 \
--quiet \
-i ${SVG}.tmp \
-o ${SVG}
rm ${SVG}.tmp
-i "${SOURCE}.tmp" \
-o "${SOURCE}"
rm "${SOURCE}.tmp"
}
# optimize source svg files
optimize_svg ${SOURCE_ICON}
optimize_svg ${SOURCE_FASTLANE}
optimize_svg ${SOURCE_LAUNCH_IMAGE}
# build icons
function build_application_icon() {
ICON_SIZE="$1"
function build_icon() {
SOURCE="$1"
TARGET="$2"
echo "Building ${TARGET}"
TARGET_PNG="${TARGET}.png"
inkscape \
--export-width=${ICON_SIZE} \
--export-height=${ICON_SIZE} \
--export-filename=${TARGET_PNG} \
${SOURCE_ICON}
optipng ${OPTIPNG_OPTIONS} ${TARGET_PNG}
}
# build fastlane image
function build_fastlane_image() {
WIDTH="$1"
HEIGHT="$2"
TARGET="$3"
if [[ ! -f "${SOURCE}" ]]; then
echo "Missing file: ${SOURCE}"
exit 1
fi
echo "Building ${TARGET}"
if [[ ! -d "$(dirname ${TARGET})" ]]; then
mkdir -p "$(dirname ${TARGET})"
fi
TARGET_PNG="${TARGET}.png"
optimize_svg "${SOURCE}"
inkscape \
--export-width=${WIDTH} \
--export-height=${HEIGHT} \
--export-filename=${TARGET_PNG} \
${SOURCE_FASTLANE}
--export-width="${ICON_SIZE}" \
--export-height="${ICON_SIZE}" \
--export-filename="${TARGET}" \
"${SOURCE}"
optipng ${OPTIPNG_OPTIONS} ${TARGET_PNG}
optipng ${OPTIPNG_OPTIONS} "${TARGET}"
}
# build launch images (splash screen)
function build_launch_image() {
ICON_SIZE="$1"
TARGET="$2"
echo "Building ${TARGET}"
TARGET_PNG="${TARGET}.png"
inkscape \
--export-width=${ICON_SIZE} \
--export-height=${ICON_SIZE} \
--export-filename=${TARGET_PNG} \
${SOURCE_LAUNCH_IMAGE}
optipng ${OPTIPNG_OPTIONS} ${TARGET_PNG}
}
#######################################################
build_application_icon 72 ${BASE_DIR}/android/app/src/main/res/mipmap-hdpi/ic_launcher
build_application_icon 48 ${BASE_DIR}/android/app/src/main/res/mipmap-mdpi/ic_launcher
build_application_icon 96 ${BASE_DIR}/android/app/src/main/res/mipmap-xhdpi/ic_launcher
build_application_icon 144 ${BASE_DIR}/android/app/src/main/res/mipmap-xxhdpi/ic_launcher
build_application_icon 192 ${BASE_DIR}/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher
build_application_icon 512 ${BASE_DIR}/fastlane/metadata/android/en-US/images/icon
# Create output folders
mkdir -p "${ASSETS_DIR}"
build_launch_image 72 ${BASE_DIR}/android/app/src/main/res/mipmap-hdpi/launch_image
build_launch_image 48 ${BASE_DIR}/android/app/src/main/res/mipmap-mdpi/launch_image
build_launch_image 96 ${BASE_DIR}/android/app/src/main/res/mipmap-xhdpi/launch_image
build_launch_image 144 ${BASE_DIR}/android/app/src/main/res/mipmap-xxhdpi/launch_image
build_launch_image 192 ${BASE_DIR}/android/app/src/main/res/mipmap-xxxhdpi/launch_image
# Delete existing generated images
find "${ASSETS_DIR}" -type f -name "*.png" -delete
build_fastlane_image 1024 500 ${BASE_DIR}/fastlane/metadata/android/en-US/images/featureGraphic
# build menu images
for MENU_IMAGE in ${AVAILABLE_MENU_IMAGES}; do
build_icon "${CURRENT_DIR}/menu_${MENU_IMAGE}.svg" "${ASSETS_DIR}/menu/${MENU_IMAGE}.png"
done
#! /bin/bash
# Check dependencies
command -v inkscape >/dev/null 2>&1 || { echo >&2 "I require inkscape but it's not installed. Aborting."; exit 1; }
command -v scour >/dev/null 2>&1 || { echo >&2 "I require scour but it's not installed. Aborting."; exit 1; }
command -v optipng >/dev/null 2>&1 || { echo >&2 "I require optipng but it's not installed. Aborting."; exit 1; }
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
BASE_DIR="$(dirname "${CURRENT_DIR}")"
ASSETS_DIR="${BASE_DIR}/assets"
OPTIPNG_OPTIONS="-preserve -quiet -o7"
ICON_SIZE=192
#######################################################
# Game images
AVAILABLE_GAME_IMAGES="
"
# Settings images
AVAILABLES_GAME_SETTINGS="
"
#######################################################
# optimize svg
function optimize_svg() {
SOURCE="$1"
cp ${SOURCE} ${SOURCE}.tmp
scour \
--remove-descriptive-elements \
--enable-id-stripping \
--enable-viewboxing \
--enable-comment-stripping \
--nindent=4 \
--quiet \
-i ${SOURCE}.tmp \
-o ${SOURCE}
rm ${SOURCE}.tmp
}
# build icons
function build_icon() {
SOURCE="$1"
TARGET="$2"
echo "Building ${TARGET}"
if [ ! -f "${SOURCE}" ]; then
echo "Missing file: ${SOURCE}"
exit 1
fi
optimize_svg "${SOURCE}"
inkscape \
--export-width=${ICON_SIZE} \
--export-height=${ICON_SIZE} \
--export-filename=${TARGET} \
${SOURCE}
optipng ${OPTIPNG_OPTIONS} ${TARGET}
}
function build_settings_icons() {
INPUT_STRING="$1"
SETTING_NAME="$(echo "${INPUT_STRING}" | cut -d":" -f1)"
SETTING_VALUES="$(echo "${INPUT_STRING}" | cut -d":" -f2 | tr "," " ")"
for SETTING_VALUE in ${SETTING_VALUES}
do
SETTING_CODE="${SETTING_NAME}_${SETTING_VALUE}"
build_icon ${CURRENT_DIR}/${SETTING_CODE}.svg ${ASSETS_DIR}/icons/${SETTING_CODE}.png
done
}
#######################################################
# Create output folders
mkdir -p ${ASSETS_DIR}/icons
# Delete existing generated images
find ${ASSETS_DIR}/icons -type f -name "*.png" -delete
# build game images
for GAME_IMAGE in ${AVAILABLE_GAME_IMAGES}
do
build_icon ${CURRENT_DIR}/${GAME_IMAGE}.svg ${ASSETS_DIR}/icons/${GAME_IMAGE}.png
done
# build settings images
for GAME_SETTING in ${AVAILABLES_GAME_SETTINGS}
do
build_settings_icons "${GAME_SETTING}"
done
#! /bin/bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
"${CURRENT_DIR}/build_application_icons.sh"
"${CURRENT_DIR}/build_repository_icons.sh"
#! /bin/bash
# Check dependencies
command -v inkscape >/dev/null 2>&1 || {
echo >&2 "I require inkscape but it's not installed. Aborting."
exit 1
}
command -v scour >/dev/null 2>&1 || {
echo >&2 "I require scour but it's not installed. Aborting."
exit 1
}
command -v optipng >/dev/null 2>&1 || {
echo >&2 "I require optipng but it's not installed. Aborting."
exit 1
}
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
BASE_DIR="$(dirname "${CURRENT_DIR}")"
SOURCE_ICON="${CURRENT_DIR}/icon.svg"
SOURCE_FASTLANE="${CURRENT_DIR}/featureGraphic.svg"
SOURCE_LAUNCH_IMAGE="${CURRENT_DIR}/icon.svg"
OPTIPNG_OPTIONS="-preserve -quiet -o7"
if [ ! -f "${SOURCE_ICON}" ]; then
echo "Missing file: ${SOURCE_ICON}"
fi
if [ ! -f "${SOURCE_FASTLANE}" ]; then
echo "Missing file: ${SOURCE_FASTLANE}"
fi
if [ ! -f "${SOURCE_LAUNCH_IMAGE}" ]; then
echo "Missing file: ${SOURCE_LAUNCH_IMAGE}"
fi
function optimize_svg() {
SVG="$1"
cp "${SVG}" "${SVG}.tmp"
scour \
--remove-descriptive-elements \
--enable-id-stripping \
--enable-viewboxing \
--enable-comment-stripping \
--nindent=4 \
--quiet \
-i "${SVG}.tmp" \
-o "${SVG}"
rm "${SVG}.tmp"
}
# optimize source svg files
optimize_svg "${SOURCE_ICON}"
optimize_svg "${SOURCE_FASTLANE}"
optimize_svg "${SOURCE_LAUNCH_IMAGE}"
# build icons
function build_application_icon() {
ICON_SIZE="$1"
TARGET="$2"
echo "Building ${TARGET}"
TARGET_PNG="${TARGET}.png"
inkscape \
--export-width="${ICON_SIZE}" \
--export-height="${ICON_SIZE}" \
--export-filename="${TARGET_PNG}" \
"${SOURCE_ICON}"
optipng ${OPTIPNG_OPTIONS} "${TARGET_PNG}"
}
# build fastlane image
function build_fastlane_image() {
WIDTH="$1"
HEIGHT="$2"
TARGET="$3"
echo "Building ${TARGET}"
TARGET_PNG="${TARGET}.png"
inkscape \
--export-width="${WIDTH}" \
--export-height="${HEIGHT}" \
--export-filename="${TARGET_PNG}" \
"${SOURCE_FASTLANE}"
optipng ${OPTIPNG_OPTIONS} "${TARGET_PNG}"
}
# build launch images (splash screen)
function build_launch_image() {
ICON_SIZE="$1"
TARGET="$2"
echo "Building ${TARGET}"
TARGET_PNG="${TARGET}.png"
inkscape \
--export-width="${ICON_SIZE}" \
--export-height="${ICON_SIZE}" \
--export-filename="${TARGET_PNG}" \
"${SOURCE_LAUNCH_IMAGE}"
optipng ${OPTIPNG_OPTIONS} "${TARGET_PNG}"
}
build_application_icon 72 "${BASE_DIR}/android/app/src/main/res/mipmap-hdpi/ic_launcher"
build_application_icon 48 "${BASE_DIR}/android/app/src/main/res/mipmap-mdpi/ic_launcher"
build_application_icon 96 "${BASE_DIR}/android/app/src/main/res/mipmap-xhdpi/ic_launcher"
build_application_icon 144 "${BASE_DIR}/android/app/src/main/res/mipmap-xxhdpi/ic_launcher"
build_application_icon 192 "${BASE_DIR}/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher"
build_application_icon 512 "${BASE_DIR}/fastlane/metadata/android/en-US/images/icon"
build_launch_image 72 "${BASE_DIR}/android/app/src/main/res/mipmap-hdpi/launch_image"
build_launch_image 48 "${BASE_DIR}/android/app/src/main/res/mipmap-mdpi/launch_image"
build_launch_image 96 "${BASE_DIR}/android/app/src/main/res/mipmap-xhdpi/launch_image"
build_launch_image 144 "${BASE_DIR}/android/app/src/main/res/mipmap-xxhdpi/launch_image"
build_launch_image 192 "${BASE_DIR}/android/app/src/main/res/mipmap-xxxhdpi/launch_image"
build_fastlane_image 1024 500 "${BASE_DIR}/fastlane/metadata/android/en-US/images/featureGraphic"
<?xml version="1.0" encoding="UTF-8"?>
<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 102 102" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><defs><radialGradient id="radialGradient876" cx="51" cy="51" r="51" gradientUnits="userSpaceOnUse"><stop stop-color="#94bc4f" offset=".53489"/><stop stop-color="#e84e34" offset="1"/></radialGradient></defs><rect x="1" y="1" width="100" height="100" ry="0" fill="url(#radialGradient876)" stroke="#000" stroke-width="2"/><path d="m50.952 32.393c1.3622-0.0046 4.9652 11.398 6.07 12.195 1.1048 0.79696 13.062 0.61914 13.487 1.9133s-9.3059 8.2444-9.7225 9.5414c-0.41657 1.297 3.4475 12.614 2.3481 13.418-1.0993 0.80441-10.717-6.3028-12.079-6.2982-1.3622 0.0046-10.931 7.1767-12.036 6.3797s2.6827-12.14 2.2574-13.434c-0.42533-1.2941-10.203-8.1785-9.7868-9.4754 0.41657-1.297 12.375-1.2 13.474-2.0044s4.6252-12.231 5.9874-12.236z" fill="#fff" stroke="#030303" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="6" stroke-width="3.3"/></svg>
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:random/provider/data.dart';
import 'package:random/screens/demo.dart';
import 'package:random/screens/home.dart';
void main() {
runApp(MyApp());
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((value) => runApp(MyApp()));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (BuildContext context) => Data(),
child: Consumer<Data>(builder: (context, data, child) {
return MaterialApp(
title: 'Flutter Demo',
title: 'Jeux de mots et lettres',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
home: Home(),
onGenerateRoute: (settings) {
switch (settings.name) {
case '/demo':
{
return MaterialPageRoute(
builder: (context) => DemoPage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
default:
{
print("Unknown menu entry: " + settings.name.toString());
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
break;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
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),
),
return null;
},
);
}),
);
}
}
import 'package:flutter/foundation.dart';
class Data extends ChangeNotifier {}
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:random/provider/data.dart';
class DemoPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
Data myProvider = Provider.of<Data>(context);
Scaffold pageContent = Scaffold(
appBar: AppBar(
elevation: 0,
actions: <Widget>[
IconButton(
icon: const Icon(Icons.loop),
onPressed: () => print(myProvider),
),
],
),
backgroundColor: Colors.blue,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Text('TOP'),
SizedBox(height: 2),
Text('BOTTOM'),
],
),
),
);
return SizedBox.expand(
child: Container(
child: FittedBox(
fit: BoxFit.contain,
alignment: Alignment.center,
child: SizedBox(
height: (MediaQuery.of(context).size.height),
width: (MediaQuery.of(context).size.width),
child: pageContent,
),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:random/provider/data.dart';
class Home extends StatelessWidget {
static const String id = 'home';
Future<void> resetGame(Data myProvider) async {}
@override
Widget build(BuildContext context) {
Data myProvider = Provider.of<Data>(context);
Container _buildMenuItemContainer(String code, Color color) {
double imageSize = 150;
String imageAsset = 'assets/menu/' + code + '.png';
return Container(
margin: EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Colors.teal,
width: 8,
),
),
child: TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(15),
backgroundColor: color,
),
child: Image(
image: AssetImage(imageAsset),
width: imageSize,
height: imageSize,
fit: BoxFit.fill,
),
onPressed: () {
resetGame(myProvider);
Navigator.pushNamed(
context,
'/' + code,
);
},
),
);
}
return Scaffold(
backgroundColor: Colors.blue,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
_buildMenuItemContainer('demo', Colors.pink),
],
),
),
);
}
}
......@@ -74,6 +74,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
......@@ -81,6 +88,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.4"
sky_engine:
dependency: transitive
description: flutter
......@@ -137,3 +151,4 @@ packages:
version: "2.1.2"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.16.0"
name: random
description: A random application.
publish_to: 'none'
publish_to: "none"
version: 1.0.0+1
environment:
......@@ -9,6 +9,7 @@ environment:
dependencies:
flutter:
sdk: flutter
provider: ^6.0.2
dev_dependencies:
flutter_test:
......@@ -16,3 +17,5 @@ dev_dependencies:
flutter:
uses-material-design: true
assets:
- assets/menu/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment