Skip to content

Instantly share code, notes, and snippets.

@Hellomik2002
Last active December 11, 2019 13:58
Show Gist options
  • Save Hellomik2002/4ec21c5aa9127952922db05de9f87d31 to your computer and use it in GitHub Desktop.
Save Hellomik2002/4ec21c5aa9127952922db05de9f87d31 to your computer and use it in GitHub Desktop.
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:grata/components/molecules/service-card.dart';
import 'package:grata/helpers/forListview.dart';
import 'package:grata/providers/data.dart';
import 'package:grata/providers/instit.dart';
import 'package:grata/screens/components/molecules/single-app-bar.dart';
import 'package:grata/screens/components/molecules/positioned-card.dart';
import 'package:grata/screens/components/pages/timeandOrder.dart';
import 'package:grata/screens/models/single-instit-model.dart';
import 'package:provider/provider.dart';
class SingleInstitutionArg {
final String institutionId;
SingleInstitutionArg({@required this.institutionId});
}
class SingleInstitution extends StatefulWidget {
static const String routeName = "singleProduct";
@override
_SingleInstitutionState createState() => _SingleInstitutionState();
}
class _SingleInstitutionState extends State<SingleInstitution> with SingleTickerProviderStateMixin{
double deviceWidth = 0;
double _opacityMainCard = 1;
final ScrollController _controller = ScrollController();
double offsetDis = 120;
Institution institution;
DataProvider dataProvider;
final ValueNotifier<double> cardOpacity = ValueNotifier<double>(1);
Future<void> _upadteOpacityCard() {
if (_controller.offset < offsetDis) {
double newV = math.pow((_controller.offset - offsetDis) / offsetDis, 2);
newV = math.pow(newV, 4);
cardOpacity.value = newV;
} else {
if (cardOpacity.value != 0) {
// setState(() {
// _opacityMainCard = 0;
// });
cardOpacity.value = 0;
}
}
return null;
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
final SingleInstitutionArg args = ModalRoute.of(context).settings.arguments;
final value = Provider.of<DataProvider>(context);
final actualValue = value.institutions
.firstWhere((value) => value.id == args.institutionId);
if (dataProvider != value) {
dataProvider = value;
value.getServiceByInstitutionId(args.institutionId);
this.institution = actualValue;
}
}
@override
void initState() {
super.initState();
_controller..addListener(_upadteOpacityCard);
}
@override
void dispose() {
super.dispose();
cardOpacity?.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
return SingleInstitutionAncestor(
child: Scaffold(
backgroundColor: Color.fromRGBO(244, 244, 244, 1),
floatingActionButton: FloatingActionButton(
elevation: 1,
backgroundColor: Colors.orange,
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => OrderWidget()));
},
child: Icon(Icons.check),
),
bottomSheet: Container(
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
),
),
padding:
const EdgeInsets.only(left: 36, right: 36, top: 8, bottom: 8),
child: FittedBox(
// fit: BoxFit.cover,
child: Text(
"ORDER 3 FOR KZT 500000",
style: TextStyle(color: Colors.orange),
),
),
height: 60,
),
body: Stack(
children: <Widget>[
ScrollConfiguration(
behavior: MyBehavior(),
child: CustomScrollView(
controller: _controller,
slivers: <Widget>[
SingleAppBar(imagePath: institution.imageBackgroundUrl),
SliverList(
delegate: SliverChildListDelegate([
SizedBox(
height: 100,
),
Column(
children: dataProvider.currentServices.map<Widget>(
(value) {
return ServiceCard(value);
},
).toList(),
),
Column(
children: dataProvider.currentServices.map<Widget>(
(value) {
return ServiceCard(value);
},
).toList(),
),
SizedBox(height: 600),
]),
)
],
),
),
PositionedCard(cardOpacity.value, institution.name),
],
),
),
);
}
}
// assets/logo_hey.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment