Initial commit

This commit is contained in:
vjrj 2018-06-29 00:57:21 +02:00
parent e46f792c49
commit 85cff9dba8
20 changed files with 663 additions and 0 deletions

16
comunes_flutter.iml Normal file
View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

143
lib/appIntroPage.dart Normal file
View file

@ -0,0 +1,143 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
// import 'package:padder/padding.dart';
import 'comunes_flutter.dart';
class AppIntroItem {
final IconData icon;
final String title;
final String subTitle;
AppIntroItem({this.icon, this.title, this.subTitle = ''});
// 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec vitae eros. Nunc sit amet neque. Ut id dui. Integer viverra feugiat sem. Morbi aliquam turpis rhoncus sapien volutpat condimentum.'});
}
typedef void OnIntroFinish(BuildContext context);
typedef List<AppIntroItem> ListItems(BuildContext context);
abstract class AppIntroPage extends StatelessWidget {
static const String routeName = '/appintro';
final ListItems items;
final OnIntroFinish onIntroFinish;
const AppIntroPage({Key key, this.items, this.onIntroFinish})
: super(key: key);
@override
Widget build(BuildContext context) {
return new Scaffold(
// appBar: new AppBar(),
body: new DefaultTabController(
length: items(context).length,
child: new _AppIntroPageSelector(items: items, onFinish: onIntroFinish),
),
);
}
}
class _AppIntroPageSelector extends StatelessWidget {
const _AppIntroPageSelector({this.items, this.onFinish});
final ListItems items;
final OnIntroFinish onFinish;
void _handleArrowButtonPress(BuildContext context, int delta) {
final TabController controller = DefaultTabController.of(context);
if (!controller.indexIsChanging)
controller
.animateTo((controller.index + delta).clamp(0, items(context).length - 1));
}
@override
Widget build(BuildContext context) {
final TabController controller = DefaultTabController.of(context);
final ThemeData theme = Theme.of(context);
final Color color = theme.accentColor;
final TextStyle titleStyle =
theme.textTheme.headline.copyWith(color: color);
final TextStyle subTitleStyle =
theme.textTheme.subhead; //.copyWith(color: color);
// final TextStyle descriptionStyle = theme.textTheme.subhead;
return new SafeArea(
top: true,
bottom: false,
child: new Column(
children: <Widget>[
new Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
new IconButton(
onPressed: () {
onFinish(context);
},
icon: new Icon(Icons.close, size: 30.0, color: Colors.black38)),
]),
new Expanded(
child: new OrientationBuilder(builder: (context, orientation) {
return new IconTheme(
data: new IconThemeData(
size: orientation == Orientation.portrait ? 200.0 : 100.0,
color: color,
),
child: new TabBarView(
children: items(context).map((AppIntroItem item) {
return new Container(
padding: const EdgeInsets.all(12.0),
child: new Center(
child: new CenteredSpaceEvenlyColumn(children: <Widget>[
Icon(
item.icon,
semanticLabel: item.title,
),
new Padding(
padding: new EdgeInsets.only(left: 16.0, right: 16.0),
child: new CenteredColumn(children: <Widget>[
new Text(
item.title,
style: titleStyle,
textAlign: TextAlign.center,
),
new SizedBox(height: 20.0),
new Text(
item.subTitle,
style: subTitleStyle,
textAlign: TextAlign.center,
)
])),
]),
),
);
}).toList()),
);
})),
new Container(
margin: const EdgeInsets.only(top: 16.0),
child: new Row(
children: listWithoutNulls(<Widget>[
new IconButton(
icon: const Icon(Icons.chevron_left),
color: color,
onPressed: () {
_handleArrowButtonPress(context, -1);
},
tooltip: 'Page back'),
new TabPageSelector(controller: controller),
new IconButton(
icon: const Icon(Icons.chevron_right),
color: color,
onPressed: () {
_handleArrowButtonPress(context, 1);
if (!controller.indexIsChanging &&
controller.index == items(context).length - 1) {
onFinish(context);
}
},
tooltip: 'Page forward'),
]),
mainAxisAlignment: MainAxisAlignment.spaceBetween)),
],
),
);
}
}

17
lib/comunes_flutter.dart Normal file
View file

