simple_page_widgets.dart 14.4 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

class FirstRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
余玠's avatar
余玠 committed
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
        child:
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: 
          <Widget>[
            RaisedButton(
                child: Text('Open second route'),
                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!");
                    FlutterBoost.singleton.open("second",urlParams:{"present":true}).then((Map value) {
                      print(
                          "call me when page is finished. did recieve second route result $value");
                    });
                  },
                ),
            ],
Jidong Chen's avatar
init  
Jidong Chen committed
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
class EmbededFirstRouteWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          child: Text('Open second route'),
          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");
            });
          },
        ),
      ),
    );
  }
}

Jidong Chen's avatar
init  
Jidong Chen committed
67 68 69 70 71 72 73 74 75 76 77
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
78 79 80 81 82

            BoostContainerSettings settings =
                BoostContainer.of(context).settings;
            FlutterBoost.singleton.close(settings.uniqueId,
                result: {"result": "data from second"});
Jidong Chen's avatar
init  
Jidong Chen committed
83
          },
Jidong Chen's avatar
Jidong Chen committed
84
          child: Text('Go back with result!'),
Jidong Chen's avatar
init  
Jidong Chen committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
        ),
      ),
    );
  }
}

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
101
            FlutterBoost.singleton.open("second");
Jidong Chen's avatar
init  
Jidong Chen committed
102 103 104 105 106 107 108 109
          },
          child: Text('Open second route'),
        ),
      ),
    );
  }
}

yangwu.jia's avatar
yangwu.jia committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
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
132 133 134
class FlutterRouteWidget extends StatefulWidget {
  FlutterRouteWidget({this.params,this.message});
  final Map params;
135 136
  final String message;

yangwu.jia's avatar
yangwu.jia committed
137 138 139 140 141 142
  @override
  _FlutterRouteWidgetState createState() => _FlutterRouteWidgetState();
}

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

Jidong Chen's avatar
init  
Jidong Chen committed
144 145
  @override
  Widget build(BuildContext context) {
yangwu.jia's avatar
yangwu.jia committed
146
    final String message=widget.message;
Jidong Chen's avatar
init  
Jidong Chen committed
147 148
    return Scaffold(
      appBar: AppBar(
yangwu.jia's avatar
yangwu.jia committed
149 150 151 152
        brightness:Brightness.light,
        backgroundColor: Colors.white,
        textTheme:new TextTheme(title: TextStyle(color: Colors.black)) ,

Jidong Chen's avatar
init  
Jidong Chen committed
153 154
        title: Text('flutter_boost_example'),
      ),
yangwu.jia's avatar
yangwu.jia committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
      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
                      .open("sample://nativePage", urlParams: {
                    "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
208
                        'open first',
yangwu.jia's avatar
yangwu.jia committed
209 210 211 212 213 214
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
yangwu.jia's avatar
yangwu.jia committed
215
                      .open("first", urlParams: {
yangwu.jia's avatar
yangwu.jia committed
216 217 218 219 220 221 222 223 224
                    "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
225
                        'open second',
yangwu.jia's avatar
yangwu.jia committed
226 227 228 229 230 231
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
yangwu.jia's avatar
yangwu.jia committed
232
                      .open("second", urlParams: {
yangwu.jia's avatar
yangwu.jia committed
233 234 235 236 237 238 239 240 241
                    "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
242
                        'open tab',
yangwu.jia's avatar
yangwu.jia committed
243 244 245 246 247 248
                        style: TextStyle(fontSize: 22.0, color: Colors.black),
                      )),

                  ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
                  ///例如:sample://nativePage?aaa=bbb
                  onTap: () => FlutterBoost.singleton
yangwu.jia's avatar
yangwu.jia committed
249
                      .open("tab", urlParams: {
yangwu.jia's avatar
yangwu.jia committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                    "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
                      .open("sample://flutterPage", urlParams: {
                    "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: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (_) => PushWidget()));
                  },
                ),
yangwu.jia's avatar
yangwu.jia committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

              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: () {
                  Navigator.push(context,
                      MaterialPageRoute(builder: (_) => PlatformRouteWidget()));
                },
              ),
yangwu.jia's avatar
yangwu.jia committed
299 300 301 302 303 304 305 306 307 308 309 310 311
                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
312
            ),
yangwu.jia's avatar
yangwu.jia committed
313 314

        ),
Jidong Chen's avatar
init  
Jidong Chen committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
      ),
    );
  }
}

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
360
            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
Jidong Chen's avatar
init  
Jidong Chen committed
361 362 363 364 365 366 367 368 369 370
          ),
          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
371
            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
372 373 374 375 376 377 378 379 380 381
          ),
          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
382 383
            onTap: () =>
                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
Jidong Chen's avatar
init  
Jidong Chen committed
384 385 386 387 388 389
          )
        ],
      ),
    );
  }
}
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409

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();

410 411 412 413 414 415 416 417 418
//    if (_backPressedListenerUnsub == null) {
//      _backPressedListenerUnsub =
//          BoostContainer.of(context).addBackPressedListener(() {
//        if (BoostContainer.of(context).onstage &&
//            ModalRoute.of(context).isCurrent) {
//          Navigator.pop(context);
//        }
//      });
//    }
419 420 421 422 423 424 425 426 427 428 429
  }

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

  @override
  Widget build(BuildContext context) {
hym's avatar
hym committed
430
    return FlutterRouteWidget(message: "Pushed Widget");
431 432
  }
}