Skip to content

Commit

Permalink
change app Routing
Browse files Browse the repository at this point in the history
  • Loading branch information
devaziz0 committed Jul 3, 2019
1 parent c136f15 commit 17035c6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
7 changes: 3 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'redux/reducers.dart';
import 'package:redux_thunk/redux_thunk.dart';
import 'package:learning2/screens/feed/feed.dart';
void main() {
runApp(MyApp());
}
Expand All @@ -22,10 +23,8 @@ class MyApp extends StatelessWidget {
store:store ,
child: MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: MyStatelessWidget(),
),
home: FeedScreen(),

)
);

Expand Down
53 changes: 37 additions & 16 deletions lib/screens/feed/feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import 'package:learning2/redux/reducers.dart';
import 'package:redux/redux.dart';
import 'dart:async';
import 'package:learning2/main.dart';
import 'package:learning2/screens/main/main.dart';
import 'package:learning2/screens/feed/widgets/change_notification.dart';
//void main() => runApp(Feed());

class Feed extends StatefulWidget {
Feed({Key key}) : super(key: key);
class FeedScreen extends StatefulWidget {
FeedScreen({Key key}) : super(key: key);
static const String _title = 'Signalements';


@override
_FeedState createState() {
// TODO: implement createState
return _FeedState();
}
}

class _FeedState extends State<Feed> {
class _FeedState extends State<FeedScreen> {
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
new GlobalKey<RefreshIndicatorState>();
bool loading = false;
List<Anomaly> list;
List<Anomaly> list = [];
Timer timer;

@override
Expand All @@ -40,6 +40,18 @@ class _FeedState extends State<Feed> {
bool changed = await api.checkNewPosts(MyApp.store);
if (changed) MyApp.store.dispatch(new SetPostsChanged(changed: changed));
});
final getReactions = GetUserReactionAction([]);
final getAnomalies = GetAnomaliesAction([]);

MyApp.store.dispatch(getReactions.getReactions());
MyApp.store.dispatch(getAnomalies.getAnomalies());

Future.wait([
getAnomalies.completer.future,
getReactions.completer.future,
]).then((c) {

});
}

@override
Expand Down Expand Up @@ -70,6 +82,7 @@ class _FeedState extends State<Feed> {
)
],
),

body:
Stack(
alignment: Alignment.topCenter ,
Expand All @@ -92,23 +105,31 @@ class _FeedState extends State<Feed> {
child:PostList(posts: store.state.anomalies),
color: Colors.blueAccent,
onRefresh: () {
final getReactions = GetUserReactionAction([]);
final getAnomalies = GetAnomaliesAction([]);
store.dispatch(getReactions.getReactions());
store.dispatch(getAnomalies.getAnomalies());
Future.wait([
getAnomalies.completer.future,
getReactions.completer.future,
]).then((c) {
final getReactions = GetUserReactionAction([]);
final getAnomalies = GetAnomaliesAction([]);

store.dispatch(getReactions.getReactions());
store.dispatch(getAnomalies.getAnomalies());

Future.wait([
getAnomalies.completer.future,
getReactions.completer.future,
]).then((c) {

});
return getReactions.completer.future;
}),
],
)
),

floatingActionButton: FloatingActionButton(
onPressed: () {

Navigator.push(context, MaterialPageRoute(builder: (context) => PostScreenWidget()));
},
child: Icon(Icons.add),
backgroundColor: Colors.blue,
),
);
}
);
Expand Down
21 changes: 14 additions & 7 deletions lib/screens/main/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import 'package:learning2/models/app_state.dart';

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatefulWidget {
MyStatelessWidget({Key key}) : super(key: key);
class PostScreenWidget extends StatefulWidget {
PostScreenWidget({Key key}) : super(key: key);


@override
Expand All @@ -29,7 +29,7 @@ class MyStatelessWidget extends StatefulWidget {
}
}

class _MyStatefulWidgetState extends State<MyStatelessWidget> {
class _MyStatefulWidgetState extends State<PostScreenWidget> {
bool isLoading=false;
bool havePosition = false;
Position position;
Expand Down Expand Up @@ -67,7 +67,11 @@ class _MyStatefulWidgetState extends State<MyStatelessWidget> {

@override
Widget build(BuildContext context) {
return StoreConnector<AppState, bool>(

return Scaffold(
appBar: AppBar(title: const Text('Ajouter un post')),

body: StoreConnector<AppState, bool>(
converter: (store) => store.state.isLoading,
builder: (context, isLoading) => isLoading ? Center(child: CircularProgressIndicator(),)
:Center(
Expand Down Expand Up @@ -198,7 +202,7 @@ class _MyStatefulWidgetState extends State<MyStatelessWidget> {
onPressed: () async {
if (_formKey.currentState.validate()){
onSave(title,description, state.position.latitude.toString(), state.position.longitude.toString());
Navigator.push(context, MaterialPageRoute(builder: (context) => Feed()));
Navigator.pop(context);
}
},
)
Expand All @@ -224,7 +228,8 @@ class _MyStatefulWidgetState extends State<MyStatelessWidget> {
getAnomalies.completer.future,
getReactions.completer.future,
]).then((c) {
Navigator.push(context, MaterialPageRoute(builder: (context) => Feed()));

Navigator.pop(context);
});

});
Expand All @@ -238,9 +243,11 @@ class _MyStatefulWidgetState extends State<MyStatelessWidget> {
),
)
,
);
)


);

}

}
Expand Down

0 comments on commit 17035c6

Please sign in to comment.