Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //File lib/main.dart
- import 'package:flutter/material.dart';
- import 'package:sanca_news/single_article.dart';
- void main() {
- runApp(MyApp());
- }
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- // backgroundColor: Colors.green,
- appBar: AppBar(
- ...
- ...
- ),
- body: Padding(
- padding: const EdgeInsets.all(10.0),
- child: ListView(
- children: <Widget>[
- // card for newest articles
- Card(
- ...
- ...
- ),
- Container(
- ...
- ...
- ...
- ),
- buildCard(),
- buildCard(),
- buildCard(),
- buildCard(),
- buildCard(),
- ],
- ),
- )),
- );
- }
- String text =
- "Ini text beritanya Ini text beritanya Ini text beritanya Ini text ...";
- Card buildCard() {
- return Card(
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
- elevation: 5,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- Flexible(
- flex: 2,
- child: Container(
- margin: EdgeInsets.all(5),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- text,
- style: TextStyle(
- fontSize: 12,
- fontWeight: FontWeight.w700,
- fontFamily: "Poppins"),
- ),
- Container(
- margin: EdgeInsets.only(top: 5),
- child: RaisedButton(
- onPressed: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (BuildContext context) =>
- SingleArticle()));
- },
- child: Text(
- "Read more ...",
- style: TextStyle(fontFamily: "Poppins"),
- ),
- ),
- )
- ],
- ))),
- Flexible(
- ...
- ...
- ),
- ],
- ),
- );
- }
- }
- //File single_article.dart
- import 'package:flutter/material.dart';
- class SingleArticle extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- appBar: AppBar(
- title: Text("Halaman Single Article"),
- ),
- body: Center(
- child: Text("Halaman Single Article"),
- ),
- ),
- );
- }
- }
- //Error yang muncul:
- ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
- The following assertion was thrown while handling a gesture:
- Navigator operation requested with a context that does not include a Navigator.
- The context used to push or pop routes from the Navigator must be that of a widget that is a
- descendant of a Navigator widget.
- When the exception was thrown, this was the stack:
- ...
- ...
- (elided 3 frames from dart:async)
- Handler: "onTap"
- Recognizer:
- TapGestureRecognizer#e04f5
- ═══════ Exception caught by gesture ═══════════════════════════════════════════
- The following assertion was thrown while handling a gesture:
- Navigator operation requested with a context that does not include a Navigator.
- ...
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement