144 lines
4.0 KiB
Dart
144 lines
4.0 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:checker/resources.dart';
|
||
import 'package:checker/strings.dart';
|
||
import 'package:flutter/material.dart';
|
||
|
||
import 'package:checker/base/base_state.dart';
|
||
import 'package:checker/consts.dart';
|
||
import 'package:checker/common.dart';
|
||
|
||
/// Класс содержит заголовки и текст блоков FAQ.
|
||
class Entry {
|
||
Entry(this.title, this.text);
|
||
final String title;
|
||
final String text;
|
||
}
|
||
|
||
class EntryItem extends StatelessWidget {
|
||
|
||
const EntryItem(this.entry);
|
||
final Entry entry;
|
||
|
||
Widget _buildTiles(BuildContext context, Entry root) {
|
||
EdgeInsets margin = new EdgeInsets.only(left: 20.0, right: 20.0);
|
||
TextStyle titleStyle = Theme.of(context).textTheme.button.copyWith(
|
||
fontWeight: FontWeight.bold,
|
||
color: faqTitlesColor);
|
||
return new Container(margin: margin, child: new Card(
|
||
child: new ExpansionTile(
|
||
key: new PageStorageKey<Entry>(root),
|
||
title:new Text(
|
||
root.title,
|
||
style: titleStyle),
|
||
children: [
|
||
new Container(
|
||
margin: margin,
|
||
padding: new EdgeInsets.only(top: 12.0, bottom: 20.0),
|
||
child: new Text(
|
||
root.text,
|
||
style: new TextStyle(
|
||
fontWeight: FontWeight.w300,
|
||
color: faqGrey,
|
||
fontSize: 14.0)
|
||
),
|
||
decoration: new BoxDecoration(
|
||
border: new Border(
|
||
top: new BorderSide(
|
||
color: greyTextColor,
|
||
width: 0.5)
|
||
)
|
||
)
|
||
)
|
||
]
|
||
)
|
||
)
|
||
);
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return _buildTiles(context, entry);
|
||
}
|
||
}
|
||
|
||
class FAQScreen extends StatefulWidget {
|
||
|
||
FAQScreen(this.b);
|
||
final bool b;
|
||
|
||
@override State createState() => new FAQScreenState<FAQScreen>(b);
|
||
}
|
||
|
||
class FAQScreenState<T> extends BaseState<FAQScreen> {
|
||
|
||
FAQScreenState(this.returnToScanner);
|
||
|
||
bool returnToScanner;
|
||
|
||
List<Entry> data;
|
||
|
||
@override String getTitle() {
|
||
return StringsLocalization.help();
|
||
}
|
||
|
||
@override String getHintString() {
|
||
return null;
|
||
}
|
||
|
||
@override Widget build(BuildContext context) {
|
||
if (app == null) {
|
||
platform.invokeMethod('getFlavor').then((flavor) {
|
||
initPhoneAndUrl().then((_) {
|
||
setState(() {
|
||
app = flavor;
|
||
});
|
||
});
|
||
});
|
||
}
|
||
return new Scaffold(appBar: getAppBar(), body: getScreenContent());
|
||
}
|
||
|
||
Future initPhoneAndUrl() async {
|
||
initHelp(await platform.invokeMethod('getSupportPhone'),
|
||
await platform.invokeMethod('getSupportUrl'));
|
||
}
|
||
|
||
void initHelp(String phone, String url) {
|
||
data = <Entry>[
|
||
new Entry(StringsLocalization.registration(), StringsLocalization.registrationGuide()),
|
||
new Entry(StringsLocalization.usage(), StringsLocalization.usageGuide()),
|
||
new Entry(StringsLocalization.support(), StringsLocalization.supportGuide(phone, url)),
|
||
new Entry(StringsLocalization.common(), StringsLocalization.commonGuide())
|
||
];
|
||
}
|
||
|
||
@override List<Widget> getMenuButtons() {
|
||
return null;
|
||
}
|
||
|
||
/// Метод возвращает ListView с блоками faq.
|
||
@override Widget getScreenContent() {
|
||
if (data == null) {
|
||
return new Container(
|
||
decoration: new BoxDecoration(
|
||
image: new DecorationImage(
|
||
image: new ExactAssetImage(Resources.getSplash(app)),
|
||
fit: BoxFit.cover)));
|
||
} else {
|
||
return new WillPopScope(onWillPop: onWillPop, child: new ListView.builder(
|
||
itemBuilder: (BuildContext context, int index) =>
|
||
new EntryItem(data[index]),
|
||
itemCount: data.length));
|
||
}
|
||
}
|
||
|
||
onWillPop() {
|
||
if(returnToScanner) {
|
||
return startScanner(context, app, helper);
|
||
} else {
|
||
return true;
|
||
}
|
||
}
|
||
}
|