1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 22:45:44 +00:00
AideDeJeu/aidedejeu_flutter/lib/main.dart

302 lines
8.4 KiB
Dart
Raw Normal View History

2020-02-21 14:49:39 +01:00
import 'package:aidedejeu_flutter/database.dart';
2020-02-19 15:50:44 +01:00
import 'package:aidedejeu_flutter/models/items.dart';
2020-02-14 01:36:31 +01:00
import 'package:flutter/material.dart';
2020-02-14 10:37:58 +01:00
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_svg/flutter_svg.dart';
2020-02-14 01:36:31 +01:00
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
2020-02-22 03:22:41 +01:00
title: 'Haches & Dés',
2020-02-14 01:36:31 +01:00
theme: ThemeData(
2020-02-22 03:22:41 +01:00
primarySwatch: Colors.deepOrange,
2020-02-14 01:36:31 +01:00
),
2020-02-14 10:37:58 +01:00
home: MyHomePage(id: 'index.md'),
2020-02-14 01:36:31 +01:00
);
}
}
class MyHomePage extends StatefulWidget {
2020-02-14 10:37:58 +01:00
MyHomePage({Key key, @required this.id}) : super(key: key);
2020-02-14 01:36:31 +01:00
2020-02-14 10:37:58 +01:00
final String id;
2020-02-14 01:36:31 +01:00
@override
2020-02-14 10:37:58 +01:00
_MyHomePageState createState() => _MyHomePageState(id: this.id);
2020-02-14 01:36:31 +01:00
}
class _MyHomePageState extends State<MyHomePage> {
2020-02-14 10:37:58 +01:00
_MyHomePageState({@required this.id});
final String id;
2020-02-14 01:36:31 +01:00
2020-02-19 15:50:44 +01:00
void setItem(Item item) {
2020-02-14 01:36:31 +01:00
setState(() {
2020-02-19 15:50:44 +01:00
this.item = item;
this.markdown =
item.Markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) {
2020-02-14 10:37:58 +01:00
return '';
});
2020-02-14 01:36:31 +01:00
});
}
2020-02-14 10:37:58 +01:00
String markdown = "";
2020-02-19 15:50:44 +01:00
Item item = null;
2020-02-14 10:37:58 +01:00
MarkdownStyleSheet styleSheet;
@override
void initState() {
super.initState();
ThemeData theme = ThemeData(
brightness: Brightness.light,
primaryColor: Colors.lightBlue[800],
accentColor: Colors.cyan[600],
fontFamily: 'LinuxLibertine',
textTheme: TextTheme(
2020-02-21 14:53:31 +01:00
headline: TextStyle(fontSize: 28.0, fontWeight: FontWeight.bold),
title: TextStyle(fontSize: 22.0, fontStyle: FontStyle.italic),
body1: TextStyle(fontSize: 16.0, fontFamily: 'Hind'),
2020-02-14 10:37:58 +01:00
),
);
2020-02-19 16:00:01 +01:00
styleSheet = MarkdownStyleSheet.fromTheme(theme).copyWith(
2020-02-14 10:37:58 +01:00
tableColumnWidth: IntrinsicColumnWidth(),
tableCellsPadding: EdgeInsets.all(0.2));
2020-02-19 16:47:28 +01:00
loadItem().then((item) => setItem(item));
2020-02-19 16:00:01 +01:00
}
2020-02-19 16:47:28 +01:00
Future<Item> loadItem() async {
2020-02-19 16:00:01 +01:00
var item = await getItemWithId(this.id);
var items = await loadChildrenItems(item);
2020-02-19 16:47:28 +01:00
//setItem(item);
return item;
2020-02-14 10:37:58 +01:00
}
2020-02-19 15:50:44 +01:00
Widget buildMarkdown(BuildContext context) {
return Markdown(
data: markdown,
styleSheet: styleSheet,
onTapLink: (link) => Navigator.push(
context,
2020-02-22 02:43:08 +01:00
MaterialPageRoute(builder: (context) => MyHomePage(id: link)),
2020-02-19 15:50:44 +01:00
),
);
}
2020-02-22 02:43:08 +01:00
2020-02-19 15:50:44 +01:00
Widget buildMarkdownBody(BuildContext context) {
return MarkdownBody(
data: markdown,
styleSheet: styleSheet,
onTapLink: (link) => Navigator.push(
context,
2020-02-22 02:43:08 +01:00
MaterialPageRoute(builder: (context) => MyHomePage(id: link)),
2020-02-19 15:50:44 +01:00
),
);
}
2020-02-22 02:43:08 +01:00
2020-02-19 15:50:44 +01:00
Widget buildChildTile(BuildContext context, Item item) {
return ListTile(
title: Text(item.Name),
2020-02-21 14:49:39 +01:00
subtitle: Text(item.AliasText ?? ""),
2020-02-19 15:50:44 +01:00
onTap: () => Navigator.push(
context,
2020-02-22 02:43:08 +01:00
MaterialPageRoute(builder: (context) => MyHomePage(id: item.Id)),
2020-02-19 15:50:44 +01:00
),
);
}
2020-02-21 14:49:39 +01:00
Widget buildLibraryPage() {
return Stack(
children: <Widget>[
ListView.builder(
2020-02-22 02:43:08 +01:00
itemCount: (item?.Children?.length ?? 0) + 1,
itemBuilder: (BuildContext context, int index) {
return index == 0
? buildMarkdownBody(context)
: buildChildTile(context, item.Children[index - 1]);
})
2020-02-21 14:49:39 +01:00
],
);
}
Widget buildBookmarksPage() {
return Text("Bookmarks");
}
Widget buildSearchPage() {
return Text("Search");
}
2020-02-22 02:43:08 +01:00
BottomNavigationBarItem buildBottomNavigationBarItem(
String title, String assetName) {
2020-02-21 14:49:39 +01:00
return BottomNavigationBarItem(
icon: SvgPicture.asset(
assetName,
height: 30.0,
width: 30.0,
allowDrawingOutsideViewBox: true,
),
title: Text(title),
activeIcon: SvgPicture.asset(
assetName,
height: 40.0,
width: 40.0,
allowDrawingOutsideViewBox: true,
),
);
}
List buildBottomNavigationBarItems() {
2020-02-22 02:43:08 +01:00
return <BottomNavigationBarItem>[
2020-02-21 14:49:39 +01:00
buildBottomNavigationBarItem("Bibliothèque", "assets/spell-book.svg"),
buildBottomNavigationBarItem("Favoris", "assets/stars-stack.svg"),
buildBottomNavigationBarItem("Recherche", "assets/crystal-ball.svg"),
];
}
int indexPage = 0;
2020-02-14 01:36:31 +01:00
@override
Widget build(BuildContext context) {
2020-02-21 14:49:39 +01:00
Widget currentPage;
2020-02-22 02:43:08 +01:00
switch (indexPage) {
2020-02-21 14:49:39 +01:00
case 0:
currentPage = buildLibraryPage();
break;
case 1:
currentPage = buildBookmarksPage();
break;
case 2:
currentPage = buildSearchPage();
break;
2020-02-19 15:50:44 +01:00
}
2020-02-22 02:43:08 +01:00
2020-02-14 01:36:31 +01:00
return Scaffold(
2020-02-22 03:22:41 +01:00
//appBar: AppBar(
// title: Text(widget.id),
//),
2020-02-21 14:49:39 +01:00
body: currentPage,
2020-02-14 10:37:58 +01:00
bottomNavigationBar: BottomNavigationBar(
2020-02-21 14:49:39 +01:00
currentIndex: indexPage,
onTap: (int index) {
setState(() {
this.indexPage = index;
2020-02-22 02:43:08 +01:00
});
2020-02-21 14:49:39 +01:00
},
items: buildBottomNavigationBarItems(),
2020-02-14 01:36:31 +01:00
),
2020-02-26 00:49:46 +01:00
endDrawer: item is FilteredItems ? Drawer(
2020-02-22 02:43:08 +01:00
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
2020-02-26 11:00:26 +01:00
children: (item as FilteredItems).toFilterMap().entries.map(
(filter) =>
//ListTile(title: Text(filter.key))
Container(
child: Wrap(
children: filter.value.toString().split("|").map(
(choice) =>
FilterChip(
label: Text(choice),
backgroundColor: Colors.transparent,
shape: StadiumBorder(side: BorderSide()),
onSelected: (bool value) {
print("selected");
},
)
).toList()/* <Widget>[
FilterChip(
label: Text("truc"),
backgroundColor: Colors.transparent,
shape: StadiumBorder(side: BorderSide()),
onSelected: (bool value) {
print("selected");
},
),
FilterChip(
label: Text("truc"),
backgroundColor: Colors.transparent,
shape: StadiumBorder(side: BorderSide()),
onSelected: (bool value) {
print("selected");
},
),
],*/
),
)
).toList()
/*<Widget>[
2020-02-22 02:43:08 +01:00
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
// Update the state of the app.
// ...
},
),
Container(
child: Wrap(
children: <Widget>[
FilterChip(
label: Text("truc"),
backgroundColor: Colors.transparent,
shape: StadiumBorder(side: BorderSide()),
onSelected: (bool value) {
print("selected");
},
),
FilterChip(
label: Text("truc"),
backgroundColor: Colors.transparent,
shape: StadiumBorder(side: BorderSide()),
onSelected: (bool value) {
print("selected");
},
),
],
),
),
2020-02-26 11:00:26 +01:00
],*/
2020-02-22 02:43:08 +01:00
),
2020-02-26 00:49:46 +01:00
) : null,
2020-02-22 03:22:41 +01:00
appBar: AppBar(
title: Text(widget.id),
2020-02-26 00:49:46 +01:00
actions: item is FilteredItems ? [
2020-02-22 03:22:41 +01:00
Builder(
builder: (context) => IconButton(
icon: SvgPicture.asset(
"assets/funnel.svg",
height: 30.0,
width: 30.0,
allowDrawingOutsideViewBox: true,
), //Icon(Icons.filter),
onPressed: () => Scaffold.of(context).openEndDrawer(),
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
),
),
2020-02-26 00:49:46 +01:00
] : null,
2020-02-22 03:22:41 +01:00
),
2020-02-14 01:36:31 +01:00
);
}
}