From 28fd23b2d1071843f8015c697c4b84df98d5b93b Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Sun, 1 Mar 2020 19:04:48 +0100 Subject: [PATCH] Theme + localize --- .gitignore | 1 + aidedejeu_flutter/lib/main.dart | 20 +-- aidedejeu_flutter/lib/theme.dart | 30 ++++ aidedejeu_flutter/lib/widgets/library.dart | 8 +- aidedejeu_flutter/lib/widgets/pceditor.dart | 179 ++++++++++++-------- aidedejeu_flutter/pubspec.lock | 112 +++++++++++- aidedejeu_flutter/pubspec.yaml | 3 + 7 files changed, 257 insertions(+), 96 deletions(-) create mode 100644 aidedejeu_flutter/lib/theme.dart diff --git a/.gitignore b/.gitignore index add0d743..276d4d65 100644 --- a/.gitignore +++ b/.gitignore @@ -265,3 +265,4 @@ __pycache__/ /Ignore /AideDeJeu/AideDeJeuWeb/Properties/PublishProfiles/AideDeJeuWeb - Web Deploy.pubxml *.lock +*.lock diff --git a/aidedejeu_flutter/lib/main.dart b/aidedejeu_flutter/lib/main.dart index 6a79ca61..8bbb2344 100644 --- a/aidedejeu_flutter/lib/main.dart +++ b/aidedejeu_flutter/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:aidedejeu_flutter/theme.dart'; import 'package:aidedejeu_flutter/widgets/homepage.dart'; import 'package:flutter/material.dart'; @@ -8,24 +9,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Haches & Dés', - theme: ThemeData( - primarySwatch: Colors.deepOrange, - appBarTheme: AppBarTheme( - color: Colors.white, - iconTheme: IconThemeData(color: Colors.black), - textTheme: TextTheme( - headline6: TextStyle(fontSize: 28.0, color: Colors.black, fontWeight: FontWeight.bold, fontFamily: 'Cinzel')), - ), - brightness: Brightness.light, - primaryColor: Colors.lightBlue[800], - accentColor: Colors.cyan[600], - fontFamily: 'LinuxLibertine', - textTheme: TextTheme( - headline5: TextStyle(fontSize: 28.0, fontWeight: FontWeight.bold, fontFamily: 'Cinzel'), - headline6: TextStyle(fontSize: 22.0, fontStyle: FontStyle.normal), - bodyText2: TextStyle(fontSize: 16.0), - ), - ), + theme: mainTheme(), home: HomePage(), ); } diff --git a/aidedejeu_flutter/lib/theme.dart b/aidedejeu_flutter/lib/theme.dart new file mode 100644 index 00000000..c029c420 --- /dev/null +++ b/aidedejeu_flutter/lib/theme.dart @@ -0,0 +1,30 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; + +ThemeData mainTheme() { + return ThemeData( + primarySwatch: Colors.deepOrange, + appBarTheme: AppBarTheme( + color: Colors.white, + iconTheme: IconThemeData(color: Colors.black), + textTheme: TextTheme( + headline6: TextStyle(fontSize: 28.0, color: Colors.black, fontWeight: FontWeight.bold, fontFamily: 'Cinzel')), + ), + brightness: Brightness.light, + primaryColor: Colors.lightBlue[800], + accentColor: Colors.cyan[600], + fontFamily: 'LinuxLibertine', + textTheme: TextTheme( + headline5: TextStyle(fontSize: 28.0, fontWeight: FontWeight.bold, fontFamily: 'Cinzel'), + headline6: TextStyle(fontSize: 22.0, fontStyle: FontStyle.normal), + bodyText2: TextStyle(fontSize: 16.0), + ), + ); +} + +MarkdownStyleSheet mainMarkdownStyleSheet(BuildContext context) { + return MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith( + tableColumnWidth: IntrinsicColumnWidth(), + tableCellsPadding: EdgeInsets.all(0.2), + ); +} \ No newline at end of file diff --git a/aidedejeu_flutter/lib/widgets/library.dart b/aidedejeu_flutter/lib/widgets/library.dart index 9d1501b4..923e6368 100644 --- a/aidedejeu_flutter/lib/widgets/library.dart +++ b/aidedejeu_flutter/lib/widgets/library.dart @@ -7,6 +7,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import '../theme.dart'; + class LibraryPage extends StatefulWidget { LibraryPage({Key key, @required this.id}) : super(key: key); @@ -48,10 +50,8 @@ class _LibraryPageState extends State { @protected @mustCallSuper void didChangeDependencies() { - styleSheet = MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith( - tableColumnWidth: IntrinsicColumnWidth(), - tableCellsPadding: EdgeInsets.all(0.2), - ); + super.didChangeDependencies(); + styleSheet = mainMarkdownStyleSheet(context); } Future _loadItem() async { diff --git a/aidedejeu_flutter/lib/widgets/pceditor.dart b/aidedejeu_flutter/lib/widgets/pceditor.dart index d190d09d..e98c1bbb 100644 --- a/aidedejeu_flutter/lib/widgets/pceditor.dart +++ b/aidedejeu_flutter/lib/widgets/pceditor.dart @@ -81,68 +81,77 @@ class _PCEditorPageState extends State { } Widget _loadRaceSubRaceWidget() { - return _race != null ? Column( - children: [ - Text("Augmentation de caractéristiques"), - MarkdownBody( - data: (_race?.abilityScoreIncrease ?? "") + - "\n\n" + - (_subRace?.abilityScoreIncrease ?? ""), - onTapLink: (link) => Navigator.push( - context, - MaterialPageRoute(builder: (context) => LibraryPage(id: link)), - ), - ), - Text("Âge"), - MarkdownBody( - data: _race?.age ?? "", - onTapLink: (link) => Navigator.push( - context, - MaterialPageRoute(builder: (context) => LibraryPage(id: link)), - ), - ), - Text("Alignement"), - MarkdownBody( - data: _race?.alignment ?? "", - onTapLink: (link) => Navigator.push( - context, - MaterialPageRoute(builder: (context) => LibraryPage(id: link)), - ), - ), - Text("Taille"), - MarkdownBody( - data: _race?.size ?? "", - onTapLink: (link) => Navigator.push( - context, - MaterialPageRoute(builder: (context) => LibraryPage(id: link)), - ), - ), - Text("Vitesse"), - MarkdownBody( - data: _race?.speed ?? "", - onTapLink: (link) => Navigator.push( - context, - MaterialPageRoute(builder: (context) => LibraryPage(id: link)), - ), - ), - Text("Vision dans le noir"), - MarkdownBody( - data: _race?.darkvision ?? "", - onTapLink: (link) => Navigator.push( - context, - MaterialPageRoute(builder: (context) => LibraryPage(id: link)), - ), - ), - Text("Langues"), - MarkdownBody( - data: _race?.languages ?? "", - onTapLink: (link) => Navigator.push( - context, - MaterialPageRoute(builder: (context) => LibraryPage(id: link)), - ), - ), - ], - ): SizedBox.shrink(); + return _race != null + ? Column( + children: [ + Text("Augmentation de caractéristiques"), + MarkdownBody( + data: (_race?.abilityScoreIncrease ?? "") + + "\n\n" + + (_subRace?.abilityScoreIncrease ?? ""), + onTapLink: (link) => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage(id: link)), + ), + ), + Text("Âge"), + MarkdownBody( + data: _race?.age ?? "", + onTapLink: (link) => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage(id: link)), + ), + ), + Text("Alignement"), + MarkdownBody( + data: _race?.alignment ?? "", + onTapLink: (link) => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage(id: link)), + ), + ), + Text("Taille"), + MarkdownBody( + data: _race?.size ?? "", + onTapLink: (link) => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage(id: link)), + ), + ), + Text("Vitesse"), + MarkdownBody( + data: _race?.speed ?? "", + onTapLink: (link) => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage(id: link)), + ), + ), + Text("Vision dans le noir"), + MarkdownBody( + data: _race?.darkvision ?? "", + onTapLink: (link) => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage(id: link)), + ), + ), + Text("Langues"), + MarkdownBody( + data: _race?.languages ?? "", + onTapLink: (link) => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LibraryPage(id: link)), + ), + ), + ], + ) + : SizedBox.shrink(); } Widget _loadSubRacesWidget() { @@ -167,18 +176,42 @@ class _PCEditorPageState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text("Personnage"), + return DefaultTabController( + length: 3, + child: Scaffold( + appBar: AppBar( + title: Text("Personnage"), + bottom: TabBar( + tabs: [ + Text( + "Race", + style: TextStyle(color: Colors.black), + ), + Text( + "Historique", + style: TextStyle(color: Colors.black), + ), + Text( + "Classe", + style: TextStyle(color: Colors.black), + ), + ], + ), + ), + body: TabBarView( + children: [ + ListView( + children: [ + _loadRacesWidget(), + _loadSubRacesWidget(), + _loadRaceSubRaceWidget(), + ], + ), + Text(""), + Text(""), + ], + ), ), - body: ListView( - children: [ - _loadRacesWidget(), - _loadSubRacesWidget(), - _loadRaceSubRaceWidget() - ], - ), - ); } } diff --git a/aidedejeu_flutter/pubspec.lock b/aidedejeu_flutter/pubspec.lock index a774e828..03ddf963 100644 --- a/aidedejeu_flutter/pubspec.lock +++ b/aidedejeu_flutter/pubspec.lock @@ -1,6 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + analyzer: + dependency: transitive + description: + name: analyzer + url: "https://pub.dartlang.org" + source: hosted + version: "0.39.4" archive: dependency: transitive description: @@ -64,6 +78,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.3" + csslib: + dependency: transitive + description: + name: csslib + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" cupertino_icons: dependency: "direct main" description: @@ -71,6 +92,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + dart_style: + dependency: transitive + description: + name: dart_style + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.3" flutter: dependency: "direct main" description: flutter @@ -83,6 +111,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.2.0" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_markdown: dependency: "direct main" description: @@ -102,6 +135,20 @@ packages: description: flutter source: sdk version: "0.0.0" + glob: + dependency: transitive + description: + name: glob + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + html: + dependency: transitive + description: + name: html + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.0+3" image: dependency: transitive description: @@ -109,6 +156,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.4" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" + intl_translation: + dependency: "direct dev" + description: + name: intl_translation + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.9" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.1+1" markdown: dependency: transitive description: @@ -137,6 +205,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.4" + node_interop: + dependency: transitive + description: + name: node_interop + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + node_io: + dependency: transitive + description: + name: node_io + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1+2" + package_config: + dependency: transitive + description: + name: package_config + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.1" path: dependency: "direct main" description: @@ -179,6 +268,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.4" + pub_semver: + dependency: transitive + description: + name: pub_semver + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.3" quiver: dependency: transitive description: @@ -268,6 +364,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + watcher: + dependency: transitive + description: + name: watcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.9.7+13" xml: dependency: transitive description: @@ -275,6 +378,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.5.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" sdks: - dart: ">=2.6.0 <3.0.0" + dart: ">=2.7.0 <3.0.0" flutter: ">=1.12.1 <2.0.0" diff --git a/aidedejeu_flutter/pubspec.yaml b/aidedejeu_flutter/pubspec.yaml index a28d70cf..34665840 100644 --- a/aidedejeu_flutter/pubspec.yaml +++ b/aidedejeu_flutter/pubspec.yaml @@ -19,6 +19,8 @@ environment: dependencies: flutter: sdk: flutter + flutter_localizations: + sdk: flutter flutter_markdown: ^0.3.3 sqflite: path: @@ -32,6 +34,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + intl_translation: # For information on the generic Dart part of this file, see the