simple_page_widgets.dart 17.8 KB
Newer Older
yangwu.jia's avatar
yangwu.jia committed
1
import 'package:flutter/cupertino.dart';
Jidong Chen's avatar
init  
Jidong Chen committed
2
import 'package:flutter/material.dart';
yangwu.jia's avatar
yangwu.jia committed
3
import 'package:flutter_boost/flutter_boost.dart';
yangwu.jia's avatar
yangwu.jia committed
4
import 'package:flutter_boost_example/platform_view.dart';
Jidong Chen's avatar
init  
Jidong Chen committed
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
class FirstRouteWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _FirstRouteWidgetState();
  }
}
class _FirstRouteWidgetState extends State<FirstRouteWidget>{
  _FirstRouteWidgetState();

  @override
  void initState() {
    print('initState');
    super.initState();
  }

  @override
  void didChangeDependencies() {
    print('didChangeDependencies');
    super.didChangeDependencies();
  }

  @override
  void didUpdateWidget(FirstRouteWidget oldWidget) {
    print('didUpdateWidget');
    super.didUpdateWidget(oldWidget);
  }

  @override
  void deactivate() {
    print('deactivate');
    super.deactivate();
  }

  @override
  void dispose() {
    print('[XDEBUG] - FirstRouteWidget is disposing~');
    super.dispose();
  }

Jidong Chen's avatar
init  
Jidong Chen committed
45 46 47 48 49 50 51
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
余玠's avatar
余玠 committed
52 53 54 55 56
        child:
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: 
          <Widget>[
57 58 59 60 61 62 63 64 65 66
            RaisedButton(
                child: Text('Open native page'),
                onPressed: () {
                  print("open natve page!");
                  FlutterBoost.singleton.open("native").then((Map value) {
                    print(
                        "call me when page is finished. did recieve second route result $value");
                  });
                },
              ),
67 68 69 70 71 72 73 74 75 76 77 78
              RaisedButton(
                child: Text('Open FF route'),
                onPressed: () {
                  print("open FF page!");
                  FlutterBoost.singleton.open("firstFirst").then((Map value) {
                    print(
                        "call me when page is finished. did recieve FF route result $value");
                  });
                },
              ),
              RaisedButton(
                child: Text('Open second route1'),
余玠's avatar
余玠 committed
79 80 81 82 83 84 85 86 87 88 89 90 91
                onPressed: () {
                  print("open second page!");
                  FlutterBoost.singleton.open("second").then((Map value) {
                    print(
                        "call me when page is finished. did recieve second route result $value");
                  });
                },
              ),

              RaisedButton(
                  child: Text('Present second route'),
                  onPressed: () {
                    print("Present second page!");
justin's avatar
justin committed
92
                    FlutterBoost.singleton.open("second",urlParams:<dynamic,dynamic>{"present":true}).then((Map value) {
余玠's avatar
余玠 committed
93 94 95 96 97 98
                      print(
                          "call me when page is finished. did recieve second route result $value");
                    });
                  },
                ),
            ],
Jidong Chen's avatar
init  
Jidong Chen committed
99 100 101 102 103
        ),
      ),
    );
  }
}
104 105 106 107 108 109 110 111 112
class FirstFirstRouteWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _FirstFirstRouteWidgetState();
  }
}

class _FirstFirstRouteWidgetState extends State<FirstFirstRouteWidget>{
  _FirstFirstRouteWidgetState();
Jidong Chen's avatar
init  
Jidong Chen committed
113

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  @override
  void initState() {
    print('initState');
    super.initState();
  }

  @override
  void didChangeDependencies() {
    print('didChangeDependencies');
    super.didChangeDependencies();
  }

  @override
  void didUpdateWidget(FirstFirstRouteWidget oldWidget) {
    print('didUpdateWidget');
    super.didUpdateWidget(oldWidget);
  }

  @override
  void deactivate() {
    print('deactivate');
    super.deactivate();
  }

  @override
  void dispose() {
    print('[XDEBUG] - FirstFirstRouteWidget is disposing~');
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
        child: RaisedButton(
          child: Text('Open first route'),
          onPressed: () {

            print("open first page again!");
            FlutterBoost.singleton.open("first").then((Map value){
              print("did recieve first route result");
              print("did recieve first route result $value");
            });

          },
        ),
      ),
    );
  }
}

class EmbededFirstRouteWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _EmbededFirstRouteWidgetState();
  }

}

