Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Home extends StatelessWidget {
- final String name;
- const Home({Key key, @required this.name}) : super(key: key);
- Widget _buildTabs(BuildContext context, activeTab) {
- if (activeTab == AppTab.tasks) {
- final TodosRepository todosRepository = TodosRepository();
- return BlocProvider(
- builder: (context) =>
- TodosBloc(todosRepository: todosRepository)..dispatch(LoadTodos()),
- child: Padding(
- padding: const EdgeInsets.only(top: 64.0, left: 8.0, right: 8.0),
- child: TasksTab(),
- ),
- );
- } else if (activeTab == AppTab.goals) {
- return GoalsTab();
- } else if (activeTab == AppTab.account) {
- return Container(
- child: Center(
- child: Text('Account Tab'),
- ),
- );
- } else {
- return Container();
- }
- }
- @override
- Widget build(BuildContext context) {
- final tabBloc = BlocProvider.of<TabBloc>(context);
- return BlocBuilder(
- bloc: tabBloc,
- builder: (BuildContext context, AppTab activeTab) {
- return Scaffold(
- body: _buildTabs(context, activeTab),
- floatingActionButton: FloatingActionButton(
- onPressed: () {},
- child: Icon(Icons.add),
- tooltip: 'Add Todod',
- ),
- bottomNavigationBar: TabSelector(
- activeTab: activeTab,
- onTabSelected: (tab) => tabBloc.dispatch(UpdateTab(tab)),
- ),
- );
- },
- );
- }
- }
- class TasksTabState extends State<TasksTab> with TickerProviderStateMixin {
- AnimationController _controller;
- Animation _animation;
- @override
- void initState() {
- super.initState();
- print("Called when tab is changed");
- _controller =
- AnimationController(vsync: this, duration: Duration(milliseconds: 100));
- _animation = Tween(begin: -1.0, end: 0.0).animate(CurvedAnimation(
- parent: _controller,
- curve: Curves.fastOutSlowIn,
- ))
- ..addStatusListener(handler);
- }
- @override
- void dispose() {
- _controller.dispose();
- print("Component Disposed");
- super.dispose();
- }
- void handler(status) {
- print(status);
- if (status == AnimationStatus.completed) {
- _animation.removeStatusListener(handler);
- _controller.reset();
- _animation = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
- parent: _controller,
- curve: Curves.easeOut,
- ))
- ..addStatusListener(handler);
- _controller.reverse();
- }
- }
- Widget todoCard(Todo todo) {
- print(todo.complete);
- final double width = MediaQuery.of(context).size.width;
- _controller.forward();
- return AnimatedBuilder(
- animation: _controller,
- builder: (BuildContext context, Widget child) {
- return Transform(
- transform:
- Matrix4.translationValues(_animation.value * width, 0.0, 0.0),
- child: ExpansionTile(
- leading: CircularCheckBox(
- activeColor: Colors.redAccent,
- value: todo.complete,
- materialTapTargetSize: MaterialTapTargetSize.padded,
- onChanged: (value) {
- print(value);
- print("Current todo: $todo");
- }),
- title: new Text(
- todo.task,
- style: new TextStyle(
- fontSize: 20.0,
- fontWeight: FontWeight.bold,
- fontStyle: FontStyle.italic),
- ),
- children: <Widget>[
- new Column(
- children: [Text(todo.note)],
- ),
- ],
- ));
- });
- }
- Widget _buildTodosList(context, snapshots) {
- return ListView.builder(
- itemCount: snapshots.length,
- physics: ScrollPhysics(),
- shrinkWrap: true,
- itemBuilder: (BuildContext context, int index) {
- return todoCard(Todo.fromSnapshot(snapshots[index]));
- },
- );
- }
- @override
- Widget build(BuildContext context) {
- return BlocBuilder(
- bloc: BlocProvider.of<TodosBloc>(context),
- builder: (BuildContext context, TodosState state) {
- if (state is TodosLoading) {
- return Container(
- child: Center(
- child: CircularProgressIndicator(),
- ),
- );
- }
- if (state is LoadTodos) {
- return Container(
- child: Center(
- child: CircularProgressIndicator(),
- ),
- );
- }
- if (state is TodosLoaded) {
- return Container(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text('Project Title'),
- Text('Project description'),
- StreamBuilder(
- stream: state.snapshotStream,
- builder: (BuildContext context, AsyncSnapshot snapshot) {
- return !snapshot.hasData
- ? Center(
- child: CircularProgressIndicator(),
- )
- : _buildTodosList(context, snapshot.data.documents);
- },
- ),
- ],
- ),
- );
- }
- },
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement