Created
November 9, 2022 07:12
-
-
Save iapicca/f28393fcb209ec1c28f8839c53ffdc0d to your computer and use it in GitHub Desktop.
issue 114952
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() => runApp( | |
| const MaterialApp( | |
| home: MyScaffold( | |
| tabs: [ | |
| MyColumn(), | |
| MyStack(), | |
| MyPositonedBottom(), | |
| MyPositonedTop(), | |
| ], | |
| ), | |
| ), | |
| ); | |
| abstract class TabWidget extends StatelessWidget { | |
| final Widget tab; | |
| const TabWidget({super.key, required this.tab}); | |
| } | |
| class MyScaffold extends StatelessWidget { | |
| final List<TabWidget> tabs; | |
| const MyScaffold({ | |
| super.key, | |
| this.tabs = const [], | |
| }); | |
| @override | |
| Widget build(context) => DefaultTabController( | |
| length: tabs.length, | |
| child: Scaffold( | |
| appBar: AppBar( | |
| title: TabBar( | |
| tabs: [for (final tabWidget in tabs) tabWidget.tab], | |
| ), | |
| ), | |
| body: TabBarView(children: tabs)), | |
| ); | |
| } | |
| class MyColumn extends TabWidget { | |
| const MyColumn({ | |
| super.key, | |
| super.tab = const Text('column'), | |
| }); | |
| @override | |
| Widget build(context) => Column( | |
| children: const [ | |
| MyTextField(), | |
| ], | |
| ); | |
| } | |
| class MyStack extends TabWidget { | |
| const MyStack({ | |
| super.key, | |
| super.tab = const Text('stack'), | |
| }); | |
| @override | |
| Widget build(context) => Stack( | |
| alignment: Alignment.center, | |
| children: const [ | |
| MyTextField(), | |
| ], | |
| ); | |
| } | |
| class MyPositonedBottom extends TabWidget { | |
| const MyPositonedBottom({ | |
| super.key, | |
| super.tab = const Text('positioned bottom'), | |
| }); | |
| @override | |
| Widget build(context) => Stack( | |
| children: [ | |
| Positioned( | |
| width: MediaQuery.of(context).size.width, | |
| bottom: MediaQuery.of(context).size.height * .5, | |
| child: const MyTextField(), | |
| ), | |
| ], | |
| ); | |
| } | |
| class MyPositonedTop extends TabWidget { | |
| const MyPositonedTop({ | |
| super.key, | |
| super.tab = const Text('positioned top'), | |
| }); | |
| @override | |
| Widget build(context) => Stack( | |
| children: [ | |
| Positioned( | |
| width: MediaQuery.of(context).size.width, | |
| top: MediaQuery.of(context).size.height * .5, | |
| child: const MyTextField(), | |
| ), | |
| ], | |
| ); | |
| } | |
| class MyTextField extends StatelessWidget { | |
| const MyTextField({super.key}); | |
| @override | |
| Widget build(context) => Form( | |
| autovalidateMode: AutovalidateMode.always, | |
| child: Container( | |
| color: Colors.yellow.withOpacity(.3), | |
| child: Padding( | |
| padding: const EdgeInsets.all(10), | |
| child: TextFormField( | |
| decoration: const InputDecoration( | |
| border: OutlineInputBorder( | |
| borderSide: BorderSide( | |
| width: 1, | |
| color: Colors.black, | |
| ), | |
| ), | |
| ), | |
| validator: (value) => 'warning', | |
| ), | |
| ), | |
| ), | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment