simple_page_widgets.dart 8.19 KB
Newer Older
余玠's avatar
余玠 committed
1 2 3 4 5 6 7 8
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';

class FirstRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
9
        title: const Text('First Route'),
余玠's avatar
余玠 committed
10 11 12
      ),
      body: Center(
        child: RaisedButton(
13
          child: const Text('Open second route'),
余玠's avatar
余玠 committed
14
          onPressed: () {
15 16 17 18 19 20
            print('open second page!');
            FlutterBoost.singleton
                .open('second')
                .then((Map<String, dynamic> value) {
              print(
                  'call me when page is finished. did recieve second route result $value');
余玠's avatar
余玠 committed
21 22 23 24 25 26 27 28 29 30 31 32 33
            });
          },
        ),
      ),
    );
  }
}

class SecondRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
34
        title: const Text('Second Route'),
余玠's avatar
余玠 committed
35 36 37 38 39 40
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            // Navigate back to first route when tapped.

41
            final BoostContainerSettings settings =
余玠's avatar
余玠 committed
42
                BoostContainer.of(context).settings;
43 44 45 46
            FlutterBoost.singleton.close(
              settings.uniqueId,
              result: <String, dynamic>{'result': 'data from second'},
            );
余玠's avatar
余玠 committed
47
          },
48
          child: const Text('Go back with result!'),
余玠's avatar
余玠 committed
49 50 51 52 53 54 55 56 57 58
        ),
      ),
    );
  }
}

class TabRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
59
      appBar: AppBar(title: const Text('Tab Route')),
余玠's avatar
余玠 committed
60 61 62
      body: Center(
        child: RaisedButton(
          onPressed: () {
63
            FlutterBoost.singleton.open('second');
余玠's avatar
余玠 committed
64
          },
65
          child: const Text('Open second route'),
余玠's avatar
余玠 committed
66 67 68 69 70 71 72
        ),
      ),
    );
  }
}

class FlutterRouteWidget extends StatelessWidget {
73
  const FlutterRouteWidget({this.message});
余玠's avatar
余玠 committed
74

75
  final String message;
余玠's avatar
余玠 committed
76 77 78 79 80

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
81
        title: const Text('flutter_boost_example'),
余玠's avatar
余玠 committed
82 83 84 85 86 87 88
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
89
              message ?? 'This is a flutter activity',
余玠's avatar
余玠 committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),

            ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
            ///例如:sample://nativePage?aaa=bbb
107 108 109 110 111 112
            onTap: () => FlutterBoost.singleton.open(
              'sample://nativePage',
              urlParams: <String, dynamic>{
                'query': <String, dynamic>{'aaa': 'bbb'}
              },
            ),
余玠's avatar
余玠 committed
113 114 115 116 117 118 119 120 121 122 123 124 125
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),

            ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
            ///例如:sample://nativePage?aaa=bbb
126 127 128 129 130 131
            onTap: () => FlutterBoost.singleton.open(
              'sample://flutterPage',
              urlParams: <String, dynamic>{
                'query': <String, dynamic>{'aaa': 'bbb'},
              },
            ),
余玠's avatar
余玠 committed
132 133 134
          ),
          InkWell(
            child: Container(
135 136 137 138 139 140 141 142
              padding: const EdgeInsets.all(8.0),
              margin: const EdgeInsets.all(8.0),
              color: Colors.yellow,
              child: Text(
                'push flutter widget',
                style: TextStyle(fontSize: 22.0, color: Colors.black),
              ),
            ),
余玠's avatar
余玠 committed
143
            onTap: () {
justin's avatar
justin committed
144
              Navigator.push<dynamic>(
145 146 147
                context,
                MaterialPageRoute<dynamic>(builder: (_) => PushWidget()),
              );
余玠's avatar
余玠 committed
148 149 150 151
            },
          ),
          InkWell(
            child: Container(
152 153 154 155 156 157 158 159
              padding: const EdgeInsets.all(8.0),
              margin: const EdgeInsets.all(8.0),
              color: Colors.yellow,
              child: Text(
                'open flutter fragment page',
                style: TextStyle(fontSize: 22.0, color: Colors.black),
              ),
            ),
余玠's avatar
余玠 committed
160
            onTap: () =>
161
                FlutterBoost.singleton.open('sample://flutterFragmentPage'),
余玠's avatar
余玠 committed
162 163 164 165 166 167 168 169
          ),
        ],
      ),
    );
  }
}

class FragmentRouteWidget extends StatelessWidget {
170
  const FragmentRouteWidget(this.params);
余玠's avatar
余玠 committed
171

172
  final Map<String, dynamic> params;
余玠's avatar
余玠 committed
173 174 175 176 177

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
178
        title: const Text('flutter_boost_example'),
余玠's avatar
余玠 committed
179 180 181 182 183 184 185
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
186
              'This is a flutter fragment',
余玠's avatar
余玠 committed
187 188 189 190 191 192 193
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
194
              '${params['tag']}' ?? '',
余玠's avatar
余玠 committed
195 196 197 198 199 200 201
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
202 203 204 205 206 207 208 209 210
              padding: const EdgeInsets.all(8.0),
              margin: const EdgeInsets.all(8.0),
              color: Colors.yellow,
              child: Text(
                'open native page',
                style: TextStyle(fontSize: 22.0, color: Colors.black),
              ),
            ),
            onTap: () => FlutterBoost.singleton.open('sample://nativePage'),
余玠's avatar
余玠 committed
211 212 213
          ),
          InkWell(
            child: Container(
214 215 216 217 218 219 220 221 222
              padding: const EdgeInsets.all(8.0),
              margin: const EdgeInsets.all(8.0),
              color: Colors.yellow,
              child: Text(
                'open flutter page',
                style: TextStyle(fontSize: 22.0, color: Colors.black),
              ),
            ),
            onTap: () => FlutterBoost.singleton.open('sample://flutterPage'),
余玠's avatar
余玠 committed
223 224 225
          ),
          InkWell(
            child: Container(
226 227 228 229 230 231 232 233
              padding: const EdgeInsets.all(8.0),
              margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
              color: Colors.yellow,
              child: Text(
                'open flutter fragment page',
                style: TextStyle(fontSize: 22.0, color: Colors.black),
              ),
            ),
余玠's avatar
余玠 committed
234
            onTap: () =>
235
                FlutterBoost.singleton.open('sample://flutterFragmentPage'),
余玠's avatar
余玠 committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
          )
        ],
      ),
    );
  }
}

class PushWidget extends StatefulWidget {
  @override
  _PushWidgetState createState() => _PushWidgetState();
}

class _PushWidgetState extends State<PushWidget> {
  VoidCallback _backPressedListenerUnsub;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();

//    if (_backPressedListenerUnsub == null) {
//      _backPressedListenerUnsub =
//          BoostContainer.of(context).addBackPressedListener(() {
//        if (BoostContainer.of(context).onstage &&
//            ModalRoute.of(context).isCurrent) {
//          Navigator.pop(context);
//        }
//      });
//    }
  }

  @override
  void dispose() {
    super.dispose();
    _backPressedListenerUnsub?.call();
  }

  @override
  Widget build(BuildContext context) {
274
    return const FlutterRouteWidget(message: 'Pushed Widget');
余玠's avatar
余玠 committed
275 276
  }
}