Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. class Home extends StatelessWidget {
  2. final String name;
  3.  
  4. const Home({Key key, @required this.name}) : super(key: key);
  5.  
  6. Widget _buildTabs(BuildContext context, activeTab) {
  7. if (activeTab == AppTab.tasks) {
  8. final TodosRepository todosRepository = TodosRepository();
  9. return BlocProvider(
  10. builder: (context) =>
  11. TodosBloc(todosRepository: todosRepository)..dispatch(LoadTodos()),
  12. child: Padding(
  13. padding: const EdgeInsets.only(top: 64.0, left: 8.0, right: 8.0),
  14. child: TasksTab(),
  15. ),
  16. );
  17. } else if (activeTab == AppTab.goals) {
  18. return GoalsTab();
  19. } else if (activeTab == AppTab.account) {
  20. return Container(
  21. child: Center(
  22. child: Text('Account Tab'),
  23. ),
  24. );
  25. } else {
  26. return Container();
  27. }
  28. }
  29.  
  30. @override
  31. Widget build(BuildContext context) {
  32. final tabBloc = BlocProvider.of<TabBloc>(context);
  33. return BlocBuilder(
  34. bloc: tabBloc,
  35. builder: (BuildContext context, AppTab activeTab) {
  36. return Scaffold(
  37. body: _buildTabs(context, activeTab),
  38. floatingActionButton: FloatingActionButton(
  39. onPressed: () {},
  40. child: Icon(Icons.add),
  41. tooltip: 'Add Todod',
  42. ),
  43. bottomNavigationBar: TabSelector(
  44. activeTab: activeTab,
  45. onTabSelected: (tab) => tabBloc.dispatch(UpdateTab(tab)),
  46. ),
  47. );
  48. },
  49. );
  50. }
  51. }
  52.  
  53. class TasksTabState extends State<TasksTab> with TickerProviderStateMixin {
  54. AnimationController _controller;
  55. Animation _animation;
  56.  
  57. @override
  58. void initState() {
  59. super.initState();
  60. print("Called when tab is changed");
  61. _controller =
  62. AnimationController(vsync: this, duration: Duration(milliseconds: 100));
  63.  
  64. _animation = Tween(begin: -1.0, end: 0.0).animate(CurvedAnimation(
  65. parent: _controller,
  66. curve: Curves.fastOutSlowIn,
  67. ))
  68. ..addStatusListener(handler);
  69. }
  70.  
  71. @override
  72. void dispose() {
  73. _controller.dispose();
  74. print("Component Disposed");
  75. super.dispose();
  76. }
  77.  
  78. void handler(status) {
  79. print(status);
  80. if (status == AnimationStatus.completed) {
  81. _animation.removeStatusListener(handler);
  82. _controller.reset();
  83. _animation = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
  84. parent: _controller,
  85. curve: Curves.easeOut,
  86. ))
  87. ..addStatusListener(handler);
  88. _controller.reverse();
  89. }
  90. }
  91.  
  92. Widget todoCard(Todo todo) {
  93. print(todo.complete);
  94. final double width = MediaQuery.of(context).size.width;
  95. _controller.forward();
  96. return AnimatedBuilder(
  97. animation: _controller,
  98. builder: (BuildContext context, Widget child) {
  99. return Transform(
  100. transform:
  101. Matrix4.translationValues(_animation.value * width, 0.0, 0.0),
  102. child: ExpansionTile(
  103. leading: CircularCheckBox(
  104. activeColor: Colors.redAccent,
  105. value: todo.complete,
  106. materialTapTargetSize: MaterialTapTargetSize.padded,
  107. onChanged: (value) {
  108. print(value);
  109. print("Current todo: $todo");
  110. }),
  111. title: new Text(
  112. todo.task,
  113. style: new TextStyle(
  114. fontSize: 20.0,
  115. fontWeight: FontWeight.bold,
  116. fontStyle: FontStyle.italic),
  117. ),
  118. children: <Widget>[
  119. new Column(
  120. children: [Text(todo.note)],
  121. ),
  122. ],
  123. ));
  124. });
  125. }
  126.  
  127. Widget _buildTodosList(context, snapshots) {
  128. return ListView.builder(
  129. itemCount: snapshots.length,
  130. physics: ScrollPhysics(),
  131. shrinkWrap: true,
  132. itemBuilder: (BuildContext context, int index) {
  133. return todoCard(Todo.fromSnapshot(snapshots[index]));
  134. },
  135. );
  136. }
  137.  
  138. @override
  139. Widget build(BuildContext context) {
  140. return BlocBuilder(
  141. bloc: BlocProvider.of<TodosBloc>(context),
  142. builder: (BuildContext context, TodosState state) {
  143. if (state is TodosLoading) {
  144. return Container(
  145. child: Center(
  146. child: CircularProgressIndicator(),
  147. ),
  148. );
  149. }
  150. if (state is LoadTodos) {
  151. return Container(
  152. child: Center(
  153. child: CircularProgressIndicator(),
  154. ),
  155. );
  156. }
  157. if (state is TodosLoaded) {
  158. return Container(
  159. child: Column(
  160. crossAxisAlignment: CrossAxisAlignment.start,
  161. children: <Widget>[
  162. Text('Project Title'),
  163. Text('Project description'),
  164. StreamBuilder(
  165. stream: state.snapshotStream,
  166. builder: (BuildContext context, AsyncSnapshot snapshot) {
  167. return !snapshot.hasData
  168. ? Center(
  169. child: CircularProgressIndicator(),
  170. )
  171. : _buildTodosList(context, snapshot.data.documents);
  172. },
  173. ),
  174. ],
  175. ),
  176. );
  177. }
  178. },
  179. );
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement