index_page.dart 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_redux/flutter_redux.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:redux/redux.dart';
  5. import 'package:redux_thunk/redux_thunk.dart';
  6. import 'package:flutter_2048/service/gameInit.dart';
  7. import 'package:flutter_2048/views/blocks.dart';
  8. import 'package:flutter_2048/views/scores.dart';
  9. import '../views/game_bg.dart';
  10. import '../views/mode_selector.dart';
  11. import '../views/playground.dart';
  12. import '../model/display.dart';
  13. import '../reducers/index.dart';
  14. import '../store/game_state.dart';
  15. /// 首页
  16. class IndexPage extends StatelessWidget {
  17. @override
  18. Widget build(BuildContext context) {
  19. ScreenUtil.init(context, designSize: Size(360, 640));
  20. return StoreProvider(
  21. store: Store<GameState>(
  22. gameReducer,
  23. middleware: [thunkMiddleware],
  24. initialState: GameState.initial(4),
  25. ),
  26. child: StoreConnector<GameState, GameProps>(
  27. converter: (store) =>
  28. GameProps(started: store.state.status.total != null),
  29. onInit: (store) {
  30. gameInit(store, 4);
  31. },
  32. builder: (context, props) {
  33. return props.started
  34. ? Container(
  35. margin: EdgeInsets.all(Display.borderMargin),
  36. child: Column(
  37. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  38. crossAxisAlignment: CrossAxisAlignment.stretch,
  39. children: [
  40. ModeSelector(),
  41. Scores(),
  42. Stack(
  43. children: [
  44. GameBg(),
  45. Blocks(),
  46. Playground(),
  47. ],
  48. ),
  49. ],
  50. ),
  51. )
  52. : Container();
  53. },
  54. ),
  55. );
  56. }
  57. }
  58. class GameProps {
  59. bool started;
  60. GameProps({required this.started});
  61. }