trphoenix
2018-10-30 f2dafcc61407aef960ee17b576794b1260e84a08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'empty_result_widget.dart';
import 'redux.dart';
import 'search_error_widget.dart';
import 'search_intro_widget.dart';
import 'search_loading_widget.dart';
import 'search_result_widget.dart';
import './SearchState.dart';
 
class SearchScreen extends StatelessWidget {
  SearchScreen({Key key}) : super(key: key);
 
  @override
  Widget build(BuildContext context) {
    return new StoreConnector<SearchState, SearchScreenViewModel>(
      converter: (store) {
        return SearchScreenViewModel(
          state: store.state,
          onTextChanged: (term) => store.dispatch(SearchAction(term)),
        );
      },
      builder: (BuildContext context, SearchScreenViewModel vm) {
        return new Scaffold(
          body: new Stack(
            children: <Widget>[
              new Flex(direction: Axis.vertical, children: <Widget>[
                new Container(
                  padding: new EdgeInsets.fromLTRB(16.0, 24.0, 16.0, 4.0),
                  child: new TextField(
                    decoration: new InputDecoration(
                      border: InputBorder.none,
                      hintText: 'Search Github...',
                    ),
                    style: new TextStyle(
                      fontSize: 36.0,
                      fontFamily: "Hind",
                      decoration: TextDecoration.none,
                    ),
                    onChanged: vm.onTextChanged,
                  ),
                ),
                new Expanded(
                  child: new Stack(
                    children: <Widget>[
                      // Fade in an intro screen if no term has been entered
                      new SearchIntroWidget(vm.state.result?.isNoTerm ?? false),
 
                      // Fade in an Empty Result screen if the search contained
                      // no items
                      new EmptyResultWidget(vm.state.result?.isEmpty ?? false),
 
                      // Fade in a loading screen when results are being fetched
                      // from Github
                      new SearchLoadingWidget(vm.state.isLoading ?? false),
 
                      // Fade in an error if something went wrong when fetching
                      // the results
                      new SearchErrorWidget(vm.state.hasError ?? false),
 
                      // Fade in the Result if available
                      new SearchResultWidget(vm.state.result),
                    ],
                  ),
                )
              ])
            ],
          ),
        );
      },
    );
  }
}
 
class SearchScreenViewModel {
  final SearchState state;
  final void Function(String term) onTextChanged;
 
  SearchScreenViewModel({this.state, this.onTextChanged});
}