105 lines
4.0 KiB
Dart
105 lines
4.0 KiB
Dart
import 'package:aman_kassa_flutter/core/entity/Category.dart';
|
|
import 'package:aman_kassa_flutter/core/entity/Goods.dart';
|
|
import 'package:aman_kassa_flutter/redux/actions/main_actions.dart';
|
|
import 'package:aman_kassa_flutter/redux/state/main_state.dart';
|
|
import 'package:aman_kassa_flutter/redux/store.dart';
|
|
import 'package:aman_kassa_flutter/shared/app_colors.dart';
|
|
import 'package:aman_kassa_flutter/shared/shared_styles.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_redux/flutter_redux.dart';
|
|
|
|
class CatalogBottomSheet extends StatelessWidget {
|
|
final ScrollController scrollController;
|
|
|
|
CatalogBottomSheet({this.scrollController});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return StoreConnector<AppState, MainState>(
|
|
converter: (store) => store.state.mainState,
|
|
onInit: (store) => Redux.store.dispatch(selectBottomElement(0)),
|
|
builder: (context, vm) {
|
|
return WillPopScope(
|
|
onWillPop: () {
|
|
if (vm.prevCategories.length > 0) {
|
|
Redux.store.dispatch(backBottomElement);
|
|
} else
|
|
Navigator.pop(context);
|
|
return new Future(() => false);
|
|
},
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(
|
|
vm.prevCategories.isNotEmpty
|
|
? vm.prevCategories?.last?.name
|
|
: '',
|
|
style: TextStyle(color: Colors.black45),
|
|
),
|
|
iconTheme: IconThemeData(color: Colors.black),
|
|
backgroundColor: whiteColor,
|
|
elevation: 3,
|
|
leading: IconButton(
|
|
icon: Icon(vm.prevCategories.length > 0
|
|
? Icons.arrow_back
|
|
: Icons.close),
|
|
onPressed: () {
|
|
if (vm.prevCategories.length > 0) {
|
|
Redux.store.dispatch(backBottomElement);
|
|
} else
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
),
|
|
body: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: ListView.builder(
|
|
controller: scrollController,
|
|
itemCount: vm.bottomSheetElements.length,
|
|
itemBuilder: (context, index) {
|
|
var el = vm.bottomSheetElements[index];
|
|
String name;
|
|
if (el is Category) {
|
|
Category category = el;
|
|
name = category.name;
|
|
} else if (el is Good) {
|
|
Good good = el;
|
|
name = good.name;
|
|
}
|
|
return Card(
|
|
child: ListTile(
|
|
leading: Icon(
|
|
el is Category ? Icons.layers : Icons.move_to_inbox,
|
|
size: 40,
|
|
),
|
|
title: Text(name),
|
|
onTap: () {
|
|
if (el is Category) {
|
|
Redux.store.dispatch(selectBottomElement(el.id));
|
|
}
|
|
},
|
|
trailing:
|
|
el is Category ? Icon(Icons.chevron_right) : null,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
RaisedButton(
|
|
child: Text(
|
|
'Отмена',
|
|
style: buttonBigTitleTextStyle,
|
|
),
|
|
color: redColor,
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
}),
|
|
],
|
|
)),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|