@ -0,0 +1,17 @@
export 'layout/centeredMaxWidget.dart';
export 'layout/centeredRow.dart';
export 'layout/centeredColumn.dart';
export 'layout/centeredSpaceBetweenColumn.dart';
export 'layout/centeredSpaceBetweenRow.dart';
export 'layout/centeredSpaceAroundRow.dart';
export 'layout/centeredSpaceAroundColumn.dart';
export 'layout/centeredSpaceEvenlyRow.dart';
export 'layout/centeredSpaceEvenlyColumn.dart';
export 'widgets/roundedButton.dart';
export 'utils/utils.dart';
export 'utils/secretLoader.dart';
export 'appIntroPage.dart';
export 'materialAppWithIntro.dart';

78
lib/generated/i18n.dart Normal file
View file

@ -0,0 +1,78 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: camel_case_types
// ignore_for_file: prefer_single_quotes
//This file is automatically generated. DO NOT EDIT, all your changes would be lost.
class S implements WidgetsLocalizations {
const S();
static const GeneratedLocalizationsDelegate delegate =
const GeneratedLocalizationsDelegate();
static S of(BuildContext context) =>
Localizations.of<S>(context, WidgetsLocalizations);
@override
TextDirection get textDirection => TextDirection.ltr;
}
class en extends S {
const en();
}
class GeneratedLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocalizations> {
const GeneratedLocalizationsDelegate();
List<Locale> get supportedLocales {
return const <Locale>[
const Locale("en", ""),
];
}
LocaleResolutionCallback resolution({Locale fallback}) {
return (Locale locale, Iterable<Locale> supported) {
final Locale languageLocale = new Locale(locale.languageCode, "");
if (supported.contains(locale))
return locale;
else if (supported.contains(languageLocale))
return languageLocale;
else {
final Locale fallbackLocale = fallback ?? supported.first;
return fallbackLocale;
}
};
}
@override
Future<WidgetsLocalizations> load(Locale locale) {
final String lang = getLang(locale);
switch (lang) {
case "en":
return new SynchronousFuture<WidgetsLocalizations>(const en());
default:
return new SynchronousFuture<WidgetsLocalizations>(const S());
}
}
@override
bool isSupported(Locale locale) => supportedLocales.contains(locale);
@override
bool shouldReload(GeneratedLocalizationsDelegate old) => false;
}
String getLang(Locale l) => l.countryCode != null && l.countryCode.isEmpty
? l.languageCode
: l.toString();

View file

