To design a Parent-Child UI page in Flutter with three tabs widget, you can use the following code as an example:
- Create a new Dart file (e.g., parent_child_page.dart) and add the following code:
import 'package:flutter/material.dart';
class ParentChildPage extends StatefulWidget {
@override
_ParentChildPageState createState() => _ParentChildPageState();
}
class _ParentChildPageState extends State<ParentChildPage> {
// List to store parent-child group data
List<GroupData> groupData = [];
// Callback function to handle submitting the data entered by the user
void submitData(String arabicName, String englishName) {
GroupData newGroupData = GroupData(arabicName, englishName);
setState(() {
groupData.add(newGroupData);
});
}
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3, // Number of tabs
child: Scaffold(
appBar: AppBar(
title: Text('Parent-Child Groups'),
bottom: TabBar(
tabs: [
Tab(text: 'Group 1'),
Tab(text: 'Group 2'),
Tab(text: 'Group 3'),
],
),
),
body: TabBarView(
children: [
// Tab 1 content
GroupForm(submitData),
// Tab 2 content
GroupForm(submitData),
// Tab 3 content
GroupForm(submitData),
],
),
),
);
}
}
class GroupData {
String arabicName;
String englishName;
GroupData(this.arabicName, this.englishName);
}
class GroupForm extends StatelessWidget {
final Function(String, String) onSubmit;
GroupForm(this.onSubmit);
final TextEditingController arabicNameController = TextEditingController();
final TextEditingController englishNameController = TextEditingController();
void submitForm() {
final String arabicName = arabicNameController.text;
final String englishName = englishNameController.text;
onSubmit(arabicName, englishName);
}
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: arabicNameController,
decoration: InputDecoration(labelText: 'Arabic Name'),
),
TextField(
controller: englishNameController,
decoration: InputDecoration(labelText: 'English Name'),
),
ElevatedButton(
onPressed: submitForm,
child: Text('Submit'),
),
],
),
),
);
}
}
- In your main.dart file, add the following code to see the UI:
import 'package:flutter/material.dart';
import 'package:your_app_name/parent_child_page.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Parent-Child UI Example',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: ParentChildPage(),
);
}
}
In this example, the ParentChildPage class represents the main page containing the tabs. The GroupData class represents a model for storing the Arabic and English names. The GroupForm class represents the form displayed on each tab to input the data. The submitData function handles submitting the form data and updating the UI.
With this code, each tab will have its own form to input the Arabic and English names, and when the user clicks the submit button, the data will be added to the groupData list and displayed on the respective tab.