Limit max width of Container in Flutter

You can add a constraint to the Container Widget with the preferred maxWidth like this: Widget build(context) { return Row( mainAxisSize: MainAxisSize.min, children: [ Container( constraints: BoxConstraints(minWidth: 100, maxWidth: 200), padding: EdgeInsets.all(10), decoration: BoxDecoration( color: color ?? Colors.blue, borderRadius: BorderRadius.circular(10) ), child: msg ) ], ); }

How to overlay a widget on top of a flutter App?

Maybe a more optimal way exists, but as an option this is an example with two pages, local navigator and Overlay. import ‘package:flutter/material.dart’; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { final _navigatorKey = GlobalKey<NavigatorState>(); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: … Read more

How to use BottomNavigationBar with Navigator?

int index = 0; @override Widget build(BuildContext context) { return new Scaffold( body: new Stack( children: <Widget>[ new Offstage( offstage: index != 0, child: new TickerMode( enabled: index == 0, child: new MaterialApp(home: new YourLeftPage()), ), ), new Offstage( offstage: index != 1, child: new TickerMode( enabled: index == 1, child: new MaterialApp(home: new YourRightPage()), … Read more

How to catch exception in flutter?

Try void loginUser(String email, String password) async { try { var user = await _data .userLogin(email, password); _view.onLoginComplete(user); }); } on FetchDataException catch(e) { print(‘error caught: $e’); _view.onLoginError(); } } catchError is sometimes a bit tricky to get right. With async/await you can use try/catch like with sync code and it is usually much easier … Read more