@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
abstract class AbstractCenteredColumn extends Column {
AbstractCenteredColumn({
Key key,
MainAxisAlignment mainAxisAlignment,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: mainAxisAlignment,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
textDirection: textDirection,
verticalDirection: VerticalDirection.down,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
abstract class AbstractCenteredRow extends Row {
AbstractCenteredRow({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
mainAxisAlignment,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: mainAxisAlignment,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
textDirection: textDirection,
verticalDirection: VerticalDirection.down,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredColumn.dart';
class CenteredColumn extends AbstractCenteredColumn {
CenteredColumn({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.center,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'centeredColumn.dart';
import 'centeredRow.dart';
class CenteredMaxWidget extends CenteredColumn {
CenteredMaxWidget({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: <Widget>[new CenteredRow(children: children)],
key: key,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredRow.dart';
class CenteredRow extends AbstractCenteredRow {
CenteredRow({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.center,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredColumn.dart';
class CenteredSpaceAroundColumn extends AbstractCenteredColumn {
CenteredSpaceAroundColumn({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.spaceAround,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredRow.dart';
class CenteredSpacedAroundRow extends AbstractCenteredRow {
CenteredSpacedAroundRow({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.spaceAround,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredColumn.dart';
class CenteredSpaceBetweenColumn extends AbstractCenteredColumn {
CenteredSpaceBetweenColumn({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredRow.dart';
class CenteredSpacedBetweenRow extends AbstractCenteredRow {
CenteredSpacedBetweenRow({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredColumn.dart';
class CenteredSpaceEvenlyColumn extends AbstractCenteredColumn {
CenteredSpaceEvenlyColumn({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'abstractCenteredRow.dart';
class CenteredSpacedEvenlyRow extends AbstractCenteredRow {
CenteredSpacedEvenlyRow({
Key key,
TextDirection textDirection,
TextBaseline textBaseline,
List<Widget> children: const <Widget>[],
}) : super(
children: children,
key: key,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
textDirection: textDirection,
textBaseline: textBaseline,
);
}

View file

@ -0,0 +1,81 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:async';
abstract class MaterialAppWithIntro extends StatelessWidget {
final String name;
final ThemeData theme;
final Map<String, WidgetBuilder> routes;
final WidgetBuilder introWidget;
final WidgetBuilder continueWidget;
final String prefsKey;
MaterialAppWithIntro(this.name, this.theme, this.routes, this.introWidget,
this.continueWidget, this.prefsKey);
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new MaterialAppWithIntroHome(introWidget, continueWidget, prefsKey),
title: name,
theme: theme,
routes: routes);
}
}
class MaterialAppWithIntroHome extends StatefulWidget {
final WidgetBuilder introWidget;
final WidgetBuilder continueWidget;
final String prefsKey;
MaterialAppWithIntroHome(this.introWidget, this.continueWidget, this.prefsKey);
@override
_MaterialAppWithIntroState createState() =>
_MaterialAppWithIntroState(introWidget, continueWidget, prefsKey);
}
class _MaterialAppWithIntroState extends State<MaterialAppWithIntroHome> {
final WidgetBuilder introWidget;
final WidgetBuilder continueWidget;
final String prefsKey;
_MaterialAppWithIntroState(this.introWidget, this.continueWidget, this.prefsKey);
@override
void initState() {
super.initState();
new Timer(new Duration(milliseconds: 1000), () {
checkFirstStart();
});
}
// https://stackoverflow.com/questions/50654195/flutter-one-time-intro-screen
Future checkFirstStart() async {
final String initialWizardKey = prefsKey;
SharedPreferences prefs = await SharedPreferences.getInstance();
bool showInitialWizard = (prefs.getBool(initialWizardKey) ?? true);
if (showInitialWizard) {
prefs.setBool(initialWizardKey, false);
print('Show initial intro at first start');
Navigator
.of(context)
.pushReplacement(new MaterialPageRoute(builder: this.introWidget));
} else {
print('Don\'t show initial intro ');
Navigator
.of(context)
.pushReplacement(new MaterialPageRoute(builder: this.continueWidget));
}
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new CircularProgressIndicator(),// Loading...
),
);
}
}

View file

@ -0,0 +1,17 @@
import 'dart:async' show Future;
import 'dart:convert' show json;
import 'package:flutter/services.dart' show rootBundle;
class SecretLoader {
final String secretPath;
SecretLoader({this.secretPath});
Future<Map<String, dynamic>> load() {
rootBundle.loadString(secretPath, cache: false);
return rootBundle.loadStructuredData<Map<String, dynamic>>(this.secretPath,
(jsonStr) async {
return json.decode(jsonStr);
});
}
}

11
lib/utils/utils.dart Normal file
View file

@ -0,0 +1,11 @@
import 'package:flutter/material.dart';
bool notNull(Object o) => o != null;
// What is the best way to optionally include a widget in a list of children
// https://github.com/flutter/flutter/issues/3783
List<Widget> listWithoutNulls(List<Widget> children) =>
children.where(notNull).toList();
ellipse(String s,[ int end = 4]) => s != null ? s.substring(0, end) + '...' : null;

View file

@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
class RoundedBtn extends StatelessWidget {
final btnRadius = new Radius.circular(90.0);
final IconData icon;
final String text;
final Color backColor;
final Color fontColor;
final TextStyle textStyle;
VoidCallback onPressed;
RoundedBtn(
{@required this.icon,
@required this.text,
@required this.onPressed,
@required this.backColor,
this.textStyle = const TextStyle(fontSize: 20.0, color: Colors.white),
this.fontColor = Colors.white});
RoundedBtn.nav(
{@required this.icon,
@required this.text,
@required BuildContext context,
@required route,
@required this.backColor,
this.textStyle = const TextStyle(fontSize: 20.0, color: Colors.white),
this.fontColor = Colors.white}) {
this.onPressed = () {
Navigator.pushNamed(context, route);
};
}
@override
Widget build(BuildContext context) {
return new SizedBox(
child: new RaisedButton(
elevation: 1.0,
color: backColor,
child: new Padding(
padding: const EdgeInsets.all(10.0),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Icon(icon, size: 32.0, color: fontColor),
new SizedBox(width: 10.0),
new Text(text, style: textStyle),
],
),
),
onPressed: onPressed,
shape: new RoundedRectangleBorder(
borderRadius: BorderRadius.all(btnRadius))),
);
}
}

51
pubspec.yaml Normal file
View file

@ -0,0 +1,51 @@
name: comunes_flutter
description: Comunes flutter and dart libs
version: 0.0.12
author:
homepage:
dependencies:
flutter:
sdk: flutter
shared_preferences: "^0.4.2"
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.io/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.io/custom-fonts/#from-packages