class _EmbededFirstRouteWidgetState extends State<EmbededFirstRouteWidget> {
178 179
  @override
  Widget build(BuildContext context) {
180
    print('_EmbededFirstRouteWidgetState build called!');
181 182 183
    return Scaffold(
      body: Center(
        child: RaisedButton(
184
          child: Text('Open second route2'),
185 186 187 188 189 190 191 192 193 194 195
          onPressed: () {
            print("open second page!");
            FlutterBoost.singleton.open("second").then((Map value) {
              print(
                  "call me when page is finished. did recieve second route result $value");
            });
          },
        ),
      ),
    );
  }
196 197 198 199 200
  @override
  void dispose() {
    print('[XDEBUG]:_EmbededFirstRouteWidgetState dispose called!');
    super.dispose();
  }
201 202
}

Jidong Chen's avatar
init  
Jidong Chen committed
203 204 205 206 207 208 209 210 211 212 213
class SecondRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Second Route"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            // Navigate back to first route when tapped.
hym's avatar
hym committed
214 215 216 217

            BoostContainerSettings settings =
                BoostContainer.of(context).settings;
            FlutterBoost.singleton.close(settings.uniqueId,
justin's avatar
justin committed
218
                result: <dynamic,dynamic>{"result": "data from second"});
Jidong Chen's avatar
init  
Jidong Chen committed
219
          },
Jidong Chen's avatar
Jidong Chen committed
220
          child: Text('Go back with result!'),
Jidong Chen's avatar
init  
Jidong Chen committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        ),
      ),
    );
  }
}

class TabRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Tab Route"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
yangwu.jia's avatar
yangwu.jia committed
237
            FlutterBoost.singleton.open("second");
Jidong Chen's avatar
init  
Jidong Chen committed
238
          },
239
          child: Text('Open second route3'),
Jidong Chen's avatar
init  
Jidong Chen committed
240 241 242 243 244 245
        ),
      ),
    );
  }
}

yangwu.jia's avatar
yangwu.jia committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
class PlatformRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:Text("Platform Route"),
      ),
      body: Center(
        child: RaisedButton(
          child: TextView(),
          onPressed: () {
            print("open second page!");
            FlutterBoost.singleton.open("second").then((Map value) {
              print(
                  "call me when page is finished. did recieve second route result $value");
            });
          },
        ),
      ),
    );
  }
}
yangwu.jia's avatar
yangwu.jia committed
268 269 270
class FlutterRouteWidget extends StatefulWidget {
  FlutterRouteWidget({this.params,this.message});
  final Map params;
271 272
  final String message;

yangwu.jia's avatar
yangwu.jia committed
273 274 275 276 277 278
  @override
  _FlutterRouteWidgetState createState() => _FlutterRouteWidgetState();
}

class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
  final TextEditingController _usernameController = TextEditingController();
279

Jidong Chen's avatar
init  
Jidong Chen committed
280 281
  @override
  Widget build(BuildContext context) {
yangwu.jia's avatar
yangwu.jia committed
282
    final String message=widget.message;
Jidong Chen's avatar
init  
Jidong Chen committed
283 284
    return Scaffold(
      appBar: AppBar(
yangwu.jia's avatar
yangwu.jia committed
285 286 287 288
        brightness:Brightness.light,
        backgroundColor: Colors.white,
        textTheme:new TextTheme(title: TextStyle(color: Colors.black)) ,

Jidong Chen's avatar
init  
Jidong Chen committed
289 290
        title: Text('flutter_boost_example'),
      ),
yangwu.jia's avatar
yangwu.jia committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
      body: SingleChildScrollView(
        child:Container(
            margin: const EdgeInsets.all(24.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  margin: const EdgeInsets.only(top: 10.0,bottom: 20.0),
                  child: Text(
                    message ?? "This is a flutter activity \n params:${widget.params}",
                    style: TextStyle(fontSize: 28.0, color: Colors.blue),
                  ),
                  alignment: AlignmentDirectional.center,
                ),
//                Expanded(child: Container()),
                const CupertinoTextField(
                  prefix: Icon(
                    CupertinoIcons.person_solid,
                    color: CupertinoColors.lightBackgroundGray,
                    size: 28.0,
                  ),
                  padding: EdgeInsets.symmetric(horizontal: 6.0, vertical: 12.0),
                  clearButtonMode: OverlayVisibilityMode.editing,
                  textCapitalization: TextCapitalization.words,
                  autocorrect: false,
                  decoration: BoxDecoration(
                    border: Border(bottom: BorderSide(width: 0.0, color: CupertinoColors.inactiveGray)),
                  ),
                  placeholder: 'Name',
                ),
                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
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
334
                      .open("sample://nativePage", urlParams: <dynamic,dynamic>{
yangwu.jia's avatar
yangwu.jia committed
335 336 337 338 339 340 341 342 343
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      padding: const EdgeInsets.all(8.0),
                      margin: const EdgeInsets.all(8.0),
                      color: Colors.yellow,
                      child: Text(
yangwu.jia's avatar
yangwu.jia committed
344
                        'open first',
yangwu.jia's avatar
yangwu.jia committed
345 346 347 348 349 350
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
351
                      .open("first", urlParams: <dynamic,dynamic>{
yangwu.jia's avatar
yangwu.jia committed
352 353 354 355 356 357 358 359 360
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      padding: const EdgeInsets.all(8.0),
                      margin: const EdgeInsets.all(8.0),
                      color: Colors.yellow,
                      child: Text(
yangwu.jia's avatar
yangwu.jia committed
361
                        'open second',
yangwu.jia's avatar
yangwu.jia committed
362 363 364 365 366 367
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
368
                      .open("second", urlParams:<dynamic,dynamic> {
yangwu.jia's avatar
yangwu.jia committed
369 370 371 372 373 374 375 376 377
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      padding: const EdgeInsets.all(8.0),
                      margin: const EdgeInsets.all(8.0),
                      color: Colors.yellow,
                      child: Text(
yangwu.jia's avatar
yangwu.jia committed
378
                        'open tab',
yangwu.jia's avatar
yangwu.jia committed
379 380 381 382 383 384
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
385
                      .open("tab", urlParams:<dynamic,dynamic> {
yangwu.jia's avatar
yangwu.jia committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
                    "query": {"aaa": "bbb"}
                  }),
                ),
                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
                  onTap: () => FlutterBoost.singleton
justin's avatar
justin committed
402
                      .open("sample://flutterPage", urlParams:<dynamic,dynamic> {
yangwu.jia's avatar
yangwu.jia committed
403 404 405 406 407 408 409 410 411 412 413 414 415
                    "query": {"aaa": "bbb"}
                  }),
                ),
                InkWell(
                  child: Container(
                      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),
                      )),
                  onTap: () {
justin's avatar
justin committed
416 417
                  Navigator.push<dynamic>(context,
                        MaterialPageRoute<dynamic>(builder: (_) => PushWidget()));
yangwu.jia's avatar
yangwu.jia committed
418 419
                  },
                ),
yangwu.jia's avatar
yangwu.jia committed
420 421 422 423 424 425 426 427 428 429 430

              InkWell(
                child: Container(
                    padding: const EdgeInsets.all(8.0),
                    margin: const EdgeInsets.all(8.0),
                    color: Colors.yellow,
                    child: Text(
                      'push Platform demo',
                      style: TextStyle(fontSize: 22.0, color: Colors.black),
                    )),
                onTap: () {
justin's avatar
justin committed
431 432
                  Navigator.push<dynamic>(context,
                      MaterialPageRoute<dynamic>(builder: (_) => PlatformRouteWidget()));
yangwu.jia's avatar
yangwu.jia committed
433 434
                },
              ),
yangwu.jia's avatar
yangwu.jia committed
435 436 437 438 439 440 441 442 443 444 445 446 447
                InkWell(
                  child: Container(
                      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),
                      )),
                  onTap: () => FlutterBoost.singleton
                      .open("sample://flutterFragmentPage"),
                ),
              ],
Jidong Chen's avatar
init  
Jidong Chen committed
448
            ),
yangwu.jia's avatar
yangwu.jia committed
449 450

        ),
Jidong Chen's avatar
init  
Jidong Chen committed
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
      ),
    );
  }
}

class FragmentRouteWidget extends StatelessWidget {
  final Map params;

  FragmentRouteWidget(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            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),
                )),
hym's avatar
hym committed
496
            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
Jidong Chen's avatar
init  
Jidong Chen committed
497 498 499 500 501 502 503 504 505 506
          ),
          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),
                )),
hym's avatar
hym committed
507
            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
508 509 510 511 512 513 514 515 516 517
          ),
          InkWell(
            child: Container(
                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),
                )),
hym's avatar
hym committed
518 519
            onTap: () =>
                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
520 521 522 523 524 525
          )
        ],
      ),
    );
  }
}
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545

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

class _PushWidgetState extends State<PushWidget> {
  VoidCallback _backPressedListenerUnsub;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();

546 547 548 549 550 551 552 553 554
//    if (_backPressedListenerUnsub == null) {
//      _backPressedListenerUnsub =
//          BoostContainer.of(context).addBackPressedListener(() {
//        if (BoostContainer.of(context).onstage &&
//            ModalRoute.of(context).isCurrent) {
//          Navigator.pop(context);
//        }
//      });
//    }
555 556 557 558 559 560 561 562 563 564 565
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _backPressedListenerUnsub?.call();
  }

  @override
  Widget build(BuildContext context) {
hym's avatar
hym committed
566
    return FlutterRouteWidget(message: "Pushed Widget");
567 568
  }
}